|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jme.util.BinaryFileReader
public class BinaryFileReader
BinaryFileReader
provides a convienience class that wraps the
DataInputStream object for easier reading. Rather than having to deal with
a binary file one byte at a time, this class will handle reading: byte,
short, int, float and string. The file is read at the start, the file
stored as an array of bytes. An index into the array will keep track of
the reading point. The index can be manually adjusted via the
setOffset
method.
Constructor Summary | |
---|---|
BinaryFileReader(java.io.InputStream md2)
|
|
BinaryFileReader(java.lang.String f)
Constructor creates a new BinaryFileReader class. |
|
BinaryFileReader(java.net.URL f)
Constructor instantiates a new BinaryFileReader object,
loading the provided file and reading the data into a byte array. |
Method Summary | |
---|---|
void |
markPos()
Sets a mark for a later seekMarkOffset call. |
void |
open(java.net.URL f)
open opens a given URL stream. |
int |
readByte()
readByte reads a single byte from the array and
returns this. |
float |
readFloat()
readFloat reads four bytes from the array, generating
a float. |
int |
readInt()
readInt reads four bytes from the array, generating
an int. |
int |
readShort()
readShort reads two bytes from the array, generating
a short. |
int |
readShort2()
|
short |
readSignedShort()
Reads a signed short value. |
java.lang.String |
readString(int size)
readString reads a specified number of bytes to
form a string. |
void |
seekMarkOffset(int offset)
Seeks to the position of the last mark + offset. |
void |
setOffset(int offset)
setOffset sets the index of the file data. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BinaryFileReader(java.lang.String f)
BinaryFileReader
class. This
constructor takes the filename string as a parameter. This filename
is converted into a URL and opened. If the filename is invalid, a
MalformedURLException
will be generated and logged.
f
- the file to open.public BinaryFileReader(java.net.URL f)
BinaryFileReader
object,
loading the provided file and reading the data into a byte array.
f
- the file to read.public BinaryFileReader(java.io.InputStream md2)
Method Detail |
---|
public void open(java.net.URL f)
open
opens a given URL stream. The data is read completely
and the stream is then closed. This allows the stream to only be needed
for the time it takes to read all the data, it is then closed.
f
- the url pointing to the file to be read.public int readByte()
readByte
reads a single byte from the array and
returns this. The file index is then increased by one.
public int readShort()
readShort
reads two bytes from the array, generating
a short. The file index is then increased by two. The short is then
inserted into an integer for convienience.
public int readShort2()
public int readInt()
readInt
reads four bytes from the array, generating
an int. The file index is then increased by four.
public float readFloat()
readFloat
reads four bytes from the array, generating
a float. The file index is then increased by four.
public java.lang.String readString(int size)
readString
reads a specified number of bytes to
form a string. The length of the string (number of characters)
is required to notify when reading should stop. The index is
increased the number of characters read.
size
- the length of the string to read.
public void setOffset(int offset)
setOffset
sets the index of the file data.
offset
- the new index of the file pointer.public void markPos()
public void seekMarkOffset(int offset)
offset
- The Offset relative to mark.public short readSignedShort()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |