public class OutputArrayOrStream extends Object
A class that allows writing to either an OutputStream
or a byte[] or short[] of preallocated size.
An unallocated instance may be constructed but any attempt to write to it will fail until either an OutputStream is assigned or an array of the appropriate type is allocated. This allows, for example, the instance to be created and later allocated based on size information, e.g., as header information is encountered while decompressing before decompressed pixel values need to be written.
Modifier and Type | Field and Description |
---|---|
protected int |
byteOffset |
protected byte[] |
byteValues |
protected ByteOrder |
order |
protected OutputStream |
out |
protected int |
shortOffset |
protected short[] |
shortValues |
Constructor and Description |
---|
OutputArrayOrStream() |
OutputArrayOrStream(byte[] byteValues) |
OutputArrayOrStream(OutputStream out,
ByteOrder order) |
OutputArrayOrStream(short[] shortValues) |
Modifier and Type | Method and Description |
---|---|
void |
allocateByteArray(int length) |
void |
allocateShortArray(int length) |
void |
close()
Closes any assigned OutputStream.
|
byte[] |
getByteArray() |
OutputStream |
getOutputStream() |
short[] |
getShortArray() |
ByteOrder |
order()
Retrieves the OutputStream's byte order used when writing short values.
|
void |
order(ByteOrder order)
Modifes the OutputStream's byte order used when writing short values.
|
void |
setOutputStream(OutputStream out,
ByteOrder order) |
void |
writeByte(int b)
Writes the specified
byte to this output. |
void |
writeShort(int s)
Writes the specified
short to this output. |
protected OutputStream out
protected ByteOrder order
protected byte[] byteValues
protected short[] shortValues
protected int byteOffset
protected int shortOffset
public OutputArrayOrStream()
public OutputArrayOrStream(OutputStream out, ByteOrder order)
public OutputArrayOrStream(byte[] byteValues)
public OutputArrayOrStream(short[] shortValues)
public void setOutputStream(OutputStream out, ByteOrder order) throws IOException
IOException
public ByteOrder order()
Retrieves the OutputStream's byte order used when writing short values.
public void order(ByteOrder order) throws IOException
Modifes the OutputStream's byte order used when writing short values.
order
- the new byte order, either BIG_ENDIAN or LITTLE_ENDIANIOException
- if no OutputStream assignedpublic void allocateByteArray(int length) throws IOException
IOException
public void allocateShortArray(int length) throws IOException
IOException
public OutputStream getOutputStream()
public byte[] getByteArray()
public short[] getShortArray()
public void writeByte(int b) throws IOException
byte
to this output.b
- the byte
.IOException
- if an I/O error occurs.public void writeShort(int s) throws IOException
short
to this output.s
- the short
.IOException
- if an I/O error occurs.public void close() throws IOException
Closes any assigned OutputStream.
Does nothing if arrays allocated instead of an OutputStream (i.e., does NOT release them).
IOException
- if an I/O error occurs.