|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--com.bbn.openmap.io.BinaryFile
The BinaryFile is the standard object used to access data files. It acts like a RandomAccessFile, but will work on jar file contents and URLs, too. The source of the data is isolated through the InputReader interface.
| Field Summary | |
protected boolean |
MSBFirst
The byte order of the underlying file. |
| Constructor Summary | |
BinaryFile(java.io.File f)
Constructs a new BinaryFile with the specified file as the input. |
|
BinaryFile(java.lang.String name)
Constructs a new BinaryFile with the specified file as the input. |
|
| Method Summary | |
static void |
addClosable(Closable it)
Add an object that can be closed if needed. |
void |
assertChar(char expected)
Read a bytes and throw an InvalidCharException if it doesn't match expected |
long |
available()
Return how many bytes left to be read in the file. |
boolean |
byteOrder()
Accessor for the byte ordering used to read multibyte types. |
void |
byteOrder(boolean msbfirst)
Set the byte-ordering used to read shorts, int, etc. |
void |
close()
Closes the underlying file |
static void |
closeClosable()
|
static boolean |
exists(java.lang.String name)
A simple test method to determine if a file or directory, represented by a string, can be found by the current Java environment. |
void |
finalize()
Makes sure that the file has been closed. |
long |
getFilePointer()
Get the index of the next character to be read |
InputReader |
getInputReader()
Get the inputReader used for accessing the file, for quering purposes. |
java.lang.String |
getName()
Get the source name from the input reader. |
long |
length()
The length of the InputReader source. |
int |
read()
Read from the file. |
int |
read(byte[] b)
Read from the file. |
int |
read(byte[] b,
int off,
int len)
Read from the file |
byte[] |
readBytes(int howmany,
boolean allowless)
Read from the file. |
char |
readChar()
Reads and returns a single byte, cast to a char |
double |
readDouble()
Reads and returns a double |
java.lang.String |
readFixedLengthString(int length)
Reads length bytes and returns a string composed
of the bytes cast to chars |
float |
readFloat()
Reads and returns a float |
void |
readFloatArray(float[] vec,
int offset,
int len)
|
int |
readInteger()
Reads and returns a long |
void |
readIntegerArray(int[] vec,
int offset,
int len)
|
long |
readLong()
Reads and returns a long |
short |
readShort()
Reads and returns a short. |
java.lang.String |
readToDelimiter(char delim)
Reads a string until the specified delimiter or EOF is encountered |
static void |
removeClosable(Closable it)
Remove an object from the closable list. |
void |
seek(long pos)
Set the index of the next character to be read. |
void |
setInputReader(InputReader reader)
Set the input reader used by the BinaryFile. |
protected boolean |
setJarInputReader(java.lang.String name)
Takes a name of a file, and checks to see if it reflects an entry in a jar file. |
long |
skipBytes(long n)
Skip over n bytes in the input file |
| Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected boolean MSBFirst
true==
MSB-First == big-endian)
| Constructor Detail |
public BinaryFile(java.io.File f)
throws java.io.IOException
f - the file to be opened for reading
java.io.IOException - pass-through errors from opening a
RandomAccessFile with fRandomAccessFile
public BinaryFile(java.lang.String name)
throws java.io.IOException
name - the name of the file to be opened for reading
java.io.IOException - pass-through errors from opening the
file.| Method Detail |
protected boolean setJarInputReader(java.lang.String name)
throws java.io.IOException
java.io.IOExceptionpublic static boolean exists(java.lang.String name)
name - A path to a file, a URL, or a path to a jar file
entry.public java.lang.String getName()
public InputReader getInputReader()
public void setInputReader(InputReader reader)
public void byteOrder(boolean msbfirst)
msbfirst - true= MSB first,
false= LSB firstpublic boolean byteOrder()
public long skipBytes(long n)
throws java.io.IOException
n - the number of bytes to skip
java.io.IOException - Any IO errors that occur in skipping
bytes in the underlying file
public long getFilePointer()
throws java.io.IOException
java.io.IOException - Any IO errors that occur in accessing
the underlying file
public void seek(long pos)
throws java.io.IOException
pos - the position to seek to.
java.io.IOException - Any IO Errors that occur in seeking the
underlying file.
public long length()
throws java.io.IOException
java.io.IOException
public long available()
throws java.io.IOException
java.io.IOException - Any IO errors encountered in accessing
the file
public void close()
throws java.io.IOException
java.io.IOException - Any IO errors encountered in accessing
the file
public int read()
throws java.io.IOException
java.io.IOException - Any IO errors encountered in reading
from the file
public int read(byte[] b,
int off,
int len)
throws java.io.IOException
b - The byte array to read intooff - the first array position to read intolen - the number of bytes to read
java.io.IOException - Any IO errors encountered in reading
from the file
public int read(byte[] b)
throws java.io.IOException
b - the byte array to read into. Equivelent to
read(b, 0, b.length)
java.io.IOException - Any IO errors encountered in reading
from the fileRandomAccessFile.read(byte[])
public byte[] readBytes(int howmany,
boolean allowless)
throws java.io.EOFException,
FormatException
howmany - the number of bytes to readallowless - if we can return fewer bytes than requested
FormatException - Any IO Exceptions, plus an
end-of-file encountered after reading some, but now
enough, bytes when allowless was false
java.io.EOFException - Encountered an end-of-file while
allowless was false, but NO bytes
had been read.
public char readChar()
throws java.io.EOFException,
FormatException
java.io.EOFException - the end-of-file has been reached, so no
chars where available
FormatException - a rethrown IOException
public short readShort()
throws java.io.EOFException,
FormatException
java.io.EOFException - there were less than 2 bytes left in
the file
FormatException - rethrow of IOExceptions encountered
while reading the bytes for the shortread(byte[])
public int readInteger()
throws java.io.EOFException,
FormatException
java.io.EOFException - there were less than 4 bytes left in
the file
FormatException - rethrow of IOExceptions encountered
while reading the bytes for the integerread(byte[])
public void readIntegerArray(int[] vec,
int offset,
int len)
throws java.io.EOFException,
FormatException
java.io.EOFException
FormatException
public long readLong()
throws java.io.EOFException,
FormatException
java.io.EOFException - there were less than 8 bytes left in
the file
FormatException - rethrow of IOExceptions encountered
while reading the bytes for the longread(byte[])
public float readFloat()
throws java.io.EOFException,
FormatException
java.io.EOFException - there were less than 4 bytes left in
the file
FormatException - rethrow of IOExceptions encountered
while reading the bytes for the floatread(byte[])
public void readFloatArray(float[] vec,
int offset,
int len)
throws java.io.EOFException,
FormatException
java.io.EOFException
FormatException
public double readDouble()
throws java.io.EOFException,
FormatException
java.io.EOFException - there were less than 8 bytes left in
the file
FormatException - rethrow of IOExceptions encountered
while reading the bytes for the shortread(byte[])
public java.lang.String readFixedLengthString(int length)
throws java.io.EOFException,
FormatException
length bytes and returns a string composed
of the bytes cast to chars
length - the number of bytes to read into the string
java.io.EOFException - there were less than
length bytes left in the file
FormatException - rethrow of IOExceptions encountered
while reading the bytes for the short
public void assertChar(char expected)
throws java.io.EOFException,
FormatException
expected
expected - what the next char is claimed to be
java.io.EOFException - there wasn't a byte, so we can't check
for a match
InvalidCharException - throws when the character read
doesn't match expected The .c member
of the thrown exception is the actual char read
FormatException - some other error from reading the
file
public java.lang.String readToDelimiter(char delim)
throws FormatException
delim - the end-of-string delimiter
FormatException - rethrow of IOExceptions from the
read methods
public void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwable - what it throws.public static void addClosable(Closable it)
it - the object that can be closedpublic static void removeClosable(Closable it)
it - the object to removepublic static void closeClosable()
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||