Package cds.savot.model.interpreter
Class BitInterpreter
java.lang.Object
cds.savot.model.interpreter.BinaryFieldInterpreter<Character>
cds.savot.model.interpreter.CharInterpreter
cds.savot.model.interpreter.BitInterpreter
- 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 -
Method Summary
Modifier and TypeMethodDescriptionprotected Character
convertPrimary
(Object value) Converts/Casts the given object into an object of type T.decode
(InputStream input) Decodes the binary data coming from the given input stream.decodePrimary
(byte[] bytes, int offset) Decodes only one data of type T from the given bytes array.void
encode
(OutputStream output, Object value) Encodes the given value in binary and writes it in the given output stream.byte[]
encodePrimary
(Character value) Encodes a single value of type T in binary.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 Details
-
BitInterpreter
- Throws:
BinaryInterpreterException
-
-
Method Details
-
decode
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<Character>
- Parameters:
input
- Data to decode.- Returns:
null
if EOF, else the decoded data of type T.- Throws:
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:
-
decodePrimary
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:
UnsupportedOperationException
-
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
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(OutputStream output, Object value) throws 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<Character>
- Parameters:
output
- Stream in which the encoded value must be written.value
- The value to write once encoded in binary.- Throws:
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:
-
encodePrimary
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<Character>
- Returns:
- Array of the given length of padding values.
-