public class ResourceBuffer extends Object implements Closeable
A data is a 8-bits word (signed or unsigned), a 16-bits word (signed or
unsigned), a 32-bits (signed or unsigned), a float, a double, a
String
or a ResourceArray
.
Constructor and Description |
---|
ResourceBuffer(String name)
Opens a
ResourceBuffer on the resource described by its path. |
Modifier and Type | Method and Description |
---|---|
void |
align(int nbBytes)
Force to align position on given number of bytes.
|
int |
available()
Returns the available number of bytes that can be read (or skipped over) from
this buffer.
|
void |
close()
Closes this resource and releases any system resources associated with the
resource.
|
ResourceArray |
readArray()
Reads a
ResourceArray and increments position in the data. |
boolean |
readBoolean()
Reads a boolean and increments position in the data.
|
byte |
readByte()
Reads a byte and increments position in the data.
|
char |
readChar()
Reads a char and increments position in the data.
|
int |
readInt()
Reads an integer and increments position in the data.
|
short |
readShort()
Reads a short and increments position in the data.
|
String |
readString()
Reads a
String and increments position in the data. |
long |
readVarLong()
Reads a 64-bits signed integer and increments position in the data.
|
int |
readVarSInt()
Reads a 32-bits signed integer and increments position in the data.
|
int |
readVarUInt()
Reads a 32-bits unsigned integer and increments position in the data.
|
void |
seek(long offset)
Sets the buffer position indicator.
|
public ResourceBuffer(String name) throws IOException
ResourceBuffer
on the resource described by its path.name
- absolute resource name, as defined by
Class.getResourceAsStream(String)
(name must begin with
character '/').IllegalArgumentException
- when path does not denote an absolute path.IOException
- when the resource is not available in application classpath.NullPointerException
- if resource is nullpublic void align(int nbBytes) throws IOException
nbBytes
- number of bytes to alignEOFException
- when end of file is reached.IOException
- if an I/O error occurs.public int available() throws IOException
IOException
- if an I/O error occurs.public void close() throws IOException
read
calls will cause an unknown behavior.close
in interface Closeable
close
in interface AutoCloseable
IOException
- if an I/O error occurs.public ResourceArray readArray() throws IOException
ResourceArray
and increments position in the data.ResourceArray
read.EOFException
- when end of file is reached.IOException
- if an I/O error occurs.public boolean readBoolean() throws IOException
EOFException
- when end of file is reached.IOException
- if an I/O error occurs.public byte readByte() throws IOException
EOFException
- when end of file is reached.IOException
- if an I/O error occurs.public char readChar() throws IOException
EOFException
- when end of file is reached.IOException
- if an I/O error occurs.public int readInt() throws IOException
EOFException
- when end of file is reached.IOException
- if an I/O error occurs.public short readShort() throws IOException
EOFException
- when end of file is reached.IOException
- if an I/O error occurs.public String readString() throws IOException
String
and increments position in the data.String
read.EOFException
- when end of file is reached.IOException
- if an I/O error occurs.public long readVarLong() throws IOException
EOFException
- when end of file is reached.IOException
- if an I/O error occurs.public int readVarSInt() throws IOException
EOFException
- when end of file is reached.IOException
- if an I/O error occurs.public int readVarUInt() throws IOException
EOFException
- when end of file is reached.IOException
- if an I/O error occurs.public void seek(long offset) throws IOException
offset
- the offset from start of buffer.IndexOutOfBoundsException
- if there is no position with the given offset.EOFException
- when end of file is reached.IOException
- if an I/O error occurs.