public class OutputArrayOrStream
extends java.lang.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 java.nio.ByteOrder |
order |
protected java.io.OutputStream |
out |
protected int |
shortOffset |
protected short[] |
shortValues |
Constructor and Description |
---|
OutputArrayOrStream() |
OutputArrayOrStream(byte[] byteValues) |
OutputArrayOrStream(java.io.OutputStream out,
java.nio.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() |
java.io.OutputStream |
getOutputStream() |
short[] |
getShortArray() |
java.nio.ByteOrder |
order()
Retrieves the OutputStream's byte order used when writing short values.
|
void |
order(java.nio.ByteOrder order)
Modifes the OutputStream's byte order used when writing short values.
|
void |
setOutputStream(java.io.OutputStream out,
java.nio.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 java.io.OutputStream out
protected java.nio.ByteOrder order
protected byte[] byteValues
protected short[] shortValues
protected int byteOffset
protected int shortOffset
public OutputArrayOrStream()
public OutputArrayOrStream(java.io.OutputStream out, java.nio.ByteOrder order)
public OutputArrayOrStream(byte[] byteValues)
public OutputArrayOrStream(short[] shortValues)
public void setOutputStream(java.io.OutputStream out, java.nio.ByteOrder order) throws java.io.IOException
java.io.IOException
public java.nio.ByteOrder order()
Retrieves the OutputStream's byte order used when writing short values.
public void order(java.nio.ByteOrder order) throws java.io.IOException
Modifes the OutputStream's byte order used when writing short values.
order
- the new byte order, either BIG_ENDIAN or LITTLE_ENDIANjava.io.IOException
- if no OutputStream assignedpublic void allocateByteArray(int length) throws java.io.IOException
java.io.IOException
public void allocateShortArray(int length) throws java.io.IOException
java.io.IOException
public java.io.OutputStream getOutputStream()
public byte[] getByteArray()
public short[] getShortArray()
public void writeByte(int b) throws java.io.IOException
byte
to this output.b
- the byte
.java.io.IOException
- if an I/O error occurs.public void writeShort(int s) throws java.io.IOException
short
to this output.s
- the short
.java.io.IOException
- if an I/O error occurs.public void close() throws java.io.IOException
Closes any assigned OutputStream.
Does nothing if arrays allocated instead of an OutputStream (i.e., does NOT release them).
java.io.IOException
- if an I/O error occurs.