fulmine.protocol.specification
Class ByteWriter

java.lang.Object
  extended by fulmine.protocol.specification.ByteWriter

public final class ByteWriter
extends Object

Utility methods for writing primitives to a byte[] using the fulmine delta (FD) protocol. As per the protocol, integrals can be compacted; the appropriate integral write methods perform this compacting.

Please refer to the "Fulmine Delta Transmission Protocol" specification for a complete description of the fulmine serialisation technique.

Author:
Ramon Servadei
See Also:
ByteReader

Constructor Summary
ByteWriter()
           
 
Method Summary
static byte[] getBytes(String data)
          Get the byte[] for that data string encoded to ByteConstants.ENCODING.
static int writeBoolean(boolean data, byte[][] bytes, int start)
          Transform the data into a byte[] representation.
static int writeBytes(byte[] data, byte[][] buffer, int start)
          Write the data byte[] into buffer[0][start]
static int writeDouble(double data, byte[][] bytes, int start)
          Transform the data into a byte[] representation.
static int writeFloat(float data, byte[][] bytes, int start)
          Transform the data into a byte[] representation.
static int writeInteger(int data, byte[][] bytes, int start)
          Transform the data into a byte[] representation.
static void writeIntegerAsBytes(int data, byte[][] buffer, int startFrom, int numberOfBytes)
          Write the integer data into buffer[0], starting at buffer[0][startFrom].
static int writeLong(long data, byte[][] bytes, int start)
          Transform the data into a byte[] representation.
static int writeString(String data, byte[][] bytes, int start)
          Transform the data into a byte[] representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteWriter

public ByteWriter()
Method Detail

writeBytes

public static int writeBytes(byte[] data,
                             byte[][] buffer,
                             int start)
Write the data byte[] into buffer[0][start]

Parameters:
data - the data to transform into a byte[] representation
buffer - buffer[0] will hold the data
start - the position in bytes[0] where the data should be written
Returns:
the number of bytes written

writeString

public static int writeString(String data,
                              byte[][] bytes,
                              int start)
Transform the data into a byte[] representation. The byte data is written to bytes[0][start].

Parameters:
data - the data to transform into a byte[] representation
bytes - bytes[0] will hold the data
start - the position in bytes[0] where the data should be written
Returns:
the number of bytes written. The number of bytes written is 2x the number of characters in the data (UTF16 character is 2 bytes).

writeBoolean

public static int writeBoolean(boolean data,
                               byte[][] bytes,
                               int start)
Transform the data into a byte[] representation. The byte data is written to bytes[0][start].

Parameters:
data - the data to transform into a byte[] representation
bytes - bytes[0] will hold the data
start - the position in bytes[0] where the data should be written
Returns:
the number of bytes written. For a boolean, 1 byte is written with a value 0 for false, 1 for true.

writeFloat

public static int writeFloat(float data,
                             byte[][] bytes,
                             int start)
Transform the data into a byte[] representation. The byte data is written to bytes[0][start].

Parameters:
data - the data to transform into a byte[] representation
bytes - bytes[0] will hold the data
start - the position in bytes[0] where the data should be written
Returns:
the number of bytes written. For a float, the raw bits are written into the byte[], this will always take up 4 bytes.

writeDouble

public static int writeDouble(double data,
                              byte[][] bytes,
                              int start)
Transform the data into a byte[] representation. The byte data is written to bytes[0][start].

Parameters:
data - the data to transform into a byte[] representation
bytes - bytes[0] will hold the data
start - the position in bytes[0] where the data should be written
Returns:
the number of bytes written. For a double the raw bits are written into the byte[], this will always take up 8 bytes.

writeInteger

public static int writeInteger(int data,
                               byte[][] bytes,
                               int start)
Transform the data into a byte[] representation. The byte data is written to bytes[0][start].

Parameters:
data - the data to transform into a byte[] representation
bytes - bytes[0] will hold the data
start - the position in bytes[0] where the data should be written
Returns:
the number of bytes written. The number of bytes written depends on the integral value.

writeLong

public static int writeLong(long data,
                            byte[][] bytes,
                            int start)
Transform the data into a byte[] representation. The byte data is written to bytes[0][start].

Parameters:
data - the data to transform into a byte[] representation
bytes - bytes[0] will hold the data
start - the position in bytes[0] where the data should be written
Returns:
the number of bytes written. The number of bytes written depends on the integral value.

getBytes

public static byte[] getBytes(String data)
Get the byte[] for that data string encoded to ByteConstants.ENCODING.

Parameters:
data - the string to get the byte[] for
Returns:
the byte[] for the string in the encoding format or an empty array if the string is null

writeIntegerAsBytes

public static void writeIntegerAsBytes(int data,
                                       byte[][] buffer,
                                       int startFrom,
                                       int numberOfBytes)
Write the integer data into buffer[0], starting at buffer[0][startFrom]. Only the bytes of the integer up to numberOfBytes are written.

Parameters:
data - the data to write into buffer[0][startFrom]
buffer - the buffer to hold the data
startFrom - the index in buffer[0] to start writing the bytes
numberOfBytes - the number of bytes of data to write, starting from the least significant byte


Copyright © 2007-2009. All Rights Reserved.