Package nom.tam.util
Class OutputEncoder.OutputBuffer
java.lang.Object
nom.tam.util.OutputEncoder.OutputBuffer
- Enclosing class:
OutputEncoder
The conversion buffer for encoding Java arrays (objects) into a binary data representation.
The buffering is most efficient if multiple conversions (put methods) are collated before a forced
OutputEncoder.flush()
call to the output. The caller need not worry about space remaining in the buffer. As new data
is placed (put) into the buffer, the buffer will automatically flush the contents to the output to make space for
new elements as it goes. The caller only needs to call the final OutputEncoder.flush()
, to ensure that all elements
bufferes so far are written to the output.
short[] shortArray = new short[100]; float[] floaTarray = new float[48]; // populate the arrays with data... // Convert to binary representation using the local // conversion buffer. ConversionBuffer buf = getBuffer(); // Convert as much data as we want to the output format... buf.putDouble(1.0); buf.putInt(-1); buf.put(shortArray, 0, shortArray.length); buf.put(floatArray, 0, floatArray.length); // Once we are done with a chunk of data, we need to // make sure all it written to the output buf.flush();
- Author:
- Attila Kovacs
-
Method Summary
Modifier and TypeMethodDescriptionprotected ByteOrder
Returns the current byte order of the binary representation to which data is encoded.protected void
put
(byte[] src, int start, int length) Puts an array of bytes into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.protected void
put
(double[] src, int start, int length) Puts an array of 64-bit double-precision floating point values into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.protected void
put
(float[] src, int start, int length) Puts an array of 32-bit single-precision floating point values into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.protected void
put
(int[] src, int start, int length) Puts an array of 32-bit integers into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.protected void
put
(long[] src, int start, int length) Puts an array of 64-bit integers into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.protected void
put
(short[] src, int start, int length) Puts an array of 16-bit integers into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.protected void
putByte
(byte b) Puts a single byte into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.protected void
putDouble
(double d) Puts an 8-byte double-precision floating point value into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.protected void
putFloat
(float f) Puts an 4-byte single-precision floating point value into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.protected void
putInt
(int i) Puts a 4-byte integer into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.protected void
putLong
(long l) Puts an 8-byte integer into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.protected void
putShort
(short s) Puts a 2-byte integer into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.protected void
setByteOrder
(ByteOrder order) Sets the byte order of the binary representation to which data is encoded.
-
Method Details
-
setByteOrder
Sets the byte order of the binary representation to which data is encoded.- Parameters:
order
- the new byte order- See Also:
-
byteOrder
Returns the current byte order of the binary representation to which data is encoded.- Returns:
- the byte order
- See Also:
-
putByte
Puts a single byte into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.- Parameters:
b
- the byte value- Throws:
IOException
- if the conversion buffer could not be flushed to the output to make room for the new conversion.- See Also:
-
putShort
Puts a 2-byte integer into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.- Parameters:
s
- the 16-bit integer value- Throws:
IOException
- if the conversion buffer could not be flushed to the output to make room for the new conversion.- See Also:
-
putInt
Puts a 4-byte integer into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.- Parameters:
i
- the 32-bit integer value- Throws:
IOException
- if the conversion buffer could not be flushed to the output to make room for the new conversion.- See Also:
-
putLong
Puts an 8-byte integer into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.- Parameters:
l
- the 64-bit integer value- Throws:
IOException
- if the conversion buffer could not be flushed to the output to make room for the new conversion.- See Also:
-
putFloat
Puts an 4-byte single-precision floating point value into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.- Parameters:
f
- the 32-bit single-precision floating point value- Throws:
IOException
- if the conversion buffer could not be flushed to the output to make room for the new conversion.- See Also:
-
putDouble
Puts an 8-byte double-precision floating point value into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.- Parameters:
d
- the 64-bit double-precision floating point value- Throws:
IOException
- if the conversion buffer could not be flushed to the output to make room for the new conversion.- See Also:
-
put
Puts an array of bytes into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.- Parameters:
src
- an array of byte valuesstart
- the index of the first element to convertlength
- the number of elements to convert- Throws:
IOException
- if the conversion buffer could not be flushed to the output to make room for the new conversion.
-
put
Puts an array of 16-bit integers into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.- Parameters:
src
- an array of 16-bit integer valuesstart
- the index of the first element to convertlength
- the number of elements to convert- Throws:
IOException
- if the conversion buffer could not be flushed to the output to make room for the new conversion.
-
put
Puts an array of 32-bit integers into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.- Parameters:
src
- an array of 32-bit integer valuesstart
- the index of the first element to convertlength
- the number of elements to convert- Throws:
IOException
- if the conversion buffer could not be flushed to the output to make room for the new conversion.
-
put
Puts an array of 64-bit integers into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.- Parameters:
src
- an array of 64-bit integer valuesstart
- the index of the first element to convertlength
- the number of elements to convert- Throws:
IOException
- if the conversion buffer could not be flushed to the output to make room for the new conversion.
-
put
Puts an array of 32-bit single-precision floating point values into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.- Parameters:
src
- an array of 32-bit single-precision floating point valuesstart
- the index of the first element to convertlength
- the number of elements to convert- Throws:
IOException
- if the conversion buffer could not be flushed to the output to make room for the new conversion.
-
put
Puts an array of 64-bit double-precision floating point values into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.- Parameters:
src
- an array of 64-bit double-precision floating point valuesstart
- the index of the first element to convertlength
- the number of elements to convert- Throws:
IOException
- if the conversion buffer could not be flushed to the output to make room for the new conversion.
-