Sea 0.4.0

gov.lbl.dsd.sea.nio.util
Class ByteConverter

java.lang.Object
  extended bygov.lbl.dsd.sea.nio.util.ByteConverter

public class ByteConverter
extends Object

Efficient big endian array conversions for high performance I/O through bulk data transfer rather than piece-wise transfer. (You may want to disregard this class in favour of the conversion facilities in the ByteBuffer family of classes).

Avoids deep non-inlined synchronized call chains in the java.io package. The following conversions are supported:

This exactly mimics the semantics of DataInputStream and DataOutputStream. In fact, this is a copy&paste of the JDK 1.4.2 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(java.lang.Object, int, java.lang.Object, int, int), except for the length argument which is always given in primitive element units! Please don't flame for not writing redundant javadoc for each and every method.

Version:
$Revision: 1.12 $, $Date: 2004/07/28 01:53:13 $

Field Summary
static int SIZE_OF_BOOLEAN
           
static int SIZE_OF_BYTE
           
static int SIZE_OF_CHAR
           
static int SIZE_OF_DOUBLE
           
static int SIZE_OF_FLOAT
           
static int SIZE_OF_INT
           
static int SIZE_OF_LONG
           
static int SIZE_OF_SHORT
           
 
Method Summary
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 v)
          Returns the integer value gained when interpreting the value v as an unsigned byte.
static int readUnsignedByte(byte[] src, int srcPos)
           
static long readUnsignedInt(byte[] src, int srcPos)
           
static long readUnsignedInt(int v)
          Returns the long value gained when interpreting the value v as an unsigned int.
static int readUnsignedShort(byte[] src, int srcPos)
           
static int readUnsignedShort(short v)
          Returns the integer value gained when interpreting the value v as an unsigned short.
static void write(boolean[] src, int srcPos, byte[] dest, int destPos, int length)
           
static void write(byte[] src, int srcPos, byte[] dest, int destPos, int length)
           
static void write(char[] src, int srcPos, byte[] dest, int destPos, int length)
           
static void write(double[] src, int srcPos, byte[] dest, int destPos, int length)
           
static void write(float[] src, int srcPos, byte[] dest, int destPos, int length)
           
static void write(int[] src, int srcPos, byte[] dest, int destPos, int length)
           
static void write(long[] src, int srcPos, byte[] dest, int destPos, int length)
           
static void write(short[] src, int srcPos, byte[] dest, int destPos, int length)
           
static void writeBoolean(boolean v, byte[] dest, int destPos)
           
static void writeByte(byte v, byte[] dest, int destPos)
           
static void writeChar(char v, byte[] dest, int destPos)
           
static void writeDouble(double src, byte[] dest, int destPos)
           
static void writeFloat(float v, byte[] dest, int destPos)
           
static void writeInt(int v, byte[] dest, int destPos)
           
static void writeLong(long v, byte[] dest, int destPos)
           
static void writeShort(short v, byte[] dest, int destPos)
           
static void writeUnsignedInt(long v, byte[] dest, int destPos)
           
static void writeUnsignedShort(int v, byte[] dest, int destPos)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIZE_OF_BOOLEAN

public static final int SIZE_OF_BOOLEAN
See Also:
Constant Field Values

SIZE_OF_BYTE

public static final int SIZE_OF_BYTE
See Also:
Constant Field Values

SIZE_OF_CHAR

public static final int SIZE_OF_CHAR
See Also:
Constant Field Values

SIZE_OF_SHORT

public static final int SIZE_OF_SHORT
See Also:
Constant Field Values

SIZE_OF_INT

public static final int SIZE_OF_INT
See Also:
Constant Field Values

SIZE_OF_FLOAT

public static final int SIZE_OF_FLOAT
See Also:
Constant Field Values

SIZE_OF_LONG

public static final int SIZE_OF_LONG
See Also:
Constant Field Values

SIZE_OF_DOUBLE

public static final int SIZE_OF_DOUBLE
See Also:
Constant Field Values
Method Detail

readByte

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

readBoolean

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

readChar

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

readShort

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

readInt

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

readFloat

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

readLong

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

readDouble

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

readUnsignedByte

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

readUnsignedShort

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

readUnsignedInt

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

readUnsignedByte

public static int readUnsignedByte(byte v)
Returns the integer value gained when interpreting the value v as an unsigned byte. Example: readUnsignedByte(0xFF) == 255, rather than -1.


readUnsignedShort

public static int readUnsignedShort(short v)
Returns the integer value gained when interpreting the value v as an unsigned short.


readUnsignedInt

public static long readUnsignedInt(int v)
Returns the long value gained when interpreting the value v as an unsigned int.


read

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

read

public static void read(byte[] src,
                        int srcPos,
                        boolean[] 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,
                        short[] 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,
                        float[] 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,
                        double[] dest,
                        int destPos,
                        int length)

writeByte

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

writeBoolean

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

writeChar

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

writeShort

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

writeFloat

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

writeInt

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

writeLong

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

writeDouble

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

writeUnsignedShort

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

writeUnsignedInt

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

write

public static void write(byte[] 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(char[] 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(int[] 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(long[] src,
                         int srcPos,
                         byte[] dest,
                         int destPos,
                         int length)

write

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

Sea 0.4.0