public class BufferedRandomAccessReader extends Object implements Closeable
Constructor and Description |
---|
BufferedRandomAccessReader(File file)
Opens the specified file for read-only, random-access.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the file resources used by the referenced instance.
|
long |
getFilePosition()
Provides the current position within the random-access file.
|
File |
getFileReference()
Gets a File object referring to the currently open file (if any).
|
long |
getFileSize()
Gets the current size of the file in bytes.
|
String |
readAscii(int maximumLength)
Reads a C/C++ style null-terminated string of a specified maximum
length from the from data file.
|
int |
readAscii(StringBuilder builder,
int maximumLength)
Reads a C/C++ style null-terminated string of a specified maximum
length from the from data file.
|
boolean |
readBoolean()
Reads one input byte and returns
true if that byte is nonzero,
false if that byte is zero. |
byte |
readByte()
Reads and returns one input byte.
|
double |
readDouble()
Read 8 bytes from the file and returns a Java double.
|
double |
readDoubleBigEndian()
Read 8 bytes from the file and returns a Java double.
|
float |
readFloat()
Reads 4 bytes from the file and returns a Java float.
|
int |
readInt()
Read 4 bytes and return Java integer.
|
int |
readIntBigEndian()
Read 4 bytes and return Java integer.
|
long |
readLong()
Read 8 bytes from the file and returns a java long
|
short |
readShort()
Reads two bytes from the file treating them as being in little-endian order
and returns a short.
|
int |
readUnsignedByte()
Reads one input byte and returns an integer value
in the range 0 through 255.
|
long |
readUnsignedInt()
Reads 4 bytes given in little-endian order and and returns
a Java long primitive given values in the range 0 through 4294967295.
|
int |
readUnsignedShort()
Read two bytes and returns a
Java int primitive.
|
void |
seek(long position)
Sets the virtual file-pointer position measured from the
beginning of the file.
|
int |
skipBytes(int n)
Makes an attempt to advance the virtual file position by
n
bytes in order to match the functionality of the DataInput interface. |
public BufferedRandomAccessReader(File file) throws IOException
file
- A valid file object.IOException
- In the event of an unrecoverable IO condition
such as file not found, access denied, etc.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
- In the event of an unrecoverable I/O condition.public File getFileReference()
public long getFileSize()
public long getFilePosition()
public String readAscii(int maximumLength) throws IOException
maximumLength
- Maximum number of bytes to be read from file.IOException
- In the event of an unrecoverable I/O condition.public int readAscii(StringBuilder builder, int maximumLength) throws IOException
builder
- The StringBuilder to which data is appended; if
the builder already contains text, then it will not be clear out
before the data is written.maximumLength
- Maximum number of bytes to be read from file.IOException
- In the event of an unrecoverable I/O condition.public boolean readBoolean() throws IOException
true
if that byte is nonzero,
false
if that byte is zero. This method may be used to
read the byte written by the writeBoolean method of interface DataOutput.IOException
- In the event of an unrecoverable I/O condition.public byte readByte() throws IOException
IOException
- In the event of an unrecoverable I/O condition.public int readUnsignedByte() throws IOException
IOException
- In the event of an unrecoverable I/O condition.public long readUnsignedInt() throws IOException
IOException
- In the event of an unrecoverable I/O condition.public int readUnsignedShort() throws IOException
IOException
- In the event of an unrecoverable I/O condition.public int readInt() throws IOException
IOException
- In the event of an unrecoverable I/O condition.public int readIntBigEndian() throws IOException
IOException
- In the event of an unrecoverable I/O condition.public double readDoubleBigEndian() throws IOException
IOException
- In the event of an unrecoverable I/O condition.public double readDouble() throws IOException
IOException
- In the event of an unrecoverable I/O condition.public float readFloat() throws IOException
IOException
- In the event of an unrecoverable I/O condition.public long readLong() throws IOException
IOException
- In the event of an unrecoverable I/O condition.public short readShort() throws IOException
IOException
- In the event of an unrecoverable I/O condition.public void seek(long position) throws IOException
position
- The file position, measured in bytes from the
beginning of the file at which to set the virtual file position.IOException
- In the event of an unrecoverable I/O condition.public int skipBytes(int n) throws IOException
n
bytes in order to match the functionality of the DataInput interface.n
- The number of bytes byte which to advance the file positionIOException
- In the event of an unrecoverable I/O condition.Copyright © 2021. All rights reserved.