org.jlab.coda.jevio
Class ByteDataTransformer

java.lang.Object
  extended by org.jlab.coda.jevio.ByteDataTransformer

public class ByteDataTransformer
extends java.lang.Object

This utility class contains methods for transforming a raw byte array into arrays of other types and vice versa as well as other handy methods.

Author:
heddle, timmer, wolin

Constructor Summary
ByteDataTransformer()
           
 
Method Summary
static int byteBitsToInt(byte byteVal)
          Copies a 1-byte byte value into a 4-byte int while preserving bit pattern.
static double[] getAsDoubleArray(byte[] bytes, java.nio.ByteOrder byteOrder)
          Converts a byte array into a double array.
static float[] getAsFloatArray(byte[] bytes, java.nio.ByteOrder byteOrder)
          Converts a byte array into a float array.
static int[] getAsIntArray(byte[] bytes, java.nio.ByteOrder byteOrder)
          Converts a byte array into an int array.
static long[] getAsLongArray(byte[] bytes, java.nio.ByteOrder byteOrder)
          Converts a byte array into a long array.
static short[] getAsShortArray(byte[] bytes, java.nio.ByteOrder byteOrder)
          Converts a byte array into an short array.
static short[] getAsShortArray(byte[] bytes, int padding, java.nio.ByteOrder byteOrder)
          Converts a byte array into an short array while accounting for padding.
static void intToBytes(int intVal, byte[] b, int off)
          Copies an integer value into 4 bytes of a byte array.
static int shortBitsToInt(short shortVal)
          Copies a 2-byte short value into a 4-byte int while preserving bit pattern.
static void shortToBytes(short val, byte[] b, int off)
          Copies a short value into 2 bytes of a byte array.
static byte[] toBytes(double[] data, java.nio.ByteOrder byteOrder)
          Turn double array into byte array.
static void toBytes(double[] data, java.nio.ByteOrder byteOrder, byte[] dest, int off)
          Turn double array into byte array.
static byte[] toBytes(double data, java.nio.ByteOrder byteOrder)
          Turn double into byte array.
static void toBytes(double data, java.nio.ByteOrder byteOrder, byte[] dest, int off)
          Turn double into byte array.
static byte[] toBytes(float[] data, java.nio.ByteOrder byteOrder)
          Turn float array into byte array.
static void toBytes(float[] data, java.nio.ByteOrder byteOrder, byte[] dest, int off)
          Turn float array into byte array.
static byte[] toBytes(float data, java.nio.ByteOrder byteOrder)
          Turn float into byte array.
static void toBytes(float data, java.nio.ByteOrder byteOrder, byte[] dest, int off)
          Turn float into byte array.
static byte[] toBytes(int[] data, java.nio.ByteOrder byteOrder)
          Turn int array into byte array.
static void toBytes(int[] data, java.nio.ByteOrder byteOrder, byte[] dest, int off)
          Turn int array into byte array.
static byte[] toBytes(int[] data, int offset, int length, java.nio.ByteOrder byteOrder)
          Turn int array into byte array.
static byte[] toBytes(int data, java.nio.ByteOrder byteOrder)
          Turn int into byte array.
static void toBytes(int data, java.nio.ByteOrder byteOrder, byte[] dest, int off)
          Turn int into byte array.
static byte[] toBytes(long[] data, java.nio.ByteOrder byteOrder)
          Turn long array into byte array.
static void toBytes(long[] data, java.nio.ByteOrder byteOrder, byte[] dest, int off)
          Turn long array into byte array.
static byte[] toBytes(long data, java.nio.ByteOrder byteOrder)
          Turn long into byte array.
static void toBytes(long data, java.nio.ByteOrder byteOrder, byte[] dest, int off)
          Turn long into byte array.
static byte[] toBytes(short[] data, java.nio.ByteOrder byteOrder)
          Turn short array into byte array.
static void toBytes(short[] data, java.nio.ByteOrder byteOrder, byte[] dest, int off)
          Turn short array into byte array.
static byte[] toBytes(short data, java.nio.ByteOrder byteOrder)
          Turn short into byte array.
static void toBytes(short data, java.nio.ByteOrder byteOrder, byte[] dest, int off)
          Turn short into byte array.
static byte[] toBytes2(double[] data, java.nio.ByteOrder byteOrder)
          Turn double array into byte array.
static void toBytes2(double[] data, java.nio.ByteOrder byteOrder, byte[] dest, int off)
          Turn double array into byte array.
static byte[] toBytesStream(int[] data, java.nio.ByteOrder byteOrder)
          Turn int array into byte array.
static double toDouble(byte[] data, java.nio.ByteOrder byteOrder, int off)
          Turn section of byte array into a double.
static double toDouble(byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7, byte b8, java.nio.ByteOrder byteOrder)
          Turn 8 bytes into a double.
static double[] toDoubleArray(byte[] data, java.nio.ByteOrder byteOrder)
          Turn byte array into a double array.
static void toDoubleArray(byte[] data, java.nio.ByteOrder byteOrder, double[] dest, int off)
          Turn byte array into an double array.
static float toFloat(byte[] data, java.nio.ByteOrder byteOrder, int off)
          Turn section of byte array into a float.
static float toFloat(byte b1, byte b2, byte b3, byte b4, java.nio.ByteOrder byteOrder)
          Turn 4 bytes into a float.
static float[] toFloatArray(byte[] data, java.nio.ByteOrder byteOrder)
          Turn byte array into a float array.
static void toFloatArray(byte[] data, java.nio.ByteOrder byteOrder, float[] dest, int off)
          Turn byte array into an float array.
static int toInt(byte[] data, java.nio.ByteOrder byteOrder, int off)
          Turn section of byte array into an int.
static int toInt(byte b1, byte b2, byte b3, byte b4, java.nio.ByteOrder byteOrder)
          Turn 4 bytes into an int.
static int[] toIntArray(byte[] data, java.nio.ByteOrder byteOrder)
          Turn byte array into an int array.
static void toIntArray(byte[] data, java.nio.ByteOrder byteOrder, int[] dest, int off)
          Turn byte array into an int array.
static long toLong(byte[] data, java.nio.ByteOrder byteOrder, int off)
          Turn section of byte array into a long.
static long toLong(byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7, byte b8, java.nio.ByteOrder byteOrder)
          Turn 8 bytes into a long.
static long[] toLongArray(byte[] data, java.nio.ByteOrder byteOrder)
          Turn byte array into a long array.
static void toLongArray(byte[] data, java.nio.ByteOrder byteOrder, long[] dest, int off)
          Turn byte array into an long array.
static short toShort(byte[] data, java.nio.ByteOrder byteOrder, int off)
          Turn section of byte array into a short.
static short toShort(byte b1, byte b2, java.nio.ByteOrder byteOrder)
          Turn 2 bytes into a short.
static short[] toShortArray(byte[] data, java.nio.ByteOrder byteOrder)
          Turn byte array into a short array.
static void toShortArray(byte[] data, java.nio.ByteOrder byteOrder, short[] dest, int off)
          Turn byte array into an short array.
static short[] toShortArray(byte[] data, int padding, java.nio.ByteOrder byteOrder)
          Turn byte array into a short array while taking padding into account.
static void toShortArray(byte[] data, int padding, java.nio.ByteOrder byteOrder, short[] dest, int off)
          Turn byte array into a short array while taking padding into account.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteDataTransformer

public ByteDataTransformer()
Method Detail

getAsIntArray

public static int[] getAsIntArray(byte[] bytes,
                                  java.nio.ByteOrder byteOrder)
Converts a byte array into an int array. Use toIntArray(byte[], java.nio.ByteOrder) for better performance.

Parameters:
bytes - the byte array.
byteOrder - the endianness of the data in the byte array, ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN.
Returns:
the raw bytes converted into an int array.

getAsShortArray

public static short[] getAsShortArray(byte[] bytes,
                                      java.nio.ByteOrder byteOrder)
Converts a byte array into an short array. Use toShortArray(byte[], java.nio.ByteOrder) for better performance.

Parameters:
bytes - the byte array.
byteOrder - the endianness of the data in the byte array, ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN.
Returns:
the raw bytes converted into an int array.

getAsShortArray

public static short[] getAsShortArray(byte[] bytes,
                                      int padding,
                                      java.nio.ByteOrder byteOrder)
Converts a byte array into an short array while accounting for padding. Use toShortArray(byte[], int, java.nio.ByteOrder) for better performance.

Parameters:
bytes - the byte array.
padding - number of bytes at the end of the byte array to ignore. Valid values are 0 and mulitples of 2 (though only 0 & 2 are used).
byteOrder - the endianness of the data in the byte array, ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN.
Returns:
the raw bytes converted into an int array.

getAsLongArray

public static long[] getAsLongArray(byte[] bytes,
                                    java.nio.ByteOrder byteOrder)
Converts a byte array into a long array. Use toLongArray(byte[], java.nio.ByteOrder) for better performance.

Parameters:
bytes - the byte array.
byteOrder - the endianness of the data in the byte array, ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN.
Returns:
the raw bytes converted into a long array.

getAsDoubleArray

public static double[] getAsDoubleArray(byte[] bytes,
                                        java.nio.ByteOrder byteOrder)
Converts a byte array into a double array. Use toDoubleArray(byte[], java.nio.ByteOrder) for better performance.

Parameters:
bytes - the byte array.
byteOrder - the endianness of the data in the byte array, ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN.
Returns:
the raw bytes converted into a double array.

getAsFloatArray

public static float[] getAsFloatArray(byte[] bytes,
                                      java.nio.ByteOrder byteOrder)
Converts a byte array into a float array. Use toFloatArray(byte[], java.nio.ByteOrder) for better performance.

Parameters:
bytes - the byte array.
byteOrder - the endianness of the data in the byte array, ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN.
Returns:
the raw bytes converted into a float array.

shortBitsToInt

public static final int shortBitsToInt(short shortVal)
Copies a 2-byte short value into a 4-byte int while preserving bit pattern. In other words, it treats the short as an unsigned value. The resulting int does NOT undergo sign extension (bits of highest 2 bytes are not all ones), and will not be a negative number.

Parameters:
shortVal - short value considered to be unsigned
Returns:
the equivalent int value

byteBitsToInt

public static final int byteBitsToInt(byte byteVal)
Copies a 1-byte byte value into a 4-byte int while preserving bit pattern. In other words, it treats the byte as an unsigned value. The resulting int does NOT undergo sign extension (bits of highest 3 bytes are not all ones), and will not be a negative number.

Parameters:
byteVal - byte value considered to be unsigned
Returns:
the equivalent int value

intToBytes

public static final void intToBytes(int intVal,
                                    byte[] b,
                                    int off)
Copies an integer value into 4 bytes of a byte array.

Parameters:
intVal - integer value
b - byte array
off - offset into the byte array

shortToBytes

public static final void shortToBytes(short val,
                                      byte[] b,
                                      int off)
Copies a short value into 2 bytes of a byte array.

Parameters:
val - short value
b - byte array
off - offset into the byte array

toBytes

public static byte[] toBytes(short data,
                             java.nio.ByteOrder byteOrder)
Turn short into byte array.

Parameters:
data - short to convert
byteOrder - byte order of returned byte array (big endian if null)
Returns:
byte array representing short

toBytes

public static void toBytes(short data,
                           java.nio.ByteOrder byteOrder,
                           byte[] dest,
                           int off)
                    throws EvioException
Turn short into byte array. Avoids creation of new byte array with each call.

Parameters:
data - short to convert
byteOrder - byte order of returned bytes (big endian if null)
dest - array in which to store returned bytes
off - offset into dest array where returned bytes are placed
Throws:
EvioException - if dest is null or too small or offset negative

toBytes

public static byte[] toBytes(short[] data,
                             java.nio.ByteOrder byteOrder)
Turn short array into byte array.

Parameters:
data - short array to convert
byteOrder - byte order of returned bytes (big endian if null)
Returns:
byte array representing short array or null if data is null

toBytes

public static void toBytes(short[] data,
                           java.nio.ByteOrder byteOrder,
                           byte[] dest,
                           int off)
                    throws EvioException
Turn short array into byte array. Avoids creation of new byte array with each call.

Parameters:
data - short array to convert
byteOrder - byte order of written bytes (big endian if null)
dest - array in which to store written bytes
off - offset into dest array where returned bytes are placed
Throws:
EvioException - if data is null, dest is null or too small, or offset negative

toBytes

public static byte[] toBytes(int data,
                             java.nio.ByteOrder byteOrder)
Turn int into byte array.

Parameters:
data - int to convert
byteOrder - byte order of returned byte array (big endian if null)
Returns:
byte array representing int

toBytes

public static void toBytes(int data,
                           java.nio.ByteOrder byteOrder,
                           byte[] dest,
                           int off)
                    throws EvioException
Turn int into byte array. Avoids creation of new byte array with each call.

Parameters:
data - int to convert
byteOrder - byte order of returned bytes (big endian if null)
dest - array in which to store returned bytes
off - offset into dest array where returned bytes are placed
Throws:
EvioException - if dest is null or too small or offset negative

toBytes

public static byte[] toBytes(int[] data,
                             java.nio.ByteOrder byteOrder)
Turn int array into byte array.

Parameters:
data - int array to convert
byteOrder - byte order of returned bytes (big endian if null)
Returns:
byte array representing int array or null if data is null

toBytes

public static byte[] toBytes(int[] data,
                             int offset,
                             int length,
                             java.nio.ByteOrder byteOrder)
Turn int array into byte array.

Parameters:
data - int array to convert
offset - into int array
length - number of integers to conver to bytes
byteOrder - byte order of returned bytes (big endian if null)
Returns:
byte array representing int array or null if data is null

toBytes

public static void toBytes(int[] data,
                           java.nio.ByteOrder byteOrder,
                           byte[] dest,
                           int off)
                    throws EvioException
Turn int array into byte array. Avoids creation of new byte array with each call.

Parameters:
data - int array to convert
byteOrder - byte order of written bytes (big endian if null)
dest - array in which to store written bytes
off - offset into dest array where returned bytes are placed
Throws:
EvioException - if data is null, dest is null or too small, or offset negative

toBytesStream

public static byte[] toBytesStream(int[] data,
                                   java.nio.ByteOrder byteOrder)
Turn int array into byte array. Uses IO streams to do the work - very inefficient. Keep around for tutorial purposes.

Parameters:
data - int array to convert
byteOrder - byte order of returned bytes (big endian if null)
Returns:
byte array representing int array

toBytes

public static byte[] toBytes(long data,
                             java.nio.ByteOrder byteOrder)
Turn long into byte array.

Parameters:
data - long to convert
byteOrder - byte order of returned byte array (big endian if null)
Returns:
byte array representing long

toBytes

public static void toBytes(long data,
                           java.nio.ByteOrder byteOrder,
                           byte[] dest,
                           int off)
                    throws EvioException
Turn long into byte array. Avoids creation of new byte array with each call.

Parameters:
data - long to convert
byteOrder - byte order of returned bytes (big endian if null)
dest - array in which to store returned bytes
off - offset into dest array where returned bytes are placed
Throws:
EvioException - if dest is null or too small or offset negative

toBytes

public static byte[] toBytes(long[] data,
                             java.nio.ByteOrder byteOrder)
Turn long array into byte array.

Parameters:
data - long array to convert
byteOrder - byte order of returned bytes (big endian if null)
Returns:
byte array representing long array or null if data is null

toBytes

public static void toBytes(long[] data,
                           java.nio.ByteOrder byteOrder,
                           byte[] dest,
                           int off)
                    throws EvioException
Turn long array into byte array. Avoids creation of new byte array with each call.

Parameters:
data - long array to convert
byteOrder - byte order of written bytes (big endian if null)
dest - array in which to store written bytes
off - offset into dest array where returned bytes are placed
Throws:
EvioException - if data is null, dest is null or too small, or offset negative

toBytes

public static byte[] toBytes(float data,
                             java.nio.ByteOrder byteOrder)
Turn float into byte array.

Parameters:
data - float to convert
byteOrder - byte order of returned byte array (big endian if null)
Returns:
byte array representing float

toBytes

public static void toBytes(float data,
                           java.nio.ByteOrder byteOrder,
                           byte[] dest,
                           int off)
                    throws EvioException
Turn float into byte array. Avoids creation of new byte array with each call.

Parameters:
data - float to convert
byteOrder - byte order of returned bytes (big endian if null)
dest - array in which to store returned bytes
off - offset into dest array where returned bytes are placed
Throws:
EvioException - if dest is null or too small or offset negative

toBytes

public static byte[] toBytes(float[] data,
                             java.nio.ByteOrder byteOrder)
Turn float array into byte array.

Parameters:
data - float array to convert
byteOrder - byte order of returned bytes (big endian if null)
Returns:
byte array representing float array or null if data is null

toBytes

public static void toBytes(float[] data,
                           java.nio.ByteOrder byteOrder,
                           byte[] dest,
                           int off)
                    throws EvioException
Turn float array into byte array. Avoids creation of new byte array with each call.

Parameters:
data - float array to convert
byteOrder - byte order of written bytes (big endian if null)
dest - array in which to store written bytes
off - offset into dest array where returned bytes are placed
Throws:
EvioException - if data is null, dest is null or too small, or offset negative

toBytes

public static byte[] toBytes(double data,
                             java.nio.ByteOrder byteOrder)
Turn double into byte array.

Parameters:
data - double to convert
byteOrder - byte order of returned byte array (big endian if null)
Returns:
byte array representing double

toBytes

public static void toBytes(double data,
                           java.nio.ByteOrder byteOrder,
                           byte[] dest,
                           int off)
                    throws EvioException
Turn double into byte array. Avoids creation of new byte array with each call.

Parameters:
data - double to convert
byteOrder - byte order of returned bytes (big endian if null)
dest - array in which to store returned bytes
off - offset into dest array where returned bytes are placed
Throws:
EvioException - if dest is null or too small or offset negative

toBytes

public static byte[] toBytes(double[] data,
                             java.nio.ByteOrder byteOrder)
Turn double array into byte array.

Parameters:
data - double array to convert
byteOrder - byte order of returned bytes (big endian if null)
Returns:
byte array representing double array or null if data is null

toBytes

public static void toBytes(double[] data,
                           java.nio.ByteOrder byteOrder,
                           byte[] dest,
                           int off)
                    throws EvioException
Turn double array into byte array. Avoids creation of new byte array with each call.

Parameters:
data - double array to convert
byteOrder - byte order of written bytes (big endian if null)
dest - array in which to store written bytes
off - offset into dest array where returned bytes are placed
Throws:
EvioException - if data is null, dest is null or too small, or offset negative

toBytes2

public static byte[] toBytes2(double[] data,
                              java.nio.ByteOrder byteOrder)
Turn double array into byte array. Slower than toBytes(double[], ByteOrder). Keep this around for completeness purposes - a record of what was already tried and found wanting. Tried this for all data types.

Parameters:
data - double array to convert
byteOrder - byte order of returned bytes (big endian if null)
Returns:
byte array representing double array or null if data is null

toBytes2

public static void toBytes2(double[] data,
                            java.nio.ByteOrder byteOrder,
                            byte[] dest,
                            int off)
                     throws EvioException
Turn double array into byte array. Avoids creation of new byte array with each call. Slower than toBytes(double[], ByteOrder, byte[], int). Keep this around for completeness purposes - a record of what was already tried and found wanting. Tried this for all data types.

Parameters:
data - double array to convert
byteOrder - byte order of returned bytes (big endian if null)
dest - array in which to store returned bytes
off - offset into dest array where returned bytes are placed
Throws:
EvioException - if data is null, dest is null or too small, or offset negative

toShort

public static short toShort(byte[] data,
                            java.nio.ByteOrder byteOrder,
                            int off)
                     throws EvioException
Turn section of byte array into a short.

Parameters:
data - byte array to convert
byteOrder - byte order of supplied bytes (big endian if null)
off - offset into data array
Returns:
short converted from byte array
Throws:
EvioException - if data is null or wrong size, or off is negative

toShort

public static short toShort(byte b1,
                            byte b2,
                            java.nio.ByteOrder byteOrder)
Turn 2 bytes into a short.

Parameters:
b1 - 1st byte
b2 - 2nd byte
byteOrder - if big endian, 1st byte is most significant (big endian if null)
Returns:
short converted from byte array

toShortArray

public static short[] toShortArray(byte[] data,
                                   java.nio.ByteOrder byteOrder)
                            throws EvioException
Turn byte array into a short array.

Parameters:
data - byte array to convert
byteOrder - byte order of supplied bytes (big endian if null)
Returns:
short array converted from byte array
Throws:
EvioException - if data is null or odd size

toShortArray

public static short[] toShortArray(byte[] data,
                                   int padding,
                                   java.nio.ByteOrder byteOrder)
                            throws EvioException
Turn byte array into a short array while taking padding into account.

Parameters:
data - byte array to convert
padding - number of bytes at the end of the byte array to ignore. Valid values are 0 and 2
byteOrder - byte order of supplied bytes (big endian if null)
Returns:
short array converted from byte array
Throws:
EvioException - if data is null or odd size; padding not 0 or 2

toShortArray

public static void toShortArray(byte[] data,
                                int padding,
                                java.nio.ByteOrder byteOrder,
                                short[] dest,
                                int off)
                         throws EvioException
Turn byte array into a short array while taking padding into account.

Parameters:
data - byte array to convert
padding - number of bytes at the end of the byte array to ignore. Valid values are 0 and 2
byteOrder - byte order of supplied bytes (big endian if null)
dest - array in which to write converted bytes
off - offset into dest array
Throws:
EvioException - if data is null or wrong size; dest is null, wrong size, or off < 0

toShortArray

public static void toShortArray(byte[] data,
                                java.nio.ByteOrder byteOrder,
                                short[] dest,
                                int off)
                         throws EvioException
Turn byte array into an short array.

Parameters:
data - byte array to convert
byteOrder - byte order of supplied bytes (big endian if null)
dest - array in which to write converted bytes
off - offset into dest array
Throws:
EvioException - if data is null or wrong size; dest is null, wrong size, or off < 0

toInt

public static int toInt(byte[] data,
                        java.nio.ByteOrder byteOrder,
                        int off)
                 throws EvioException
Turn section of byte array into an int.

Parameters:
data - byte array to convert
byteOrder - byte order of supplied bytes (big endian if null)
off - offset into data array
Returns:
int converted from byte array
Throws:
EvioException - if data is null or wrong size, or off is negative

toInt

public static int toInt(byte b1,
                        byte b2,
                        byte b3,
                        byte b4,
                        java.nio.ByteOrder byteOrder)
Turn 4 bytes into an int.

Parameters:
b1 - 1st byte
b2 - 2nd byte
b3 - 3rd byte
b4 - 4th byte
byteOrder - if big endian, 1st byte is most significant & 4th is least (big endian if null)
Returns:
int converted from byte array

toIntArray

public static int[] toIntArray(byte[] data,
                               java.nio.ByteOrder byteOrder)
                        throws EvioException
Turn byte array into an int array.

Parameters:
data - byte array to convert
byteOrder - byte order of supplied bytes (big endian if null)
Returns:
int array converted from byte array
Throws:
EvioException - if data is null or wrong size

toIntArray

public static void toIntArray(byte[] data,
                              java.nio.ByteOrder byteOrder,
                              int[] dest,
                              int off)
                       throws EvioException
Turn byte array into an int array.

Parameters:
data - byte array to convert
byteOrder - byte order of supplied bytes (big endian if null)
dest - array in which to write converted bytes
off - offset into dest array
Throws:
EvioException - if data is null or wrong size; dest is null, wrong size, or off < 0

toLong

public static long toLong(byte[] data,
                          java.nio.ByteOrder byteOrder,
                          int off)
                   throws EvioException
Turn section of byte array into a long.

Parameters:
data - byte array to convert
byteOrder - byte order of supplied bytes (big endian if null)
off - offset into data array
Returns:
long converted from byte array
Throws:
EvioException - if data is null or wrong size, or off is negative

toLong

public static long toLong(byte b1,
                          byte b2,
                          byte b3,
                          byte b4,
                          byte b5,
                          byte b6,
                          byte b7,
                          byte b8,
                          java.nio.ByteOrder byteOrder)
Turn 8 bytes into a long.

Parameters:
b1 - 1st byte
b2 - 2nd byte
b3 - 3rd byte
b4 - 4th byte
b5 - 5th byte
b6 - 6th byte
b7 - 7th byte
b8 - 8th byte
byteOrder - if big endian, 1st byte is most significant & 8th least (big endian if null)
Returns:
long converted from byte array

toLongArray

public static long[] toLongArray(byte[] data,
                                 java.nio.ByteOrder byteOrder)
                          throws EvioException
Turn byte array into a long array.

Parameters:
data - byte array to convert
byteOrder - byte order of supplied bytes (big endian if null)
Returns:
long array converted from byte array
Throws:
EvioException - if data is null or wrong size

toLongArray

public static void toLongArray(byte[] data,
                               java.nio.ByteOrder byteOrder,
                               long[] dest,
                               int off)
                        throws EvioException
Turn byte array into an long array.

Parameters:
data - byte array to convert
byteOrder - byte order of supplied bytes (big endian if null)
dest - array in which to write converted bytes
off - offset into dest array
Throws:
EvioException - if data is null or wrong size; dest is null, wrong size, or off < 0

toFloat

public static float toFloat(byte[] data,
                            java.nio.ByteOrder byteOrder,
                            int off)
                     throws EvioException
Turn section of byte array into a float.

Parameters:
data - byte array to convert
byteOrder - byte order of supplied bytes (big endian if null)
off - offset into data array
Returns:
float converted from byte array
Throws:
EvioException - if data is null or wrong size, or off is negative

toFloat

public static float toFloat(byte b1,
                            byte b2,
                            byte b3,
                            byte b4,
                            java.nio.ByteOrder byteOrder)
Turn 4 bytes into a float.

Parameters:
b1 - 1st byte
b2 - 2nd byte
b3 - 3rd byte
b4 - 4th byte
byteOrder - if big endian, 1st byte is most significant & 4th least (big endian if null)
Returns:
float converted from byte array

toFloatArray

public static float[] toFloatArray(byte[] data,
                                   java.nio.ByteOrder byteOrder)
                            throws EvioException
Turn byte array into a float array.

Parameters:
data - byte array to convert
byteOrder - byte order of supplied bytes (big endian if null)
Returns:
float array converted from byte array
Throws:
EvioException - if data is null or wrong size

toFloatArray

public static void toFloatArray(byte[] data,
                                java.nio.ByteOrder byteOrder,
                                float[] dest,
                                int off)
                         throws EvioException
Turn byte array into an float array.

Parameters:
data - byte array to convert
byteOrder - byte order of supplied bytes (big endian if null)
dest - array in which to write converted bytes
off - offset into dest array
Throws:
EvioException - if data is null or wrong size; dest is null, wrong size, or off < 0

toDouble

public static double toDouble(byte[] data,
                              java.nio.ByteOrder byteOrder,
                              int off)
                       throws EvioException
Turn section of byte array into a double.

Parameters:
data - byte array to convert
byteOrder - byte order of supplied bytes (big endian if null)
off - offset into data array
Returns:
double converted from byte array
Throws:
EvioException - if data is null or wrong size, or off is negative

toDouble

public static double toDouble(byte b1,
                              byte b2,
                              byte b3,
                              byte b4,
                              byte b5,
                              byte b6,
                              byte b7,
                              byte b8,
                              java.nio.ByteOrder byteOrder)
Turn 8 bytes into a double.

Parameters:
b1 - 1st byte
b2 - 2nd byte
b3 - 3rd byte
b4 - 4th byte
b5 - 5th byte
b6 - 6th byte
b7 - 7th byte
b8 - 8th byte
byteOrder - if big endian, 1st byte is most significant & 8th least (big endian if null)
Returns:
double converted from byte array

toDoubleArray

public static double[] toDoubleArray(byte[] data,
                                     java.nio.ByteOrder byteOrder)
                              throws EvioException
Turn byte array into a double array.

Parameters:
data - byte array to convert
byteOrder - byte order of supplied bytes (big endian if null)
Returns:
double array converted from byte array
Throws:
EvioException - if data is null or wrong size

toDoubleArray

public static void toDoubleArray(byte[] data,
                                 java.nio.ByteOrder byteOrder,
                                 double[] dest,
                                 int off)
                          throws EvioException
Turn byte array into an double array.

Parameters:
data - byte array to convert
byteOrder - byte order of supplied bytes (big endian if null)
dest - array in which to write converted bytes
off - offset into dest array
Throws:
EvioException - if data is null or wrong size; dest is null, wrong size, or off < 0