public class Buffer
extends java.lang.Object
implements java.lang.Comparable, java.lang.Cloneable
Constructor and Description |
---|
Buffer()
Create a zero-count sequence.
|
Buffer(byte[] bytes)
Create a Buffer using the byte array as the initial value.
|
Buffer(byte[] bytes,
int offset,
int length)
Create a Buffer using the byte range as the initial value.
|
Modifier and Type | Method and Description |
---|---|
void |
append(byte[] bytes)
Append specified bytes to the buffer
|
void |
append(byte[] bytes,
int offset,
int length)
Append specified bytes to the buffer.
|
java.lang.Object |
clone() |
int |
compareTo(java.lang.Object other)
Define the sort order of the Buffer.
|
void |
copy(byte[] bytes,
int offset,
int length)
Copy the specified byte array to the Buffer.
|
boolean |
equals(java.lang.Object other) |
byte[] |
get()
Get the data from the Buffer.
|
int |
getCapacity()
Get the capacity, which is the maximum count that could handled without
resizing the backing storage.
|
int |
getCount()
Get the current count of the buffer.
|
int |
hashCode() |
void |
reset()
Reset the buffer to 0 size
|
void |
set(byte[] bytes)
Use the specified bytes array as underlying sequence.
|
void |
setCapacity(int newCapacity)
Change the capacity of the backing storage.
|
java.lang.String |
toString() |
java.lang.String |
toString(java.lang.String charsetName)
Convert the byte buffer to a string an specific character encoding
|
void |
truncate()
Change the capacity of the backing store to be the same as the current
count of buffer.
|
public Buffer()
public Buffer(byte[] bytes)
bytes
- This array becomes the backing storage for the object.public Buffer(byte[] bytes, int offset, int length)
bytes
- Copy of this array becomes the backing storage for the object.offset
- offset into byte arraylength
- length of datapublic void set(byte[] bytes)
bytes
- byte sequencepublic final void copy(byte[] bytes, int offset, int length)
bytes
- byte array to be assignedoffset
- offset into byte arraylength
- length of datapublic byte[] get()
public int getCount()
public int getCapacity()
public void setCapacity(int newCapacity)
newCapacity
- The new capacity in bytes.public void reset()
public void truncate()
public void append(byte[] bytes, int offset, int length)
bytes
- byte array to be appendedoffset
- offset into byte arraylength
- length of datapublic void append(byte[] bytes)
bytes
- byte array to be appendedpublic int hashCode()
hashCode
in class java.lang.Object
public int compareTo(java.lang.Object other)
compareTo
in interface java.lang.Comparable
other
- The other bufferpublic boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(java.lang.String charsetName) throws java.io.UnsupportedEncodingException
charsetName
- Valid Java Character Set Namejava.io.UnsupportedEncodingException
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException