Package nom.tam.util
Class OutputEncoder
java.lang.Object
nom.tam.util.OutputEncoder
- Direct Known Subclasses:
FitsEncoder
Efficient base class for encoding Java arrays into binary output (primarily for internal use)
- Since:
- 1.16
- Author:
- Attila Kovacs
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected final class
The conversion buffer for encoding Java arrays (objects) into a binary data representation. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected OutputWriter
The output to which to write encoded data (directly or from the conversion buffer) -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Instantiates a new Java-to-binary encoder for arrays.Instantiates a new Java-to-binary encoder for arrays, writing encoded data to the specified output. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
flush()
Flushes the contents of the conversion buffer to the underlying output.long
getCount()
Returns the number of encoded bytes that were written to the output.protected OutputEncoder.OutputBuffer
Returns the buffer that is used for conversion, which can be used to collate more elements for writing before bulk flushing data to the output (seeflush()
).protected void
Sets the output to which encoded data should be written (directly or from the conversion buffer).protected void
write
(byte[] b, int start, int length) Writes up to the specified number of bytes from a buffer directly to the output.protected void
write
(int b) Writes a byte directly to the output.abstract void
writeArray
(Object o) Writes the contents of a Java array to the output translating the data to the required binary representation.
-
Field Details
-
out
The output to which to write encoded data (directly or from the conversion buffer)
-
-
Constructor Details
-
OutputEncoder
protected OutputEncoder()Instantiates a new Java-to-binary encoder for arrays. To be used by subclass implementations only- See Also:
-
OutputEncoder
Instantiates a new Java-to-binary encoder for arrays, writing encoded data to the specified output.- Parameters:
o
- the output to which encoded data is to be written.
-
-
Method Details
-
setOutput
Sets the output to which encoded data should be written (directly or from the conversion buffer).- Parameters:
o
- the new output to which encoded data is to be written.
-
getCount
public long getCount()Returns the number of encoded bytes that were written to the output. It does not include bytes written directly (unencoded) to the output, such as viawrite(int)
orwrite(byte[], int, int)
.- Returns:
- the number of encoded bytes written to the output.
- See Also:
-
getOutputBuffer
Returns the buffer that is used for conversion, which can be used to collate more elements for writing before bulk flushing data to the output (seeflush()
).- Returns:
- the conversion buffer used by this encoder.
-
flush
Flushes the contents of the conversion buffer to the underlying output.- Throws:
IOException
- if there was an IO error writing the contents of this buffer to the output.
-
write
Writes a byte directly to the output. See the general contract ofDataOutputStream.write(int)
. Unencoded bytes written by this method are not reflected in the value returned bygetCount()
.- Parameters:
b
- the (unsigned) byte value to write.- Throws:
IOException
- if there was an underlying IO error- See Also:
-
write
Writes up to the specified number of bytes from a buffer directly to the output. See the general contract ofDataOutputStream.write(byte[], int, int)
. The number of unencoded bytes written by this method are not reflected in the value returned bygetCount()
.- Parameters:
b
- the bufferstart
- the starting buffer indexlength
- the number of bytes to write.- Throws:
IOException
- if there was an underlying IO error- See Also:
-
writeArray
Writes the contents of a Java array to the output translating the data to the required binary representation. The argument may be any generic Java array, including heterogeneous arrays of arrays.- Parameters:
o
- the Java array, including heterogeneous arrays of arrays. Ifnull
nothing will be written to the output.- Throws:
IOException
- if there was an IO error writing to the outputIllegalArgumentException
- if the supplied object is not a Java array or if it contains Java types that are not supported by the decoder.- See Also:
-