Package cds.savot.model.interpreter
Class BitInterpreter
- java.lang.Object
-
- cds.savot.model.interpreter.BinaryFieldInterpreter<java.lang.Character>
-
- cds.savot.model.interpreter.CharInterpreter
-
- cds.savot.model.interpreter.BitInterpreter
-
public class BitInterpreter extends CharInterpreter
- Author:
- Gregory Mantelet
-
-
Field Summary
-
Fields inherited from class cds.savot.model.interpreter.BinaryFieldInterpreter
arraySeparator, arraySizeInterpreter, fixArraySizes, NB_BYTES, nbItems, strNullValue, TYPE_LABEL
-
-
Constructor Summary
Constructors Constructor Description BitInterpreter(int[] arraysizes)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Character
convertPrimary(java.lang.Object value)
Converts/Casts the given object into an object of type T.java.lang.Character[]
decode(java.io.InputStream input)
Decodes the binary data coming from the given input stream.java.lang.Character
decodePrimary(byte[] bytes, int offset)
Decodes only one data of type T from the given bytes array.void
encode(java.io.OutputStream output, java.lang.Object value)
Encodes the given value in binary and writes it in the given output stream.byte[]
encodePrimary(java.lang.Character value)
Encodes a single value of type T in binary.protected java.lang.Class<java.lang.Character[]>
getArrayClass()
Gets the precise array type.byte[]
getPadding(int length)
Creates an array of the given length with padding values (0x00).-
Methods inherited from class cds.savot.model.interpreter.BinaryFieldInterpreter
arraySizeToString, convertIntoArray, convertToString, createEmptyArray, createInterpreter, getArraySize, getPadding, readBytes
-
-
-
-
Constructor Detail
-
BitInterpreter
public BitInterpreter(int[] arraysizes) throws BinaryInterpreterException
- Throws:
BinaryInterpreterException
-
-
Method Detail
-
decode
public java.lang.Character[] decode(java.io.InputStream input) throws java.io.IOException, BinaryInterpreterException
Description copied from class:BinaryFieldInterpreter
Decodes the binary data coming from the given input stream.
Basically, this method gets the array-size (particularly if variable), creates an empty array of the good dimension(s) and fills it by decoding one by one data of type T.
- Overrides:
decode
in classBinaryFieldInterpreter<java.lang.Character>
- Parameters:
input
- Data to decode.- Returns:
null
if EOF, else the decoded data of type T.- Throws:
java.io.IOException
- If the EOF has been reached in an unexpected manner or if an error occurs while reading bytes from the given input stream.BinaryInterpreterException
- See Also:
BinaryFieldInterpreter.getArraySize(InputStream)
,BinaryFieldInterpreter.readBytes(InputStream, int)
,BinaryFieldInterpreter.createEmptyArray(int)
,BinaryFieldInterpreter.decodePrimary(byte[],int)
-
decodePrimary
public java.lang.Character decodePrimary(byte[] bytes, int offset) throws java.lang.UnsupportedOperationException
Description copied from class:BinaryFieldInterpreter
Decodes only one data of type T from the given bytes array.
WARNING:
bytes
is supposed to contain enough bytes (>=BinaryFieldInterpreter.NB_BYTES
) from the given offset.- Overrides:
decodePrimary
in classCharInterpreter
- Parameters:
bytes
- Array to use to extract enough bytes so that decoding one data of type T.offset
- Position from which bytes must be read.- Returns:
- The decoded value.
- Throws:
java.lang.UnsupportedOperationException
-
getArrayClass
protected java.lang.Class<java.lang.Character[]> getArrayClass()
Description copied from class:BinaryFieldInterpreter
Gets the precise array type.
Generally:
T[].class
, where T must be a concrete class.- Overrides:
getArrayClass
in classCharInterpreter
- Returns:
- The class of an array of type T.
-
convertPrimary
protected java.lang.Character convertPrimary(java.lang.Object value) throws BinaryInterpreterException
Description copied from class:BinaryFieldInterpreter
Converts/Casts the given object into an object of type T.- Overrides:
convertPrimary
in classCharInterpreter
- Parameters:
value
- The value to cast. (MAY BE NULL)- Returns:
- The casted value.
- Throws:
BinaryInterpreterException
- If there is an error while converting the given value.
-
encode
public void encode(java.io.OutputStream output, java.lang.Object value) throws java.io.IOException, BinaryInterpreterException
Description copied from class:BinaryFieldInterpreter
Encodes the given value in binary and writes it in the given output stream.- Overrides:
encode
in classBinaryFieldInterpreter<java.lang.Character>
- Parameters:
output
- Stream in which the encoded value must be written.value
- The value to write once encoded in binary.- Throws:
java.io.IOException
- If there is an error while writing in the given stream.BinaryInterpreterException
- If there is an error while encoding the given value.- See Also:
BinaryFieldInterpreter.convertIntoArray(Object)
,BinaryFieldInterpreter.encodePrimary(Object)
,BinaryFieldInterpreter.getPadding()
-
encodePrimary
public byte[] encodePrimary(java.lang.Character value) throws BinaryInterpreterException
Description copied from class:BinaryFieldInterpreter
Encodes a single value of type T in binary.
NOTE: If the given value is null,
BinaryFieldInterpreter.getPadding()
will be returned.- Overrides:
encodePrimary
in classCharInterpreter
- Parameters:
value
- The value to encode. (MAY BE NULL).- Returns:
- The value encoded in binary.
- Throws:
BinaryInterpreterException
- If there is an error while encoding the given value.
-
getPadding
public byte[] getPadding(int length)
Description copied from class:BinaryFieldInterpreter
Creates an array of the given length with padding values (0x00). param length- Overrides:
getPadding
in classBinaryFieldInterpreter<java.lang.Character>
- Returns:
- Array of the given length of padding values.
-
-