org.simantics.databoard.util.binary
Class LittleEndian

java.lang.Object
  extended by org.simantics.databoard.util.binary.LittleEndian

public class LittleEndian
extends java.lang.Object

DataInput and DataOutput serialize primitive numbers with big endian byte order. This utility gives little endian read and write.

Author:
Toni Kalajainen

Constructor Summary
LittleEndian()
           
 
Method Summary
static int getDynamicUInt32Length(int length)
          Get number of bytes for dynamic encoding of UInt32 (1-5 bytes)
static int getUInt(java.io.DataInput in, int maxValue)
          Decode an unsigned integer.
static int getUIntLength(int maxValue)
          Calculate unsigned integer encoding length.
static void putUInt(java.io.DataOutput out, int value, int maxValue)
          Encode and write an unsigned integer.
static double readDouble(java.io.DataInput in)
           
static int readDynamicUInt32(java.io.DataInput in)
           
static float readFloat(java.io.DataInput in)
           
static int readInt(java.io.DataInput in)
           
static long readLong(java.io.DataInput in)
           
static short readShort(java.io.DataInput in)
           
static int readUInt24(java.io.DataInput in)
           
static int readUnsignedShort(java.io.DataInput in)
           
static void writeDouble(java.io.DataOutput out, double d)
           
static void writeDynamicUInt32(java.io.DataOutput out, int length)
          Write UInt32 with dynamic encoding (1-5 bytes).
static void writeFloat(java.io.DataOutput out, float v)
           
static void writeInt(java.io.DataOutput out, int v)
           
static void writeLong(java.io.DataOutput out, long v)
           
static void writeShort(java.io.DataOutput out, int v)
           
static void writeUInt24(java.io.DataOutput out, int value)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LittleEndian

public LittleEndian()
Method Detail

readShort

public static short readShort(java.io.DataInput in)
                       throws java.io.IOException
Throws:
java.io.IOException

writeShort

public static void writeShort(java.io.DataOutput out,
                              int v)
                       throws java.io.IOException
Throws:
java.io.IOException

readUnsignedShort

public static int readUnsignedShort(java.io.DataInput in)
                             throws java.io.IOException
Throws:
java.io.IOException

readInt

public static int readInt(java.io.DataInput in)
                   throws java.io.IOException
Throws:
java.io.IOException

writeInt

public static void writeInt(java.io.DataOutput out,
                            int v)
                     throws java.io.IOException
Throws:
java.io.IOException

readLong

public static long readLong(java.io.DataInput in)
                     throws java.io.IOException
Throws:
java.io.IOException

writeLong

public static void writeLong(java.io.DataOutput out,
                             long v)
                      throws java.io.IOException
Throws:
java.io.IOException

readDouble

public static double readDouble(java.io.DataInput in)
                         throws java.io.IOException
Throws:
java.io.IOException

writeDouble

public static void writeDouble(java.io.DataOutput out,
                               double d)
                        throws java.io.IOException
Throws:
java.io.IOException

readFloat

public static float readFloat(java.io.DataInput in)
                       throws java.io.IOException
Throws:
java.io.IOException

writeFloat

public static void writeFloat(java.io.DataOutput out,
                              float v)
                       throws java.io.IOException
Throws:
java.io.IOException

writeUInt24

public static void writeUInt24(java.io.DataOutput out,
                               int value)
                        throws java.io.IOException
Throws:
java.io.IOException

readUInt24

public static int readUInt24(java.io.DataInput in)
                      throws java.io.IOException
Throws:
java.io.IOException

writeDynamicUInt32

public static void writeDynamicUInt32(java.io.DataOutput out,
                                      int length)
                               throws java.io.IOException
Write UInt32 with dynamic encoding (1-5 bytes).

Parameters:
out -
length -
Throws:
java.io.IOException

readDynamicUInt32

public static int readDynamicUInt32(java.io.DataInput in)
                             throws java.io.IOException
Throws:
java.io.IOException

getDynamicUInt32Length

public static int getDynamicUInt32Length(int length)
Get number of bytes for dynamic encoding of UInt32 (1-5 bytes)

Parameters:
length - length value
Returns:
bytes required (1-5)

getUInt

public static int getUInt(java.io.DataInput in,
                          int maxValue)
                   throws java.io.IOException
Decode an unsigned integer. The number of bytes read depends on maxValue.

Parameters:
in -
maxValue -
Returns:
int
Throws:
java.io.IOException

getUIntLength

public static int getUIntLength(int maxValue)
Calculate unsigned integer encoding length.

Parameters:
maxValue -
Returns:
0-4 bytes

putUInt

public static void putUInt(java.io.DataOutput out,
                           int value,
                           int maxValue)
                    throws java.io.IOException
Encode and write an unsigned integer. The number of bytes written depends on the maxValue.

Parameters:
out -
value -
maxValue -
Throws:
java.io.IOException