public class XdrInput extends Object
EXRInputStream
to read primitive
and string data.
Each instance uses a private buffer to read data from the stream. All
methods are not thread safe, and assume that the stream will remain
valid through the lifetime of a XdrInput
instance.
Modeled after the functions in ImfXdr.h from the C++ OpenEXR library.
EXRInputStream
Constructor and Description |
---|
XdrInput(EXRInputStream stream) |
Modifier and Type | Method and Description |
---|---|
long |
position() |
boolean |
readBoolean() |
byte |
readByte() |
double |
readDouble() |
float |
readFloat() |
void |
readFully(byte[] b) |
void |
readFully(byte[] b,
int off,
int len)
Reads
len bytes from the underlying input stream, copying
them into the destination buffer b starting at offset off . |
int |
readInt() |
long |
readLong() |
String |
readNullTerminatedUTF8(int maxLength)
Read a null-terminated UTF8 string consisting at most of
maxLength bytes plus the null terminator. |
short |
readShort() |
int |
readUnsignedByte() |
int |
readUnsignedShort() |
String |
readUTF8(int length)
Read a UTF8 string using
length bytes from the stream. |
public XdrInput(EXRInputStream stream)
public long position() throws EXRIOException
EXRIOException
public boolean readBoolean() throws EXRIOException
EXRIOException
public byte readByte() throws EXRIOException
EXRIOException
public int readUnsignedByte() throws EXRIOException
EXRIOException
public short readShort() throws EXRIOException
EXRIOException
public int readUnsignedShort() throws EXRIOException
EXRIOException
public int readInt() throws EXRIOException
EXRIOException
public long readLong() throws EXRIOException
EXRIOException
public float readFloat() throws EXRIOException
EXRIOException
public double readDouble() throws EXRIOException
EXRIOException
public String readNullTerminatedUTF8(int maxLength) throws EXRIOException
maxLength
bytes plus the null terminator.
This this method consumes at most maxLength+1
bytes from the
stream, a single call consumes only as many bytes as it needs to find
the null terminator. If after reading maxLength
non-null bytes the next byte is not the null terminator an
EXRIOException
is thrown.
The actual length of the string might be less than maxLength
if it contains multi-byte characters.
maxLength
- the maximum number of non-null bytes expected.EXRIOException
- if the null terminator is missing after consuming
maxLength+1
bytes, or if an I/O error occurs.public String readUTF8(int length) throws EXRIOException
length
bytes from the stream.
Even if the string has an earlier null terminator, this method always
consumes exactly length
bytes from the stream.
The actual length of the string might be less than maxLength
if it contains multi-byte characters.
length
- number of bytes to read from the stream.IllegalArgumentException
- if length < 0
EXRIOException
- if an I/O error occurs.public void readFully(byte[] b) throws EXRIOException
EXRIOException
public void readFully(byte[] b, int off, int len) throws EXRIOException
len
bytes from the underlying input stream, copying
them into the destination buffer b
starting at offset off
.b
- non-null destination buffer.off
- initial index in b
for storing the read bytes.len
- total byte count to read.EXRIOException
- if an I/O error occurs.IllegalArgumentException
- if b
is null.IndexOutOfBoundsException
- if off
is negative,
len
is negative, or len
is greater than
b.length - off