org.exist.util
Class ByteConversion

java.lang.Object
  extended byorg.exist.util.ByteConversion

public class ByteConversion
extends java.lang.Object

A collection of static methods to write integer values from/to a byte array.

Author:
Wolfgang Meier

Constructor Summary
ByteConversion()
           
 
Method Summary
static int byteToInt(byte[] data, int start)
          Read an integer value from the specified byte array, starting at start.
static long byteToLong(byte[] data, int start)
          Read a long value from the specified byte array, starting at start.
static short byteToShort(byte[] data, int start)
          Read a short value from the specified byte array, starting at start.
static byte[] intToByte(int v, byte[] data, int start)
          Write an int value to the specified byte array.
static byte[] longToByte(long v)
          Write an int value to a newly allocated byte array.
static byte[] longToByte(long v, byte[] data, int start)
          Write a long value to the specified byte array.
static byte[] shortToByte(short v)
          Write a short value to a newly allocated byte array.
static byte[] shortToByte(short v, byte[] data, int start)
          Write a short value to the specified byte array.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteConversion

public ByteConversion()
Method Detail

byteToInt

public static final int byteToInt(byte[] data,
                                  int start)
Read an integer value from the specified byte array, starting at start.


byteToLong

public static final long byteToLong(byte[] data,
                                    int start)
Read a long value from the specified byte array, starting at start.


byteToShort

public static final short byteToShort(byte[] data,
                                      int start)
Read a short value from the specified byte array, starting at start.


intToByte

public static final byte[] intToByte(int v,
                                     byte[] data,
                                     int start)
Write an int value to the specified byte array. The first byte is written into the location specified by start.

Parameters:
v - the value
data - the byte array to write into
start - the offset
Returns:
the byte array

longToByte

public static final byte[] longToByte(long v,
                                      byte[] data,
                                      int start)
Write a long value to the specified byte array. The first byte is written into the location specified by start.

Parameters:
v - the value
data - the byte array to write into
start - the offset
Returns:
the byte array

longToByte

public static final byte[] longToByte(long v)
Write an int value to a newly allocated byte array.

Parameters:
v - the value
Returns:
the byte array

shortToByte

public static final byte[] shortToByte(short v,
                                       byte[] data,
                                       int start)
Write a short value to the specified byte array. The first byte is written into the location specified by start.

Parameters:
v - the value
data - the byte array to write into
start - the offset
Returns:
the byte array

shortToByte

public static final byte[] shortToByte(short v)
Write a short value to a newly allocated byte array.

Parameters:
v - the value
Returns:
the byte array


Copyright (C) Wolfgang Meier. All rights reserved.