public class BinaryBufferedFile extends BinaryFile
MSBFirst
Constructor and Description |
---|
BinaryBufferedFile(java.io.File f)
Constructs a BinaryBufferedFile with a File
|
BinaryBufferedFile(java.io.File f,
int buffersize)
Constructs a BinaryBufferedFile with a File and a buffer size
|
BinaryBufferedFile(java.lang.String name)
Constructs a BinaryBufferedFile with a filename
|
BinaryBufferedFile(java.lang.String name,
int buffersize)
Constructs a BinaryBufferedFile with a filename and a buffersize
|
Modifier and Type | Method and Description |
---|---|
long |
available()
Return how many bytes left to be read in the file.
|
static BinaryBufferedFile |
create(java.lang.String name)
A simple factory method that lets you try to create something without
having to really deal with failure.
|
static BinaryBufferedFile |
create(java.lang.String name,
int buffersize)
A simple factory method that lets you try to create something without
having to really deal with failure.
|
void |
dispose()
Disposes the underlying file input, and releases some resources of the
class.
|
long |
getFilePointer()
Get the index of the next character to be read
|
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.
|
java.lang.String |
readFixedLengthString(int length)
Reads
length bytes and returns a string composed of the
bytes cast to chars. |
void |
readFloatArray(float[] vec,
int offset,
int len)
Reads an array of floats from the input.
|
int |
readInteger()
Reads and returns a long.
|
void |
readIntegerArray(int[] vec,
int offset,
int len)
Reads an array of integers.
|
long |
readLong()
Reads and returns a long.
|
short |
readShort()
Reads and returns a short.
|
void |
readShortArray(short[] vec,
int offset,
int len)
Reads an array of shorts.
|
int |
readUnsignedShort()
Reads and returns a integer from 2 bytes.
|
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.
|
long |
skipBytes(long n)
Skip over n bytes in the input file
|
addClosable, assertChar, byteOrder, byteOrder, close, closeClosable, exists, finalize, getInputReader, getName, length, readDouble, readFloat, readFloatArray, readFully, readShortData, readToDelimiter, readUnsigned, removeClosable, setJarInputReader
public BinaryBufferedFile(java.io.File f, int buffersize) throws java.io.IOException
f
- the input filebuffersize
- the size to use for buffering readsjava.io.IOException
- pass-through errors from opening a BinaryFile with
fBinaryFile
public BinaryBufferedFile(java.io.File f) throws java.io.IOException
f
- the input filejava.io.IOException
- pass-through errors from opening a BinaryFile with
fBinaryFile
public BinaryBufferedFile(java.lang.String name, int buffersize) throws java.io.IOException
name
- the name/path of the input filebuffersize
- the size to use for buffering readsjava.io.IOException
- pass-through errors from opening a BinaryFile with
fBinaryFile
public BinaryBufferedFile(java.lang.String name) throws java.io.IOException
name
- the name/path of the input filejava.io.IOException
- pass-through errors from opening a BinaryFile with
fBinaryFile
public static BinaryBufferedFile create(java.lang.String name)
public static BinaryBufferedFile create(java.lang.String name, int buffersize)
public void setInputReader(InputReader reader)
setInputReader
in class BinaryFile
public long skipBytes(long n) throws java.io.IOException
BinaryFile
skipBytes
in class BinaryFile
n
- the number of bytes to skipjava.io.IOException
- Any IO errors that occur in skipping bytes in the
underlying filepublic long getFilePointer() throws java.io.IOException
BinaryFile
getFilePointer
in class BinaryFile
java.io.IOException
- Any IO errors that occur in accessing the
underlying filepublic void seek(long pos) throws java.io.IOException
BinaryFile
seek
in class BinaryFile
pos
- the position to seek to.java.io.IOException
- Any IO Errors that occur in seeking the underlying
file.public long available() throws java.io.IOException
BinaryFile
available
in class BinaryFile
java.io.IOException
- Any IO errors encountered in accessing the filepublic void dispose() throws java.io.IOException
dispose
in class BinaryFile
java.io.IOException
- IO errors encountered in closing the filepublic int read() throws java.io.IOException
BinaryFile
read
in class BinaryFile
java.io.IOException
- Any IO errors encountered in reading from the filepublic int read(byte[] b, int off, int len) throws java.io.IOException
read
in class BinaryFile
b
- The byte array to read intooff
- the first array position to read intolen
- the number of bytes to readjava.io.IOException
- Any IO errors encountered in reading from the filepublic int read(byte[] b) throws java.io.IOException
BinaryFile
read
in class BinaryFile
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
readBytes
in class BinaryFile
howmany
- the number of bytes to readallowless
- if we can return fewer bytes than requestedFormatException
- 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
readChar
in class BinaryFile
java.io.EOFException
- the end-of-file has been reached, so no chars
where availableFormatException
- a rethrown IOExceptionpublic short readShort() throws java.io.EOFException, FormatException
readShort
in class BinaryFile
java.io.EOFException
- there were less than 2 bytes left in the fileFormatException
- rethrow of IOExceptions encountered while
reading the bytes for the shortread(byte[])
public int readUnsignedShort() throws java.io.EOFException, FormatException
readUnsignedShort
in class BinaryFile
java.io.EOFException
- there were less than 2 bytes left in the fileFormatException
- rethrow of IOExceptions encountered while
reading the bytes for the shortread(byte[])
public void readShortArray(short[] vec, int offset, int len) throws java.io.EOFException, FormatException
vec
- the array to write the shorts intooffset
- the first array index to write tolen
- the number of shorts to readjava.io.EOFException
- there were fewer bytes than needed in the fileFormatException
- rethrow of IOExceptions encountered while
reading the bytes for the arraypublic int readInteger() throws java.io.EOFException, FormatException
readInteger
in class BinaryFile
java.io.EOFException
- there were less than 4 bytes left in the fileFormatException
- rethrow of IOExceptions encountered while
reading the bytes for the integerBinaryFile.read(byte[])
public void readIntegerArray(int[] vec, int offset, int len) throws java.io.EOFException, FormatException
readIntegerArray
in class BinaryFile
java.io.EOFException
- there were fewer bytes than needed in the fileFormatException
- rethrow of IOExceptions encountered while
reading the bytes for the arraypublic void readFloatArray(float[] vec, int offset, int len) throws java.io.EOFException, FormatException
readFloatArray
in class BinaryFile
vec
- the vector to read intooffset
- the first float read goes into vec[offset]len
- the number of floats to read from the streamjava.io.EOFException
- not enough bytes were left in the fileFormatException
- rethrow of IOExceptions encountered while
reading the bytes for the integerpublic long readLong() throws java.io.EOFException, FormatException
readLong
in class BinaryFile
java.io.EOFException
- there were less than 8 bytes left in the fileFormatException
- rethrow of IOExceptions encountered while
reading the bytes for the longread(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.readFixedLengthString
in class BinaryFile
length
- the number of bytes to read into the stringjava.io.EOFException
- there were less than length
bytes
left in the fileFormatException
- rethrow of IOExceptions encountered while
reading the bytes for the shortCopyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details