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 such as int and double. It also contains a method for byte swapping evio format data.

Author:
heddle, timmer, wolin

Constructor Summary
ByteDataTransformer()
           
 
Method Summary
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 void intToBytes(int intVal, byte[] b, int off)
          Copies an integer value into 4 bytes of a byte array.
static void swap(java.nio.ByteBuffer srcBuf, java.nio.ByteBuffer destBuf)
          Swaps evio format data (event or bank) contained in a ByteBuffer.
 
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.

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.

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.

getAsLongArray

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

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.

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.

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.

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

swap

public static void swap(java.nio.ByteBuffer srcBuf,
                        java.nio.ByteBuffer destBuf)
                 throws EvioException
Swaps evio format data (event or bank) contained in a ByteBuffer. NOTE: the byte order of the source buffer must be set properly by the caller using ByteBuffer.order(java.nio.ByteOrder).

Parameters:
srcBuf - evio data (event or bank) to be swapped
destBuf - destination for swapped evio data; if null, swap in place
Throws:
EvioException - if data not in evio format