org.simantics.databoard.util.binary
Class Endian

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

public class Endian
extends java.lang.Object

DataInput and DataOutput serialize primitive numbers with big endian byte order. This utility absolutely does nothing but facades byte operations.

Author:
Toni Kalajainen

Constructor Summary
Endian()
           
 
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 int readDynamicUInt32(java.io.DataInput in)
           
static int readUInt24(java.io.DataInput in)
           
static void writeDynamicUInt32(java.io.DataOutput out, int length)
          Write UInt32 with dynamic encoding (1-5 bytes).
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

Endian

public Endian()
Method Detail

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