|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectPackedByteBuf
public class PackedByteBuf
Packs ints and strings into a byte buffer, using an efficient variable-size int format. Transparently compresses and decompresses large buffers.
Nested Class Summary | |
---|---|
private class |
PackedByteBuf.CompressInfo
Keeps tracks of inflate/deflate stuff on a thread-local basis. |
Field Summary | |
---|---|
private byte[] |
bytes
Byte buffer to read from or write to |
private boolean |
compressed
Tells whether compression succeeded |
private static ThreadLocal |
compressInfo
Used to compress/decompress data |
private static int |
compressLimitMax
Maximum buffer size to compress (above this, we wouldn't have enough bytes to store the length.) |
private static int |
compressLimitMin
Minimum buffer size to compress (below this, it's probably not worth even trying). |
private static byte |
compressMarker
Special marker used to denote a compressed buffer |
private boolean |
compressTried
Tells whether we've attempted to compress the buffer |
private int |
pos
Current position within the byte buffer, bytes |
private char[] |
strChars
Temporary buffer used when decoding strings |
private int |
uncompLen
Original (uncompressed) length of the buffer |
Constructor Summary | |
---|---|
PackedByteBuf(byte[] rawBytes)
Construct a byte buffer from packed data that has been read somehow. |
|
PackedByteBuf(DataInput in,
int len)
Construct a byte buffer for reading from. |
|
PackedByteBuf(int initialSize)
Construct a byte buffer for writing into. |
|
PackedByteBuf(SubStoreReader in,
int len)
Construct a byte buffer for reading from. |
Method Summary | |
---|---|
Object |
clone()
Obtain a copy of this buffer (with only the valid bytes) |
void |
compact()
Makes the buffer as small as possible to hold the existing data; after this operation, no more data may be added. |
private void |
compress()
If the buffer hasn't been compressed yet, do so. |
private void |
decompress()
Given a raw buffer, this method determines if it is compressed, and if so, decompresses it. |
private void |
ensureSize(int nBytes)
Make sure that the buffer has room to hold at least nBytes bytes. |
int |
length()
Returns the number of bytes currently in the buffer. |
void |
output(DataOutput out)
Copy the entire contents of the buffer to an output sink. |
void |
output(DataOutput out,
int len)
Copy some or all of the buffer to an output sink. |
void |
output(SubStoreWriter out)
Copy the entire contents of the buffer to an output sink. |
void |
output(SubStoreWriter out,
int len)
Copy some or all of the buffer to an output sink. |
PackedByteBuf |
readBuffer()
Read a buffer that was previously packed into this one with writeBuffer(). |
byte |
readByte()
Read in a single byte from the buffer. |
void |
readBytes(byte[] bytes)
Read in a bunch of bytes. |
void |
readBytes(byte[] outBytes,
int start,
int length)
Read in a bunch of bytes. |
int |
readInt()
Read an integer from a buffer that was previously made with writeInt(). |
String |
readString()
Read a string from a buffer that was previously made with writeString(). |
void |
reset()
Resets the buffer so that reads/writes occur at the start. |
void |
setBytes(byte[] rawBytes)
Take a chunk of raw data for unpacking. |
void |
skipBuffer()
Skip over a buffer that was written with writeBuffer() |
void |
skipBytes(int num)
Skip a bunch of bytes |
void |
skipInt()
Skip over an integer made with writeInt() |
void |
skipString()
Skip over a string that was written with writeString() |
void |
writeBuffer(PackedByteBuf b)
Write another buffer into this one. |
void |
writeByte(byte b)
Write out a single byte. |
void |
writeBytes(byte[] b)
Write out a bunch of bytes |
void |
writeBytes(byte[] b,
int offset,
int length)
Write out a bunch of bytes |
void |
writeCharSequence(CharSequence s)
Write a general character sequence to the buffer, using an efficient format. |
void |
writeInt(int n)
Write a (non-negative) integer to the buffer. |
void |
writeString(String s)
Write a string to the buffer, using an efficient format. |
Methods inherited from class Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private byte[] bytes
private int pos
bytes
private char[] strChars
private boolean compressTried
private boolean compressed
private int uncompLen
private static ThreadLocal compressInfo
private static final byte compressMarker
private static final int compressLimitMin
private static final int compressLimitMax
Constructor Detail |
---|
public PackedByteBuf(int initialSize)
initialSize
- Hint as to the likely maximum amount of data bytes.
If this is exceeded, the buffer will expand itself
automatically.public PackedByteBuf(SubStoreReader in, int len) throws IOException
in
- Source for datalen
- How many bytes to read
IOException
public PackedByteBuf(DataInput in, int len) throws IOException
in
- Source for datalen
- How many bytes to read
IOException
public PackedByteBuf(byte[] rawBytes)
rawBytes
- The raw dataMethod Detail |
---|
public void setBytes(byte[] rawBytes)
rawBytes
- The raw dataprivate void decompress()
public Object clone()
clone
in class Object
public void writeByte(byte b)
public void writeBytes(byte[] b)
public void writeBytes(byte[] b, int offset, int length)
public void writeInt(int n)
n
- The number to writepublic void writeString(String s)
s
- The string to write.public void writeCharSequence(CharSequence s)
s
- The sequence to write.public void writeBuffer(PackedByteBuf b)
b
- The buffer to write.private void ensureSize(int nBytes)
public void reset()
private void compress()
public void compact()
public int length()
public void output(SubStoreWriter out) throws IOException
out
- Where to write the data to.
IOException
public void output(DataOutput out) throws IOException
out
- Where to write the data to.
IOException
public void output(SubStoreWriter out, int len) throws IOException
out
- Where to write the data tolen
- How many bytes to write (okay to exceed buffer length)
IOException
public void output(DataOutput out, int len) throws IOException
out
- Where to write the data tolen
- How many bytes to write (okay to exceed buffer length)
IOException
public byte readByte()
public void readBytes(byte[] bytes)
public void readBytes(byte[] outBytes, int start, int length)
public void skipBytes(int num)
public int readInt()
public void skipInt()
public String readString()
public void skipString()
public PackedByteBuf readBuffer()
public void skipBuffer()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |