|
||||||||||
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.StdBufferImpl com.sun.labs.minion.util.buffer.ArrayBuffer
public class ArrayBuffer
A buffer class for reading and writing that is backed by a growable array of bytes.
This implementation is suitable for use in postings types.
Postings
Field Summary | |
---|---|
protected int |
increaseFactor
The increase factor to use when resizing the buffer. |
protected int |
lim
The limit of the units array, i.e., the last byte that can be read. |
protected static java.lang.String |
logTag
A tag to use in logging. |
protected int |
off
The offset of the units array where the buffer we're representing starts. |
protected int |
pos
The position in the array where the next byte will be written or read. |
protected byte[] |
units
The array backing our data. |
Fields inherited from class com.sun.labs.minion.util.buffer.StdBufferImpl |
---|
masks, maxBEValues, maxValues, nBits |
Constructor Summary | |
---|---|
protected |
ArrayBuffer()
Creates an array backed buffer that we can use when duplicating or slicing. |
|
ArrayBuffer(byte[] units)
Creates an buffer backed by the given array. |
|
ArrayBuffer(byte[] units,
int off,
int length)
Creates an buffer backed by the given array. |
|
ArrayBuffer(int n)
Creates an array backed buffer with the given initial capacity. |
Method Summary | |
---|---|
WriteableBuffer |
append(ReadableBuffer b,
int n)
Appends a given number of bytes from a readable buffer onto this buffer. |
int |
byteDecode()
Decodes an integer stored using the 7 bit encoding. |
int |
byteEncode(long n)
Encodes an integer in a byte-aligned fashion, using the minimal number of bytes. |
WriteableBuffer |
capacity(int n)
Sets the capacity of the buffer to the given amount. |
protected void |
checkBounds(int p)
Checks whether the given position is outside our array bounds. |
java.lang.Object |
clone()
Clones this buffer. |
ReadableBuffer |
duplicate()
Duplicates this buffer, so that it can be used safely by other readers. |
byte |
get()
Gets the next byte from this buffer. |
byte |
get(int i)
Gets a byte from this buffer at the given position. |
ReadableBuffer |
getReadableBuffer()
Gets a readable buffer from this writeable one. |
int |
limit()
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. |
static void |
main(java.lang.String[] args)
A test program that will encode and decode random integers. |
WriteableBuffer |
or(ReadableBuffer b)
Computes the logical OR of this buffer and another. |
int |
position()
Gets the position in the buffer. |
void |
position(int position)
Sets the position in the buffer. |
WriteableBuffer |
put(byte b)
Puts a single byte onto this buffer. |
WriteableBuffer |
put(byte[] b,
int o,
int n)
Puts a number of bytes onto this buffer. |
WriteableBuffer |
put(int p,
byte b)
Puts a single byte onto this buffer at the given position. |
int |
remaining()
Gets the amount of space remaining in the buffer. |
ReadableBuffer |
slice(int p,
int s)
Slices this buffer so that a sub-buffer can be used. |
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)
Writes 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 com.sun.labs.minion.util.buffer.StdBufferImpl |
---|
append, byteDecode, byteDecode, byteDecodeLong, byteDecodeLong, byteDecodeLong, byteEncode, byteEncode, bytesRequired, byteToBinaryString, clear, countBits, countBits, decodeFloat, encode, encode, getString, set, sizeUTF8, skipByteEncoded, test, toString, toString, toString |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected byte[] units
protected int increaseFactor
protected int pos
protected int off
protected int lim
protected static java.lang.String logTag
Constructor Detail |
---|
protected ArrayBuffer()
public ArrayBuffer(int n)
n
- The initial capacity of the buffer.public ArrayBuffer(byte[] units)
units
- The array with which to back the buffer. This array is
used as provided, so changes to it will affect the buffer.public ArrayBuffer(byte[] units, int off, int length)
units
- The array with which to back the buffer. This array is
used as provided, so changes to it will affect the buffer.off
- The position in the given array where the buffer should
start.length
- The number of bytes that should be in the buffer.Method Detail |
---|
protected void checkBounds(int p)
p
- The position that we want to check.public int position()
position
in interface Buffer
public void position(int position)
position
in interface Buffer
position
- The point to which the buffer's position should be
set.public int remaining()
remaining
in interface Buffer
public WriteableBuffer capacity(int n)
capacity
in interface WriteableBuffer
n
- The number of bytes that the buffer must be able to store.
public WriteableBuffer put(byte b)
put
in interface WriteableBuffer
b
- The byte to put on the buffer
public WriteableBuffer put(int p, byte b)
put
in interface WriteableBuffer
p
- The position where the byte should be put.b
- The byte to put on the buffer
public int byteEncode(long n)
byteEncode
in interface WriteableBuffer
byteEncode
in class StdBufferImpl
n
- The number to encode.
public WriteableBuffer put(byte[] b, int o, int n)
b
- An array from which we'll take the bytes.o
- The offset in the array at which we'll start.n
- The number of bytes to take.
public WriteableBuffer append(ReadableBuffer b, int n)
append
in interface WriteableBuffer
append
in class StdBufferImpl
b
- 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 WriteableBuffer
b
- The buffer to or with this one.
public WriteableBuffer xor(ReadableBuffer b)
xor
in interface WriteableBuffer
b
- The buffer to or with this one.
public void write(java.nio.ByteBuffer b)
put
method to do so efficiently.
write
in interface WriteableBuffer
b
- The java.nio
buffer onto which we will write
this buffer.ByteBuffer.put(byte[],int,int)
public void write(java.nio.channels.WritableByteChannel chan) throws java.io.IOException
ByteBuffer
and then written to the channel.
write
in interface WriteableBuffer
chan
- The channel to which the buffer should be written.
java.io.IOException
- If there is any error writing to the channel.public void write(java.io.DataOutput o) throws java.io.IOException
write
method of DataOutput
.
write
in interface WriteableBuffer
o
- The output to which the buffer will be written.
java.io.IOException
- If there is any error writing the buffer.public void write(java.io.OutputStream os) throws java.io.IOException
write
in interface WriteableBuffer
os
- The stream to which the buffer should be written.
java.io.IOException
- If there is any error writing the buffer.public ReadableBuffer getReadableBuffer()
getReadableBuffer
in interface WriteableBuffer
public ReadableBuffer duplicate()
duplicate
in interface ReadableBuffer
public ReadableBuffer slice(int p, int s)
slice
in interface ReadableBuffer
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()
limit
in interface Buffer
public void limit(int l)
limit
in interface Buffer
l
- The limit that we wish to set.public byte get()
get
in interface ReadableBuffer
public byte get(int i)
get
in interface ReadableBuffer
i
- The position from which we would like to get the byte.
public int byteDecode()
byteDecode
in interface ReadableBuffer
byteDecode
in class StdBufferImpl
byteEncode(long)
public java.lang.Object clone()
clone
in class java.lang.Object
public static void main(java.lang.String[] args) throws java.lang.Exception
args
- The arguments.
java.lang.Exception
- If there is any problem.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |