|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.sun.labs.minion.util.buffer.StdReadableImpl com.sun.labs.minion.util.buffer.FileReadableBuffer
public class FileReadableBuffer
A buffer that can be used to read data from a file, keeping minimal amounts of data in memory.
This implementation is mainly used by the DiskDictionary
so that only
a small amount of dictionary information needs to be in main memory at
any given time.
Field Summary | |
---|---|
protected long |
be
The offset in the file of the end of the buffer that we represent. |
protected long |
bs
The offset in the file of the buffer that we represent. |
protected byte[] |
buff
The in-memory buffer. |
protected static int |
DEFAULT_BUFF_SIZE
The default buffer size, 1KB. |
protected static java.lang.String |
logTag
A tag for our log entries. |
protected long |
me
The offset in the file of the end of our in-memory buffer. |
protected long |
ms
The offset in the file of the start of our in-memory buffer. |
protected long |
pos
The offset of the current position in the buffer we're representing. |
protected java.io.RandomAccessFile |
raf
The file containing the buffer. |
Constructor Summary | |
---|---|
FileReadableBuffer(java.io.RandomAccessFile raf,
long offset,
int limit)
Creates a readable buffer that is backed by the given file. |
|
FileReadableBuffer(java.io.RandomAccessFile raf,
long offset,
int limit,
int buffSize)
Creates a readable buffer that is backed by the given file. |
Method Summary | |
---|---|
protected int |
checkBounds(long p)
Checks whether the given position is within the bounds of our in memory buffer. |
ReadableBuffer |
duplicate()
Duplicates this buffer, so that it can be used safely by other readers. |
byte |
get()
Gets the next byte in the buffer. |
byte |
get(int i)
Gets the byte at the given position in the buffer. |
int |
limit()
Gets the limit of this buffer, i.e., the last readable position. |
void |
limit(int l)
Sets the limit of this buffer, i.e., the last readable position. |
int |
position()
Gets the position of the buffer. |
void |
position(int i)
Positions the buffer. |
protected int |
read(long off)
Reads a given number of bytes from the file. |
int |
remaining()
Returns the number of bytes remaining to be read in the buffer. |
ReadableBuffer |
slice(int p,
int s)
Slices this buffer so that a sub-buffer can be used. |
java.lang.String |
toString()
Gets a string representation of the buffer. |
Methods inherited from class com.sun.labs.minion.util.buffer.StdReadableImpl |
---|
byteDecode, byteDecode, byteDecode, byteDecodeLong, byteDecodeLong, byteDecodeLong, countBits, decodeFloat, getString, skipByteEncoded, test, toString, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.io.RandomAccessFile raf
protected long ms
protected long me
protected long bs
protected long be
protected long pos
protected byte[] buff
protected static java.lang.String logTag
protected static final int DEFAULT_BUFF_SIZE
Constructor Detail |
---|
public FileReadableBuffer(java.io.RandomAccessFile raf, long offset, int limit)
raf
- The file containing the data for our buffer.offset
- The offset in the file where the data for our buffer can be found.limit
- The number of bytes of data in our buffer.public FileReadableBuffer(java.io.RandomAccessFile raf, long offset, int limit, int buffSize)
raf
- The file containing the data for our buffer.offset
- The offset in the file where the data for our buffer
can be found.limit
- The number of bytes of data in our buffer.buffSize
- The size of the in-memory buffer to use.Method Detail |
---|
protected int read(long off)
off
- The offset in the file from which the bytes should be
read.
protected int checkBounds(long p)
p
- The position that we want to check
public int remaining()
public ReadableBuffer duplicate()
public ReadableBuffer slice(int p, int s)
p
- The position at which the buffer should be sliced.s
- The number of bytes that should be in the sliced buffer.
public int limit()
public void limit(int l)
l
- The limit that we wish to set for the buffer.public byte get(int i)
i
- The position from which we wish to get a byte.
public byte get()
public int position()
public void position(int i)
i
- The position to which we should set the buffer.public java.lang.String toString()
toString
in class StdReadableImpl
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |