|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.labs.minion.util.buffer.FileWriteableBuffer
public class FileWriteableBuffer
A class for a writeable buffer that encodes data directly to a file,
utilizing an in-memory buffer. While the positional encoding methods
are supported, you are strongly advised against using this
implementation of WriteableBuffer for anything other than
writing successive bytes.
This implementation is primarily used by the DictionaryWriter class to
write interim pieces of dictionaries to a file during dumping and
merging operations.
Note that this implementation provides a flush() method that will
ensure that any data currently in memory is written to disk.
| Field Summary | |
|---|---|
protected int |
bPos
The position in our in-memory buffer. |
protected byte[] |
buff
Our in memory buffer. |
protected static int |
DEFAULT_BUFF_SIZE
Our default buffer size. |
protected static java.lang.String |
logTag
A tag for our log entries. |
protected long |
off
The offset in the file where we started writing our buffer. |
protected int |
pos
The position in the buffer we're writing. |
protected java.io.RandomAccessFile |
raf
The file to which we'll write our data. |
| Constructor Summary | |
|---|---|
FileWriteableBuffer(java.io.RandomAccessFile raf)
Creates a buffer that will write to the underlying file. |
|
FileWriteableBuffer(java.io.RandomAccessFile raf,
int size)
Creates a buffer that will write to the underlying file. |
|
| Method Summary | |
|---|---|
WriteableBuffer |
append(ReadableBuffer b)
Appends a readable buffer onto this buffer. |
WriteableBuffer |
append(ReadableBuffer b,
int n)
Appends a given number of bytes from a readable buffer onto this buffer. |
WriteableBuffer |
byteEncode(int pos,
long n,
int nBytes)
Encodes a positive long directly, using a given number of bytes, starting at the given position in the units. |
int |
byteEncode(long n)
Encodes an integer in a byte-aligned fashion, using the minimal number of bytes. |
WriteableBuffer |
byteEncode(long n,
int nBytes)
Encodes a positive long onto a writeable in a given number of bytes. |
WriteableBuffer |
capacity(int n)
Sets the capacity of this buffer to the given amount. |
WriteableBuffer |
clear()
Clears the buffer. |
WriteableBuffer |
encode(java.lang.CharSequence s)
Encodes a character sequence onto the buffer. |
WriteableBuffer |
encode(float f)
Encodes a floating point value in 4 bytes. |
void |
flush()
Flushes our in-memory buffer to the disk. |
ReadableBuffer |
getReadableBuffer()
Gets a readable buffer from this writeable one. |
int |
limit()
Gets the limit of this buffer, i.e., the last writeable position. |
void |
limit(int l)
Sets the limit of this buffer, i.e., the last readable position. |
WriteableBuffer |
or(ReadableBuffer b)
Computes the logical OR of this buffer and another. |
int |
position()
Gets the current position. |
void |
position(int p)
Sets the current position. |
WriteableBuffer |
put(byte b)
Puts a single byte onto this buffer. |
WriteableBuffer |
put(int p,
byte b)
Puts a single byte onto this buffer at the given position. |
int |
remaining()
Returns the number of bytes remaining in the buffer, which is nonsense. |
WriteableBuffer |
set(int bitIndex)
Sets the given bit to 1 in the given buffer. |
void |
write(java.nio.ByteBuffer b)
Write the buffer to a new IO buffer. |
void |
write(java.io.DataOutput o)
Write the buffer to a data output. |
void |
write(java.io.OutputStream os)
Write the buffer to a stream. |
void |
write(java.nio.channels.WritableByteChannel chan)
Write the buffer to a channel. |
WriteableBuffer |
xor(ReadableBuffer b)
Computes the logical XOR of this buffer and another. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected java.io.RandomAccessFile raf
protected byte[] buff
protected long off
protected int pos
protected int bPos
protected static int DEFAULT_BUFF_SIZE
protected static java.lang.String logTag
| Constructor Detail |
|---|
public FileWriteableBuffer(java.io.RandomAccessFile raf)
throws java.io.IOException
raf - The file to which we'll write our data.
java.io.IOException - If there is an error getting the current file pointer.
public FileWriteableBuffer(java.io.RandomAccessFile raf,
int size)
throws java.io.IOException
raf - The file to which we'll write our data.size - The size of the in-memory buffer to use.
java.io.IOException - If there is an error getting the current
file pointer.| Method Detail |
|---|
public int limit()
limit in interface BufferInteger.MAX_VALUE, since the underlying
representation is a file.public void limit(int l)
limit in interface Bufferl - The limit to set. This has no effect on this buffer.public int position()
position in interface Bufferpublic void position(int p)
position in interface Bufferp - The position.public int remaining()
remaining in interface BufferInteger.MAX_VALUE, since the file may contain that much data.public void flush()
public WriteableBuffer capacity(int n)
capacity in interface WriteableBuffern - The capacity that we want.
public WriteableBuffer put(byte b)
put in interface WriteableBufferb - The byte to put on the buffer
public WriteableBuffer put(int p,
byte b)
WriteableBuffer.
put in interface WriteableBufferp - The position where the byte should be put.b - The byte to put on the buffer
public WriteableBuffer byteEncode(long n,
int nBytes)
byteEncode in interface WriteableBuffern - The number to encode.nBytes - The number of bytes to use in the encoding.
public WriteableBuffer byteEncode(int pos,
long n,
int nBytes)
byteEncode in interface WriteableBufferpos - The position to start encoding.n - The number to encode.nBytes - The number of bytes to use in the encoding.
public int byteEncode(long n)
byteEncode in interface WriteableBuffern - The number to encode.
public WriteableBuffer encode(float f)
encode in interface WriteableBufferf - the floating point number to encode
public WriteableBuffer append(ReadableBuffer b)
append in interface WriteableBufferb - The buffer that we wish to append onto this buffer.
public WriteableBuffer append(ReadableBuffer b,
int n)
append in interface WriteableBufferb - The buffer that we wish to append onto this buffer.n - The number of bytes to append onto this buffer.
public WriteableBuffer or(ReadableBuffer b)
or in interface WriteableBufferb - The buffer to or with this one.
public WriteableBuffer xor(ReadableBuffer b)
xor in interface WriteableBufferb - The buffer to or with this one.
public WriteableBuffer encode(java.lang.CharSequence s)
byteEncode method. Then, the characters in the
sequence are encoded using a UTF-8 encoding.
encode in interface WriteableBuffers - The character sequence to encode.
public WriteableBuffer set(int bitIndex)
set in interface WriteableBufferbitIndex - the index of the bit to set to 1.
public WriteableBuffer clear()
clear in interface WriteableBufferpublic ReadableBuffer getReadableBuffer()
getReadableBuffer in interface WriteableBufferFileReadableBuffer that is backed by the same file.FileReadableBufferpublic void write(java.nio.ByteBuffer b)
write in interface WriteableBufferb - The buffer to which we'll write our data.
public void write(java.nio.channels.WritableByteChannel chan)
throws java.io.IOException
FileChannel.
write in interface WriteableBufferchan - The channel to which the buffer should be written.
java.io.IOException - If there is an error writing the data.
public void write(java.io.DataOutput o)
throws java.io.IOException
RandomAccessFile.
write in interface WriteableBuffero - The output to which the buffer should be written.
java.io.IOException - If there is an error writing the data.
public void write(java.io.OutputStream os)
throws java.io.IOException
FileOutputStream, this is done efficiently.
write in interface WriteableBufferos - The stream to which the buffer should be written.
java.io.IOException - If there is any error writing the data.write(WritableByteChannel)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||