Colt 1.0.2

cern.colt.io
Class Converting

java.lang.Object
  |
  +--cern.colt.io.Converting

public class Converting
extends Object

Efficient portable array conversions for high performance I/O through bulk data transfer rather than piece-wise transfer. Avoids deep non-inlined synchronized call chains in the java.io package. The following conversions are supported:

This exactly mimics the semantics of java.io.DataInputStream and java.io.DataOutputStream. In fact, this is a copy&paste of the JDK1.3 source code of these two classes, with efficient loops written around. Not only for disk I/O, but also for other kinds of serialization, e.g. high bandwidth networking.

Fast writing:

Fast reading:

The method arguments are exactly as used in System#arraycopy, except for the length argument which is always given in bytes! Please don't flame for not writing redundant javadoc for each and every method. Run main() for tests and benchmarks. Converting ints and longs is fastest --> some 50-75 MB/s, floats and doubles --> some 15-35 MB/s


Method Summary
static void main(String[] args)
          Test implementation for correctness and benchmarks (outputs MB/s converted back and forth).
static void read(byte[] src, int srcPos, boolean[] dest, int destPos, int length)
           
static void read(byte[] src, int srcPos, byte[] dest, int destPos, int length)
           
static void read(byte[] src, int srcPos, char[] dest, int destPos, int length)
           
static void read(byte[] src, int srcPos, double[] dest, int destPos, int length)
           
static void read(byte[] src, int srcPos, float[] dest, int destPos, int length)
           
static void read(byte[] src, int srcPos, int[] dest, int destPos, int length)
           
static void read(byte[] src, int srcPos, long[] dest, int destPos, int length)
           
static void read(byte[] src, int srcPos, short[] dest, int destPos, int length)
           
static boolean readBoolean(byte[] src, int srcPos)
           
static byte readByte(byte[] src, int srcPos)
           
static char readChar(byte[] src, int srcPos)
           
static double readDouble(byte[] src, int srcPos)
           
static float readFloat(byte[] src, int srcPos)
           
static int readInt(byte[] src, int srcPos)
           
static long readLong(byte[] src, int srcPos)
           
static short readShort(byte[] src, int srcPos)
           
static int readUnsignedByte(byte[] src, int srcPos)
           
static int readUnsignedShort(byte[] src, int srcPos)
           
static void write(boolean[] src, int srcPos, byte[] dest, int destPos, int length)
           
static void write(boolean v, byte[] dest, int destPos)
           
static void write(byte[] src, int srcPos, byte[] dest, int destPos, int length)
           
static void write(byte v, byte[] dest, int destPos)
           
static void write(char[] src, int srcPos, byte[] dest, int destPos, int length)
           
static void write(char v, byte[] dest, int destPos)
           
static void write(double[] src, int srcPos, byte[] dest, int destPos, int length)
           
static void write(double src, byte[] dest, int destPos)
           
static void write(float[] src, int srcPos, byte[] dest, int destPos, int length)
           
static void write(float vv, byte[] dest, int destPos)
           
static void write(int[] src, int srcPos, byte[] dest, int destPos, int length)
           
static void write(int v, byte[] dest, int destPos)
           
static void write(long[] src, int srcPos, byte[] dest, int destPos, int length)
           
static void write(long v, byte[] dest, int destPos)
           
static void write(short[] src, int srcPos, byte[] dest, int destPos, int length)
           
static void write(short v, byte[] dest, int destPos)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

main

public static void main(String[] args)
Test implementation for correctness and benchmarks (outputs MB/s converted back and forth).

read

public static void read(byte[] src,
                        int srcPos,
                        byte[] dest,
                        int destPos,
                        int length)

read

public static void read(byte[] src,
                        int srcPos,
                        char[] dest,
                        int destPos,
                        int length)

read

public static void read(byte[] src,
                        int srcPos,
                        double[] dest,
                        int destPos,
                        int length)

read

public static void read(byte[] src,
                        int srcPos,
                        float[] dest,
                        int destPos,
                        int length)

read

public static void read(byte[] src,
                        int srcPos,
                        int[] dest,
                        int destPos,
                        int length)

read

public static void read(byte[] src,
                        int srcPos,
                        long[] dest,
                        int destPos,
                        int length)

read

public static void read(byte[] src,
                        int srcPos,
                        short[] dest,
                        int destPos,
                        int length)

read

public static void read(byte[] src,
                        int srcPos,
                        boolean[] dest,
                        int destPos,
                        int length)

readBoolean

public static boolean readBoolean(byte[] src,
                                  int srcPos)

readByte

public static byte readByte(byte[] src,
                            int srcPos)

readChar

public static char readChar(byte[] src,
                            int srcPos)

readDouble

public static double readDouble(byte[] src,
                                int srcPos)

readFloat

public static float readFloat(byte[] src,
                              int srcPos)

readInt

public static int readInt(byte[] src,
                          int srcPos)

readLong

public static long readLong(byte[] src,
                            int srcPos)

readShort

public static short readShort(byte[] src,
                              int srcPos)

readUnsignedByte

public static int readUnsignedByte(byte[] src,
                                   int srcPos)

readUnsignedShort

public static int readUnsignedShort(byte[] src,
                                    int srcPos)

write

public static void write(byte[] src,
                         int srcPos,
                         byte[] dest,
                         int destPos,
                         int length)

write

public static void write(char[] src,
                         int srcPos,
                         byte[] dest,
                         int destPos,
                         int length)

write

public static void write(double[] src,
                         int srcPos,
                         byte[] dest,
                         int destPos,
                         int length)

write

public static void write(float[] src,
                         int srcPos,
                         byte[] dest,
                         int destPos,
                         int length)

write

public static void write(int[] src,
                         int srcPos,
                         byte[] dest,
                         int destPos,
                         int length)

write

public static void write(long[] src,
                         int srcPos,
                         byte[] dest,
                         int destPos,
                         int length)

write

public static void write(short[] src,
                         int srcPos,
                         byte[] dest,
                         int destPos,
                         int length)

write

public static void write(boolean[] src,
                         int srcPos,
                         byte[] dest,
                         int destPos,
                         int length)

write

public static void write(byte v,
                         byte[] dest,
                         int destPos)

write

public static void write(char v,
                         byte[] dest,
                         int destPos)

write

public static void write(double src,
                         byte[] dest,
                         int destPos)

write

public static void write(float vv,
                         byte[] dest,
                         int destPos)

write

public static void write(int v,
                         byte[] dest,
                         int destPos)

write

public static void write(long v,
                         byte[] dest,
                         int destPos)

write

public static void write(short v,
                         byte[] dest,
                         int destPos)

write

public static void write(boolean v,
                         byte[] dest,
                         int destPos)

Colt 1.0.2

Submit a bug or feature. Check the Colt home page for the latest news.