public final class CompositeData
extends java.lang.Object
implements java.lang.Cloneable
Modifier and Type | Class and Description |
---|---|
static class |
CompositeData.Data
This class is used to provide all data when constructing a CompositeData object.
|
Constructor and Description |
---|
CompositeData(byte[] rawBytes,
java.nio.ByteOrder byteOrder)
Constructor used when reading existing data.
|
CompositeData(java.lang.String format,
CompositeData.Data data)
Constructor used for creating this object from scratch.
|
CompositeData(java.lang.String format,
int formatTag,
CompositeData.Data data,
int dataTag,
int dataNum)
Constructor used for creating this object from scratch.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Method to clone a CompositeData object.
|
static java.util.List<java.lang.Integer> |
compositeFormatToInt(java.lang.String fmt)
This method transforms a composite, format-containing
ASCII string to an int array.
|
static void |
dataToRawBytes(java.nio.ByteBuffer rawBuf,
CompositeData.Data data,
java.util.List<java.lang.Integer> ifmt)
This method takes a CompositeData object and a transformed format string
and uses that to write data into a buffer/array in raw form.
|
static byte[] |
generateRawBytes(CompositeData[] data)
This method generates raw bytes of evio format from an array of CompositeData objects.
|
java.lang.Byte |
getByte()
This method gets the next data item as a Byte object.
|
java.nio.ByteOrder |
getByteOrder()
This method gets the raw data byte order.
|
java.lang.Double |
getDouble()
This method gets the next data item as a Double object.
|
java.lang.Float |
getFloat()
This method gets the next data item as a Float object.
|
java.lang.String |
getFormat()
This method gets the format string.
|
java.lang.Integer |
getHollerit()
This method gets the next data item (which is of Hollerit type) as an Integer object.
|
java.lang.Integer |
getInt()
This method gets the next data item as an Integer object.
|
java.util.List<java.lang.Object> |
getItems()
This method gets a list of all the data items inside the composite.
|
java.lang.Long |
getLong()
This method gets the next data item as a Long object.
|
java.lang.Integer |
getmValue()
This method gets the next m value item as an Integer object.
|
java.util.List<java.lang.Byte> |
getmValues()
This method gets a list of all the m values of the data items inside the composite.
|
java.lang.Integer |
getnValue()
This method gets the next n value item as an Integer object.
|
java.lang.Integer |
getNValue()
This method gets the next N value item as an Integer object.
|
java.util.List<java.lang.Short> |
getnValues()
This method gets a list of all the n values of the data items inside the composite.
|
java.util.List<java.lang.Integer> |
getNValues()
This method gets a list of all the N values of the data items inside the composite.
|
int |
getPadding()
Get the data padding (0, 1, 2, or 3 bytes).
|
byte[] |
getRawBytes()
This method gets the raw byte representation of this object's data.
|
java.lang.Short |
getShort()
This method gets the next data item as a Short object.
|
java.lang.String[] |
getStrings()
This method gets the next data item as a String array.
|
java.util.List<DataType> |
getTypes()
This method gets a list of all the types of the data items inside the composite.
|
int |
index()
This methods returns the index of the data item to be returned
on the next call to one of the get<Type>() methods
(e.g.
|
void |
index(int index)
This methods sets the index of the data item to be returned
on the next call to one of the get<Type>() methods
(e.g.
|
static CompositeData[] |
parse(byte[] rawBytes,
java.nio.ByteOrder byteOrder)
This method parses an array of raw bytes into an array of CompositeData objects.
|
void |
process()
This method swaps EVIO composite type data, in place, to big endian (IEEE)
if currently little endian (DECS).
|
static java.lang.String |
stringsToFormat(java.lang.String[] strings)
This method helps the CompositeData object creator by
finding the proper format string parameter for putting
this array of Strings into its data.
|
void |
swap()
This method swaps the data of this composite type between big and
little endian.
|
static void |
swapAll(byte[] src,
int srcOff,
byte[] dest,
int destOff,
int length,
java.nio.ByteOrder srcOrder)
This method converts (swaps) a buffer of EVIO composite type between big and
little endian.
|
static void |
swapData(byte[] src,
int srcOff,
byte[] dest,
int destOff,
int nBytes,
java.util.List<java.lang.Integer> ifmt,
java.nio.ByteOrder srcOrder)
This method converts (swaps) an array of EVIO composite type data
between IEEE (big endian) and DECS (little endian).
|
static void |
swapData(java.nio.ByteBuffer srcBuf,
java.nio.ByteBuffer destBuf,
int srcPos,
int destPos,
int nBytes,
java.util.List<java.lang.Integer> ifmt)
This method converts (swaps) EVIO composite type data
between Big endian and Little endian.
|
static void |
swapData(java.nio.ByteBuffer srcBuf,
java.nio.ByteBuffer destBuf,
int nBytes,
java.util.List<java.lang.Integer> ifmt)
This method converts (swaps) EVIO composite type data
between Big endian and Little endian.
|
java.lang.String |
toString()
Obtain a string representation of the composite data.
|
java.lang.String |
toString(boolean hex)
This method returns a string representation of this CompositeData object
suitable for displaying in a
gui.
|
java.lang.String |
toString(java.lang.String indent)
Obtain a string representation of the composite data.
|
java.lang.String |
toXML(boolean hex)
This method writes an xml string representation of this CompositeData object.
|
public CompositeData(java.lang.String format, CompositeData.Data data) throws EvioException
format
- format String defining datadata
- data in given formatEvioException
- data or format arg = null;
if improper format stringpublic CompositeData(java.lang.String format, int formatTag, CompositeData.Data data, int dataTag, int dataNum) throws EvioException
format
- format String defining dataformatTag
- tag used in tagsegment containing formatdata
- data in given formatdataTag
- tag used in bank containing datadataNum
- num used in bank containing dataEvioException
- data or format arg = null;
if improper format stringpublic CompositeData(byte[] rawBytes, java.nio.ByteOrder byteOrder) throws EvioException
rawBytes
- raw data defining this composite type itembyteOrder
- byte order of rawBytesEvioException
- if null arg(s) or bad data formatpublic static CompositeData[] parse(byte[] rawBytes, java.nio.ByteOrder byteOrder) throws EvioException
rawBytes
- array of raw bytes to parsebyteOrder
- byte order of raw bytesEvioException
- if null args or bad format of raw datapublic static byte[] generateRawBytes(CompositeData[] data) throws EvioException
data
- array of CompositeData object to turn into bytesEvioException
- if data takes up too much memory to store in raw byte array (JVM limit);
array elements have different byte order.public java.lang.Object clone()
clone
in class java.lang.Object
public static java.lang.String stringsToFormat(java.lang.String[] strings)
CompositeData.Data.addN(int)
strings
- array of strings to eventually put into a
CompositeData object.public int getPadding()
public java.lang.String getFormat()
public java.nio.ByteOrder getByteOrder()
public byte[] getRawBytes()
public java.util.List<java.lang.Object> getItems()
public java.util.List<DataType> getTypes()
public java.util.List<java.lang.Integer> getNValues()
public java.util.List<java.lang.Short> getnValues()
public java.util.List<java.lang.Byte> getmValues()
public int index()
getInt()
.public void index(int index)
getInt()
.index
- the index of the next data item to be returnedpublic java.lang.Integer getInt()
public java.lang.Integer getNValue()
public java.lang.Integer getnValue()
public java.lang.Integer getmValue()
public java.lang.Integer getHollerit()
public java.lang.Byte getByte()
public java.lang.Short getShort()
public java.lang.Long getLong()
public java.lang.Float getFloat()
public java.lang.Double getDouble()
public java.lang.String[] getStrings()
public static java.util.List<java.lang.Integer> compositeFormatToInt(java.lang.String fmt) throws EvioException
swapData(ByteBuffer, ByteBuffer, int, List)
to swap the endianness of composite data.
It's translated from the eviofmt C function.
format code bits <- format in ascii form
[15:14] [13:8] [7:0]
Nnm # 0 #'('
0 0 0 ')'
Nnm # 1 #'i' unsigned int
Nnm # 2 #'F' floating point
Nnm # 3 #'a' 8-bit char (C++)
Nnm # 4 #'S' short
Nnm # 5 #'s' unsigned short
Nnm # 6 #'C' char
Nnm # 7 #'c' unsigned char
Nnm # 8 #'D' double (64-bit float)
Nnm # 9 #'L' long long (64-bit int)
Nnm # 10 #'l' unsigned long long (64-bit int)
Nnm # 11 #'I' int
Nnm # 12 #'A' hollerit (4-byte char with int endining)
NOTES:
1. The number of repeats '#' must be the number between 2 and 63, number 1 assumed by default
2. If the number of repeats is symbol 'N' instead of the number, it will be taken from data assuming 'int32' format;
if the number of repeats is symbol 'n' instead of the number, it will be taken from data assuming 'int16' format;
if the number of repeats is symbol 'm' instead of the number, it will be taken from data assuming 'int8' format;
Two bits Nnm [15:14], if not zero, requires to take the number of repeats from data in appropriate format:
[01] means that number is integer (N),
[10] - short (n),
[11] - char (m)
3. If format ends but end of data did not reach, format in last parenthesis
will be repeated until all data processed; if there are no parenthesis
in format, data processing will be started from the beginning of the format
(FORTRAN agreement)
fmt
- composite data format stringEvioException
- if improper format stringpublic void swap() throws EvioException
EvioException
- if internal errorpublic static void swapAll(byte[] src, int srcOff, byte[] dest, int destOff, int length, java.nio.ByteOrder srcOrder) throws EvioException
src
- source data array (of 32 bit words)srcOff
- # of bytes offset into source data arraydest
- destination data array (of 32 bit words)destOff
- # of bytes offset into destination data arraylength
- length of data array in 32 bit wordssrcOrder
- the byte order of data in srcEvioException
- if offsets or length < 0; if src = null;
if src or dest is too smallpublic static void swapData(byte[] src, int srcOff, byte[] dest, int destOff, int nBytes, java.util.List<java.lang.Integer> ifmt, java.nio.ByteOrder srcOrder) throws EvioException
src
- source data array (of 32 bit words)srcOff
- offset into source data arraydest
- destination data array (of 32 bit words)destOff
- offset into destination data arraynBytes
- length of data to swap in bytesifmt
- format list as produced by compositeFormatToInt(String)
srcOrder
- byte order of the src data arrayEvioException
- if src == null or ifmt == null;
if nBytes < 8, or ifmt size < 1;
srcOff or destOff negative;
buffer limit/position combo too small;public static void swapData(java.nio.ByteBuffer srcBuf, java.nio.ByteBuffer destBuf, int nBytes, java.util.List<java.lang.Integer> ifmt) throws EvioException
The destBuf can be null or the same as srcBuf in which case data is swapped in place and the srcBuf byte order is switched in this method.
srcBuf
- source data bufferdestBuf
- destination data buffer; if null, use srcBuf as destinationnBytes
- length of data to swap in bytesifmt
- format list as produced by compositeFormatToInt(String)
EvioException
- if ifmt null; ifmt size < 1; nBytes < 8;
srcBuf is null;
buffer limit/position combo too small;public static void swapData(java.nio.ByteBuffer srcBuf, java.nio.ByteBuffer destBuf, int srcPos, int destPos, int nBytes, java.util.List<java.lang.Integer> ifmt) throws EvioException
The destBuf can be null or the same as srcBuf in which case data is swapped in place and the srcBuf byte order is switched in this method. The positions of both srcBuf and destBuf are NOT changed.
srcBuf
- source data bufferdestBuf
- destination data buffer; if null, use srcBuf as destinationsrcPos
- position in srcBuf to beginning swappingdestPos
- position in destBuf to beginning writing swapped datanBytes
- length of data to swap in bytes (be sure to account for padding)ifmt
- format list as produced by compositeFormatToInt(String)
EvioException
- if ifmt null; ifmt size < 1; nBytes < 8;
srcBuf is null; srcPos or destPos negative;
buffer limit/position combo too small;public static void dataToRawBytes(java.nio.ByteBuffer rawBuf, CompositeData.Data data, java.util.List<java.lang.Integer> ifmt) throws EvioException
rawBuf
- data buffer in which to put the raw bytesdata
- data to convert to raw bytesifmt
- format list as produced by compositeFormatToInt(String)
EvioException
- if ifmt size <= 0; if srcBuf or destBuf is too
small; not enough dataItems for the given formatpublic void process()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(java.lang.String indent)
indent
- a string to insert in front of each group of 5 itemspublic java.lang.String toXML(boolean hex)
hex
- if true
then print integers in hexadecimal.public java.lang.String toString(boolean hex)
hex
- if true
then print integers in hexadecimal