public final class MultiBufferedRandomAccessFile
extends java.lang.Object
implements java.io.DataInput, java.io.Closeable
| Constructor and Description |
|---|
MultiBufferedRandomAccessFile(java.io.File file,
int bufSize,
int maxBuffers)
Create a read-only random access file with the specified maximum number of buffers of the specified size.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clearCache()
Clear the cache buffers.
|
void |
close()
Closes this file and releases any system resources
associated with the buffering.
|
int |
read()
Reads the next byte in the file at the current seek position.
|
boolean |
readBoolean()
See the general contract of the
readBoolean
method of DataInput. |
byte |
readByte()
See the general contract of the
readByte
method of DataInput. |
char |
readChar()
See the general contract of the
readChar
method of DataInput. |
double |
readDouble()
See the general contract of the
readDouble
method of DataInput. |
float |
readFloat()
See the general contract of the
readFloat
method of DataInput. |
void |
readFully(byte[] b)
See the general contract of the
readFully
method of DataInput. |
void |
readFully(byte[] b,
int off,
int len)
See the general contract of the
readFully
method of DataInput. |
int |
readInt()
See the general contract of the
readInt
method of DataInput. |
java.lang.String |
readLine()
See the general contract of the
readLine
method of DataInput. |
long |
readLong()
See the general contract of the
readLong
method of DataInput. |
int |
readNextInt()
This is similar to readInt(), but the caller must guarantee that no seek()
occurred between the last call to readInt() or readNextInt() and this one.
|
short |
readShort()
See the general contract of the
readShort
method of DataInput. |
int |
readUnsignedByte()
See the general contract of the
readUnsignedByte
method of DataInput. |
int |
readUnsignedShort()
See the general contract of the
readUnsignedShort
method of DataInput. |
java.lang.String |
readUTF()
See the general contract of the
readUTF
method of DataInput. |
void |
resetStatistics()
Reset the statistics counters that are reported by the toString() method.
|
void |
seek(long seekPos)
Sets the file-pointer offset, measured from the beginning of this
file, at which the next read occurs.
|
int |
skipBytes(int n)
See the general contract of the
skipBytes
method of DataInput. |
java.lang.String |
toString()
Returns a string representation of the object.
|
public MultiBufferedRandomAccessFile(java.io.File file,
int bufSize,
int maxBuffers)
throws java.io.IOException
file - File pointing at the disk file to readbufSize - size of each buffer in bytes (must be a power of 2)maxBuffers - maximum number of buffers to usejava.io.IOException - if file cannot be opened for read-only accesspublic int read()
throws java.io.IOException
-1 if the end of the
stream is reached.java.io.IOException - if this input stream has been closed by
invoking its close() method,
or an I/O error occurs.seek(long)public boolean readBoolean()
throws java.io.IOException
readBoolean
method of DataInput.
Bytes for this operation are read from the contained file.
readBoolean in interface java.io.DataInputboolean value read.java.io.EOFException - if this input stream has reached the end.java.io.IOException - the stream has been closed and the contained
input stream does not support reading after close, or
another I/O error occurs.public byte readByte()
throws java.io.IOException
readByte
method of DataInput.
Bytes for this operation are read from the contained file.
readByte in interface java.io.DataInputbyte.java.io.EOFException - if this input stream has reached the end.java.io.IOException - the stream has been closed and the contained
input stream does not support reading after close, or
another I/O error occurs.public char readChar()
throws java.io.IOException
readChar
method of DataInput.
Bytes for this operation are read from the contained input stream.
readChar in interface java.io.DataInputchar.java.io.EOFException - if this input stream reaches the end before
reading two bytes.java.io.IOException - the stream has been closed and the contained
input stream does not support reading after close, or
another I/O error occurs.public double readDouble()
throws java.io.IOException
readDouble
method of DataInput.
Bytes for this operation are read from the contained file.
readDouble in interface java.io.DataInputdouble.java.io.EOFException - if this input stream reaches the end before
reading eight bytes.java.io.IOException - the stream has been closed and the contained
input stream does not support reading after close, or
another I/O error occurs.DataInputStream.readLong(),
Double.longBitsToDouble(long)public float readFloat()
throws java.io.IOException
readFloat
method of DataInput.
Bytes for this operation are read from the contained file.
readFloat in interface java.io.DataInputfloat.java.io.EOFException - if this input stream reaches the end before
reading four bytes.java.io.IOException - the stream has been closed and the contained
input stream does not support reading after close, or
another I/O error occurs.DataInputStream.readInt(),
Float.intBitsToFloat(int)public void readFully(byte[] b)
throws java.io.IOException
readFully
method of DataInput.
Bytes for this operation are read from the contained file.
readFully in interface java.io.DataInputb - the buffer into which the data is read.java.io.EOFException - if this input stream reaches the end before
reading all the bytes.java.io.IOException - the stream has been closed and the contained
input stream does not support reading after close, or
another I/O error occurs.public void readFully(byte[] b,
int off,
int len)
throws java.io.IOException
readFully
method of DataInput.
Bytes for this operation are read from the contained file.
readFully in interface java.io.DataInputb - the buffer into which the data is read.off - the start offset of the data.len - the number of bytes to read.java.io.EOFException - if this input stream reaches the end before
reading all the bytes.java.io.IOException - the stream has been closed and the contained
input stream does not support reading after close, or
another I/O error occurs.public int readInt()
throws java.io.IOException
readInt
method of DataInput.
Bytes for this operation are read from the contained file.
readInt in interface java.io.DataInputint.java.io.EOFException - if this input stream reaches the end before
reading four bytes.java.io.IOException - the stream has been closed and the contained
input stream does not support reading after close, or
another I/O error occurs.public java.lang.String readLine()
throws java.io.IOException
readLine
method of DataInput.
Bytes for this operation are read from the contained file. Note that this method only supports extended 8-bit ASCII; it does not support UTF-8 or other locale-specific character sets.
readLine in interface java.io.DataInputjava.io.IOException - if an I/O error occurs.public long readLong()
throws java.io.IOException
readLong
method of DataInput.
Bytes for this operation are read from the contained file.
readLong in interface java.io.DataInputlong.java.io.EOFException - if this input stream reaches the end before
reading eight bytes.java.io.IOException - the stream has been closed and the contained
input stream does not support reading after close, or
another I/O error occurs.public short readShort()
throws java.io.IOException
readShort
method of DataInput.
Bytes for this operation are read from the contained file.
readShort in interface java.io.DataInputjava.io.EOFException - if this input stream reaches the end before
reading two bytes.java.io.IOException - the stream has been closed and the contained
input stream does not support reading after close, or
another I/O error occurs.public int readUnsignedByte()
throws java.io.IOException
readUnsignedByte
method of DataInput.
Bytes for this operation are read from the contained file.
readUnsignedByte in interface java.io.DataInputjava.io.EOFException - if this input stream has reached the end.java.io.IOException - the stream has been closed and the contained
input stream does not support reading after close, or
another I/O error occurs.public int readUnsignedShort()
throws java.io.IOException
readUnsignedShort
method of DataInput.
Bytes for this operation are read from the contained file.
readUnsignedShort in interface java.io.DataInputjava.io.EOFException - if this input stream reaches the end before
reading two bytes.java.io.IOException - the stream has been closed and the contained
input stream does not support reading after close, or
another I/O error occurs.public java.lang.String readUTF()
throws java.io.IOException
readUTF
method of DataInput.
Bytes for this operation are read from the contained file.
readUTF in interface java.io.DataInputjava.io.EOFException - if this input stream reaches the end before
reading all the bytes.java.io.IOException - the stream has been closed and the contained
input stream does not support reading after close, or
another I/O error occurs.java.io.UTFDataFormatException - if the bytes do not represent a valid
modified UTF-8 encoding of a string.public int skipBytes(int n)
throws java.io.IOException
skipBytes
method of DataInput.
Bytes for this operation are read from the contained file.
skipBytes in interface java.io.DataInputn - the number of bytes to be skipped.java.io.IOException - if the contained input stream does not support
seek, or the stream has been closed and
the contained input stream does not support
reading after close, or another I/O error occurs.public void seek(long seekPos)
seekPos - the offset position, measured in bytes from the
beginning of the file, at which to set the file
pointer.public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOException - if an I/O error occurs.public java.lang.String toString()
toString in class java.lang.Objectpublic void resetStatistics()
toString()public int readNextInt()
throws java.io.IOException
int.java.io.EOFException - if this input stream reaches the end before
reading four bytes.java.io.IOException - the stream has been closed and the contained
input stream does not support reading after close, or
another I/O error occurs.readInt()public void clearCache()