Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
netscape.ldap.util.ByteBuf
public final class ByteBuf
extends java.lang.Object
implements Serializable
java.lang.StringBuffer
class. Instead of storing a string, an object of this class
stores an array of bytes. (This is referred to as a "byte buffer".)
This class also differs from StringBuffer
in the
following ways:
Alloc
and Recycle
methods are provided. You can "recycle"
any ByteBuf
objects you no longer need by using the
Recycle
method. Calling the Alloc
method will reuse objects that have been "recycled." To
To clear out the cache of these "recycled" objects, use
the EmptyRecycler
method.
Constructor Summary | |
| |
| |
| |
|
Method Summary | |
ByteBuf |
|
ByteBuf |
|
ByteBuf |
|
ByteBuf |
|
ByteBuf |
|
ByteBuf |
|
ByteBuf |
|
ByteBuf |
|
ByteBuf | |
ByteBuf |
|
ByteBuf |
|
byte |
|
int |
|
void |
|
void |
|
int |
|
int |
|
int |
|
void |
|
void |
|
byte[] |
|
String |
|
void |
|
void |
|
public ByteBuf()
Constructs an empty byte buffer with the default length of 16.
public ByteBuf(String str)
Constructs a byte buffer with the specified initial value. The new byte buffer is 16 bytes longer than the initial value.
- Parameters:
str
- initial value that this buffer should hold
public ByteBuf(bytes[] , int offset, int length)
Constructs a byte buffer with the specified length. An initial value is stored in this buffer, starting at the specified offset.
- Parameters:
offset
- index where you want the initial value to start in the arraylength
- length of the buffer to allocate
public ByteBuf(int length)
Constructs an empty byte buffer with the specified initial length.
- Parameters:
length
- initial number of bytes that this buffer should hold
public ByteBuf append(Object obj)
Appends an object to the end of this byte buffer.
- Parameters:
obj
- the object to append to the buffer
- Returns:
- the same
ByteBuf
object (not a new object) with the string representation of the specified object appended.
public ByteBuf append(String str)
Appends a string to the end of this byte buffer. This method appends one byte for each character in the string. The upper 8 bits of the character are stripped off. If you want to retain all bits in the character (not just the lower 8 bits), useappend(String.getBytes())
instead.
- Parameters:
str
- the string that you want appended to the buffer
- Returns:
- the same
ByteBuf
object (not a new object) with the specified string appended
public ByteBuf append(boolean b)
Appends a boolean to the end of this byte buffer.
- Parameters:
b
- the boolean value that you want appended to this buffer
- Returns:
- the original
ByteBuf
object (not a new object) with bytes from the string representation of the boolean value appended.
public ByteBuf append(byte b)
Appends a byte to the end of this byte buffer.
- Parameters:
b
- the byte to append to this buffer
- Returns:
- the original
ByteBuf
object (not a new object) with the specified byte appended.
public ByteBuf append(double d)
Appends adouble
to the end of this byte buffer.
- Parameters:
d
- thedouble
value to append to this buffer
- Returns:
- the original
ByteBuf
object (not a new object) with the string representation of the specifieddouble
value appended.
public ByteBuf append(float f)
Appends afloat
to the end of this byte buffer.
- Parameters:
f
- thefloat
value to append to this buffer
- Returns:
- the original
ByteBuf
object (not a new object) with the string representation of the specifiedfloat
value appended.
public ByteBuf append(int i)
Appends an integer to the end of this byte buffer.
- Parameters:
i
- the integer to append to this byte buffer
- Returns:
- the original
ByteBuf
object (not a new object) with the string representation of the specified integer appended.
public ByteBuf append(long l)
Appends along
value to the end of this byte buffer.
- Parameters:
l
- thelong
value to append to this buffer
- Returns:
- the original
ByteBuf
object (not a new object) with the string representation of the specifiedlong
value appended.
public ByteBuf append(ByteBuf buf)
Appends a byte buffer to the end of this byte buffer.
- Parameters:
buf
- the byte buffer to append to this buffer
- Returns:
- the original
ByteBuf
object (not a new object) with bytes from the specified byte buffer appended.
public ByteBuf append(str[] )
Appends an array of bytes to the end of this byte buffer.
- Parameters:
- Returns:
- the same
ByteBuf
object (not a new object) with the specified bytes appended.
public ByteBuf append(str[] , int offset, int len)
Appends a part of an array of bytes to the end of this byte buffer.
- Parameters:
offset
- the index in the array marking the start of the section to copylen
- the number of bytes to add
- Returns:
- the same
ByteBuf
object (not a new object) with the specified section of the byte array appended
public byte byteAt(int index)
Returns the byte at the specified index. The value of an index can range from 0 to length - 1.
- Parameters:
index
- index of the byte to find
public int capacity()
Returns the current capacity of the byte buffer. The capacity is the amount of storage available for newly inserted bytes. If the capacity is exceeded, more space will be allocated.
public void ensureCapacity(int minimumCapacity)
Ensures that the capacity of the buffer is at least equal to the specified minimum capacity.
- Parameters:
minimumCapacity
- the minimum number of bytes that you want the byte buffer to hold
public void getBytes(int srcBegin, int srcEnd, dst[] , int dstBegin)
Copies the bytes (from the section of the byte buffer from the indexsrcBegin
to the indexsrcEnd - 1
) into the specified byte array. The copied bytes are inserted in the byte array at the index specified bydstBegin
. BothsrcBegin
andsrcEnd
must be valid indexes in the buffer.
- Parameters:
srcBegin
- index identifying the start of the section of the byte buffer to copysrcEnd
- index identifying the end of the section of the byte buffer to copy. (Copy all bytes before the byte identified by this index.)dstBegin
- index of the byte array identifying the location to which the byte buffer is copied
public int length()
Returns the length (character count) of the byte buffer.
public int read(InputStream file, int max_bytes) throws IOException
Invokes theInputStream.read
method and appends the the bytes read to this byte buffer.
- Parameters:
file
- the input stream from which to read the bytesmax_bytes
- the maximum number of bytes to read into the byte buffer
- Returns:
- the number of bytes read, or -1 if there is no more data to read.
public int read(RandomAccessFile file, int max_bytes) throws IOException
Invokes theRandomAccessFile.read
method, appending the bytes read to this byte buffer.
- Parameters:
file
- theRandomAccessFile
object from which to read the bytesmax_bytes
- the maximum number of bytes to read into the byte buffer
- Returns:
- the number of bytes read, or -1 if there is no more data to read.
public void setByteAt(int index, byte b)
Sets the value of the byte at the specified index.
- Parameters:
index
- the index of the byte to setb
- the new value to set
public void setLength(int newLength)
Sets the length of the byte buffer. If you set a length that is shorter than the current length, bytes at the end of the buffer are lost. If you increase the length of the buffer, the values of the new bytes in the buffer are set to 0.
- Parameters:
newLength
- the new length of the buffer
public byte[] toBytes()
Returns the data in the byte buffer as a byte array.
- Returns:
- the byte array containing data in the byte buffer.
public String toString()
Returns the data in the byte buffer to a string.
- Returns:
- the string representation of the data in the byte buffer.
public void write(OutputStream out) throws IOException
Writes the contents of the byte buffer to the specified output stream.
- Parameters:
out
- the output stream
public void write(RandomAccessFile out) throws IOException
Writes the contents of the byte buffer to the specifiedRandomAccessFile
object.
- Parameters:
out
- theRandomAccessFile
object dexception IOException An I/O error has occurred.