Firefish 0.5.10

gov.lbl.dsd.util
Class ByteConverter

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

public class ByteConverter
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 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 bytes! Please don't flame for not writing redundant javadoc for each and every method.

Version:
$Revision: 1.2 $, $Date: 2004/01/30 01:18:01 $

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 String readBytes(byte[] src, int srcPos, char[] buffer, int length)
          The inverse to writeBytes(String, int, byte[], int, int); each single byte is converted to a 2 byte char.
static char readChar(byte[] src, int srcPos)
           
static String readChars(byte[] src, int srcPos, char[] buffer, int length)
           
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 int readUTF(byte[] src, int srcPos, char[] dest, int destPos, int[] srcPosNext)
           
static String readUTF(byte[] src, int srcPos, int[] srcPosNext)
           
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 v, 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)
           
static void writeBytes(String src, int srcPos, byte[] dest, int destPos, int length)
          Writes out the string to the underlying byte array as a sequence of bytes.
static void writeChars(String src, int srcPos, byte[] dest, int destPos, int length)
           
static int writeUTF(String src, int srcPos, byte[] dest, int destPos, int length)
          Writes a string to the underlying output stream using UTF-8 encoding in a machine-independent manner.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

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)

readBytes

public static String readBytes(byte[] src,
                               int srcPos,
                               char[] buffer,
                               int length)
The inverse to writeBytes(String, int, byte[], int, int); each single byte is converted to a 2 byte char.


readChar

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

readChars

public static String readChars(byte[] src,
                               int srcPos,
                               char[] buffer,
                               int length)

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)

readUTF

public static String readUTF(byte[] src,
                             int srcPos,
                             int[] srcPosNext)
                      throws UTFDataFormatException
Throws:
UTFDataFormatException

readUTF

public static int readUTF(byte[] src,
                          int srcPos,
                          char[] dest,
                          int destPos,
                          int[] srcPosNext)
                   throws UTFDataFormatException
Throws:
UTFDataFormatException

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 v,
                         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)

writeBytes

public static void writeBytes(String src,
                              int srcPos,
                              byte[] dest,
                              int destPos,
                              int length)
Writes out the string to the underlying byte array as a sequence of bytes. Each character in the string is written out, in sequence, by ignoring its high eight bits.


writeChars

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

writeUTF

public static int writeUTF(String src,
                           int srcPos,
                           byte[] dest,
                           int destPos,
                           int length)
                    throws UTFDataFormatException
Writes a string to the underlying output stream using UTF-8 encoding in a machine-independent manner.

First, two bytes are written to the output stream as if by the writeShort method giving the number of bytes to follow. This value is the number of bytes actually written out, not the length of the string. Following the length, each character of the string is output, in sequence, using the UTF-8 encoding for the character. If no exception is thrown, the counter written is incremented by the total number of bytes written to the output stream. This will be at least two plus the length of str, and at most two plus thrice the length of str.

Throws:
IOException - if an I/O error occurs.
UTFDataFormatException

Firefish 0.5.10

Jump to the Firefish Homepage