public class ResourceBuffer
extends java.lang.Object
implements java.io.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(java.lang.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.
|
java.lang.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(java.lang.String name) throws java.io.IOException
ResourceBuffer
on the resource described by its path.name
- absolute resource name, as defined by
Class.getResourceAsStream(String)
(name must begin with
character '/').java.lang.IllegalArgumentException
- when path does not denote an absolute path.java.io.IOException
- when the resource is not available in application classpath.java.lang.NullPointerException
- if resource is nullpublic void close() throws java.io.IOException
read
calls will cause an unknown behavior.close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
- if an I/O error occurs.public int readVarSInt() throws java.io.IOException
java.io.EOFException
- when end of file is reached.java.io.IOException
- if an I/O error occurs.public int readVarUInt() throws java.io.IOException
java.io.EOFException
- when end of file is reached.java.io.IOException
- if an I/O error occurs.public long readVarLong() throws java.io.IOException
java.io.EOFException
- when end of file is reached.java.io.IOException
- if an I/O error occurs.public boolean readBoolean() throws java.io.IOException
java.io.EOFException
- when end of file is reached.java.io.IOException
- if an I/O error occurs.public byte readByte() throws java.io.IOException
java.io.EOFException
- when end of file is reached.java.io.IOException
- if an I/O error occurs.public short readShort() throws java.io.IOException
java.io.EOFException
- when end of file is reached.java.io.IOException
- if an I/O error occurs.public char readChar() throws java.io.IOException
java.io.EOFException
- when end of file is reached.java.io.IOException
- if an I/O error occurs.public int readInt() throws java.io.IOException
java.io.EOFException
- when end of file is reached.java.io.IOException
- if an I/O error occurs.public java.lang.String readString() throws java.io.IOException
String
and increments position in the data.String
read.java.io.EOFException
- when end of file is reached.java.io.IOException
- if an I/O error occurs.public ResourceArray readArray() throws java.io.IOException
ResourceArray
and increments position in the data.ResourceArray
read.java.io.EOFException
- when end of file is reached.java.io.IOException
- if an I/O error occurs.public void seek(long offset) throws java.io.IOException
offset
- the offset from start of buffer.java.lang.IndexOutOfBoundsException
- if there is no position with the given offset.java.io.EOFException
- when end of file is reached.java.io.IOException
- if an I/O error occurs.public int available() throws java.io.IOException
java.io.IOException
- if an I/O error occurs.public void align(int nbBytes) throws java.io.IOException
nbBytes
- number of bytes to alignjava.io.EOFException
- when end of file is reached.java.io.IOException
- if an I/O error occurs.