|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.bbn.openmap.io.BinaryFile
public class 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, but with a chance for re-opening if accessed again. |
static void |
closeClosable()
|
void |
dispose()
Closes underlying file, get rid of resources and knowledge of file. |
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. |
protected 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 querying 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(double[] vec,
int offset,
int len)
|
void |
readFloatArray(float[] vec,
int offset,
int len)
|
BinaryFile |
readFully()
Read the BinaryFile into memory and return a new
BinaryFile instance working on that in-memory version of the
file. |
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. |
short |
readShortData()
Code for reading shorts that are two-byte integers, high order first, and negatives are signed magnitude. |
java.lang.String |
readToDelimiter(char delim)
Reads a string until the specified delimiter or EOF is encountered |
int |
readUnsigned()
Read a byte from the file, return an unsigned integer. |
int |
readUnsignedShort()
Reads and returns a integer from 2 bytes. |
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.IOException
public 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 filepublic long getFilePointer() throws java.io.IOException
java.io.IOException
- Any IO errors that occur in accessing the
underlying filepublic 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 filepublic void close() throws java.io.IOException
java.io.IOException
- Any IO errors encountered in accessing the filepublic void dispose() throws java.io.IOException
java.io.IOException
public int read() throws java.io.IOException
java.io.IOException
- Any IO errors encountered in reading from the filepublic 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 filepublic int read(byte[] b) throws java.io.IOException
b
- the byte array to read into. Equivalent 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 IOExceptionpublic int readUnsigned() throws java.io.IOException, java.io.EOFException
java.io.IOException
- Any IO errors encountered in reading from the file
java.io.EOFException
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 short readShortData() throws java.io.EOFException, FormatException
java.io.EOFException
FormatException
public int readUnsignedShort() 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 void readFloatArray(double[] 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 shortpublic 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 filepublic java.lang.String readToDelimiter(char delim) throws FormatException
delim
- the end-of-string delimiter
FormatException
- rethrow of IOExceptions from the read methodsprotected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.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()
public BinaryFile readFully() throws java.io.IOException
BinaryFile
into memory and return a new
BinaryFile
instance working on that in-memory version of the
file.
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |