Package ej.bon
Class ResourceBuffer
- java.lang.Object
-
- ej.bon.ResourceBuffer
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class ResourceBuffer extends Object implements Closeable
A resource buffer contains a set of data which is compacted to obtain a minimal footprint.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
Stringor aResourceArray.
-
-
Constructor Summary
Constructors Constructor Description ResourceBuffer(String name)Opens aResourceBufferon the resource described by its path.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidalign(int nbBytes)Force to align position on given number of bytes.intavailable()Returns the available number of bytes that can be read (or skipped over) from this buffer.voidclose()Closes this resource and releases any system resources associated with the resource.ResourceArrayreadArray()Reads aResourceArrayand increments position in the data.booleanreadBoolean()Reads a boolean and increments position in the data.bytereadByte()Reads a byte and increments position in the data.charreadChar()Reads a char and increments position in the data.intreadInt()Reads an integer and increments position in the data.shortreadShort()Reads a short and increments position in the data.StringreadString()Reads aStringand increments position in the data.longreadVarLong()Reads a 64-bits signed integer and increments position in the data.intreadVarSInt()Reads a 32-bits signed integer and increments position in the data.intreadVarUInt()Reads a 32-bits unsigned integer and increments position in the data.voidseek(long offset)Sets the buffer position indicator.
-
-
-
Constructor Detail
-
ResourceBuffer
public ResourceBuffer(String name) throws IOException
Opens aResourceBufferon the resource described by its path.- Parameters:
name- absolute resource name, as defined byClass.getResourceAsStream(String)(name must begin with character '/').- Throws:
IllegalArgumentException- when path does not denote an absolute path.IOException- when the resource is not available in application classpath.NullPointerException- if resource is null
-
-
Method Detail
-
close
public void close() throws IOExceptionCloses this resource and releases any system resources associated with the resource. All nextreadcalls will cause an unknown behavior.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if an I/O error occurs.
-
readVarSInt
public int readVarSInt() throws IOExceptionReads a 32-bits signed integer and increments position in the data.- Returns:
- the value read.
- Throws:
EOFException- when end of file is reached.IOException- if an I/O error occurs.
-
readVarUInt
public int readVarUInt() throws IOExceptionReads a 32-bits unsigned integer and increments position in the data.- Returns:
- the value read.
- Throws:
EOFException- when end of file is reached.IOException- if an I/O error occurs.
-
readVarLong
public long readVarLong() throws IOExceptionReads a 64-bits signed integer and increments position in the data.- Returns:
- the value read.
- Throws:
EOFException- when end of file is reached.IOException- if an I/O error occurs.
-
readBoolean
public boolean readBoolean() throws IOExceptionReads a boolean and increments position in the data.- Returns:
- the value read.
- Throws:
EOFException- when end of file is reached.IOException- if an I/O error occurs.
-
readByte
public byte readByte() throws IOExceptionReads a byte and increments position in the data.- Returns:
- the value read.
- Throws:
EOFException- when end of file is reached.IOException- if an I/O error occurs.
-
readShort
public short readShort() throws IOExceptionReads a short and increments position in the data.- Returns:
- the value read.
- Throws:
EOFException- when end of file is reached.IOException- if an I/O error occurs.
-
readChar
public char readChar() throws IOExceptionReads a char and increments position in the data.- Returns:
- the value read.
- Throws:
EOFException- when end of file is reached.IOException- if an I/O error occurs.
-
readInt
public int readInt() throws IOExceptionReads an integer and increments position in the data.- Returns:
- the value read.
- Throws:
EOFException- when end of file is reached.IOException- if an I/O error occurs.
-
readString
public String readString() throws IOException
Reads aStringand increments position in the data.- Returns:
- the
Stringread. - Throws:
EOFException- when end of file is reached.IOException- if an I/O error occurs.
-
readArray
public ResourceArray readArray() throws IOException
Reads aResourceArrayand increments position in the data.- Returns:
- the
ResourceArrayread. - Throws:
EOFException- when end of file is reached.IOException- if an I/O error occurs.
-
seek
public void seek(long offset) throws IOExceptionSets the buffer position indicator. The new position, measured in bytes, is obtained by adding offset bytes to the start of the buffer.- Parameters:
offset- the offset from start of buffer.- Throws:
IndexOutOfBoundsException- if there is no position with the given offset.EOFException- when end of file is reached.IOException- if an I/O error occurs.
-
available
public int available() throws IOExceptionReturns the available number of bytes that can be read (or skipped over) from this buffer.- Returns:
- the number of bytes that can be read
- Throws:
IOException- if an I/O error occurs.
-
align
public void align(int nbBytes) throws IOExceptionForce to align position on given number of bytes. A value lower than 2 is ignored.- Parameters:
nbBytes- number of bytes to align- Throws:
EOFException- when end of file is reached.IOException- if an I/O error occurs.
-
-