|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.levigo.jadice.document.io.ByteArrayBuffer
public class ByteArrayBuffer
A ByteArrayBuffer
buffers bytes but is not bound to a fixed
capacity like arrays.
Field Summary | |
---|---|
protected byte[] |
buf
The the last tail buffer. |
protected List<byte[]> |
buffers
A list of already filled up byte arrays. |
protected int |
count
Number of bytes in the tail buffer. |
protected int |
totalSize
Total number of bytes. |
Constructor Summary | |
---|---|
ByteArrayBuffer()
Creates new ByteArrayBuffer with default capacity of 4096 bytes |
|
ByteArrayBuffer(int capacity)
Creates a byte buffer with a certain capacity. |
Method Summary | |
---|---|
void |
append(byte b)
Appends a byte to this buffer |
void |
append(byte[] b)
Appends the given array of bytes. |
void |
append(byte[] b,
int off,
int len)
Appends a subarray of the given byte array. |
void |
append(ByteArrayBuffer buf)
Appends another ByteArrayBuffer to this buffer. |
void |
append(char c)
Appends a character as byte to the buffer. |
void |
clear()
Clears the buffer |
byte |
getByteAt(int index)
Returns the byte value at the given index |
int |
getBytesAt(int index,
byte[] b,
int off,
int len)
Fills up to len bytes from the buffer, and stores them into
b starting at index off . |
void |
setByteAt(int index,
byte newValue)
Changes the byte value at given index |
int |
size()
Returns the current size of the buffer. |
byte[] |
toByteArray()
Creates a newly allocated byte array. |
String |
toString()
Converts the buffer's contents into a string, translating bytes into characters according to the platform's default character encoding. |
String |
toString(String enc)
Converts the buffer's contents into a string, translating bytes into characters according to the specified character encoding. |
void |
writeTo(OutputStream out)
Writes the complete contents of this byte buffer output to the specified output stream argument, as if by calling the output stream's write method using out.write(buf, 0, count) . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected int totalSize
protected int count
protected byte[] buf
protected List<byte[]> buffers
Constructor Detail |
---|
public ByteArrayBuffer()
public ByteArrayBuffer(int capacity)
capacity
- the initial capacityMethod Detail |
---|
public void append(byte[] b, int off, int len)
b
- the array to be appendedoff
- the offset to the start of the arraylen
- the length of bytes to appendpublic void append(byte[] b)
b
- the array to be appendedpublic void append(char c)
c
- the character to be appendedpublic void append(ByteArrayBuffer buf)
buf
- the ByteArrayBuffer
to be appendedpublic void append(byte b)
b
- the byte to be appendedpublic byte getByteAt(int index)
index
- the index of the byte value looked for
ArrayIndexOutOfBoundsException
- if index is smaller than 0 or
greater then the current buffer sizepublic int getBytesAt(int index, byte[] b, int off, int len)
len
bytes from the buffer, and stores them into
b
starting at index off
.
index
- the index of the byte values looked forb
- the byte array to fill upoff
- the starting position within b
to fill up to.len
- the maximum number of bytes to fill in.
b
ArrayIndexOutOfBoundsException
- if index
is smaller
than 0 or greater then the current buffer size or if
off
is negative, len
is negative,
or off +
len
is greater than b.length
.public void setByteAt(int index, byte newValue)
index
- the index of the byte value looked fornewValue
- the new byte value at index position
ArrayIndexOutOfBoundsException
- if index is smaller than 0 or
greater then the current buffer sizepublic void clear()
public byte[] toByteArray()
public int size()
public String toString()
toString
in class Object
public String toString(String enc) throws UnsupportedEncodingException
enc
- a character-encoding name.
UnsupportedEncodingException
- If the named encoding is not
supported.public void writeTo(OutputStream out) throws IOException
out.write(buf, 0, count)
.
out
- the output stream to which to write the data.
IOException
- if an I/O error occurs.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |