public final class ByteArrayBuffer extends Object implements Serializable
| Constructor and Description | 
|---|
| ByteArrayBuffer(int capacity)Creates an instance of  ByteArrayBufferwith the given initial
 capacity. | 
| Modifier and Type | Method and Description | 
|---|---|
| void | append(byte[] b,
      int off,
      int len)Appends  lenbytes to this buffer from the given source
 array starting at indexoff. | 
| void | append(ByteBuffer buffer) | 
| void | append(char[] b,
      int off,
      int len)Appends  lenchars to this buffer from the given source
 array starting at indexoff. | 
| void | append(CharArrayBuffer b,
      int off,
      int len)Appends  lenchars to this buffer from the given source
 char array buffer starting at indexoff. | 
| void | append(int b)Appends  bbyte to this buffer. | 
| byte[] | array()Returns reference to the underlying byte array. | 
| int | byteAt(int i)Returns the  bytevalue in this buffer at the specified
 index. | 
| int | capacity()Returns the current capacity. | 
| void | clear()Clears content of the buffer. | 
| void | ensureCapacity(int required)Ensures that the capacity is at least equal to the specified minimum. | 
| int | indexOf(byte b)Returns the index within this buffer of the first occurrence of the
 specified byte, starting the search at  0and finishing
 atlength(). | 
| int | indexOf(byte b,
       int from,
       int to)Returns the index within this buffer of the first occurrence of the
 specified byte, starting the search at the specified
  beginIndexand finishing atendIndex. | 
| boolean | isEmpty() | 
| boolean | isFull() | 
| int | length()Returns the length of the buffer (byte count). | 
| void | setLength(int len)Sets the length of the buffer. | 
| byte[] | toByteArray()Converts the content of this buffer to an array of bytes. | 
public ByteArrayBuffer(int capacity)
ByteArrayBuffer with the given initial
 capacity.capacity - the capacitypublic void append(byte[] b,
                   int off,
                   int len)
len bytes to this buffer from the given source
 array starting at index off. The capacity of the buffer
 is increased, if necessary, to accommodate all len bytes.b - the bytes to be appended.off - the index of the first byte to append.len - the number of bytes to append.IndexOutOfBoundsException - if off if out of
 range, len is negative, or
 off + len is out of range.public void append(int b)
b byte to this buffer. The capacity of the buffer
 is increased, if necessary, to accommodate the additional byte.b - the byte to be appended.public void append(char[] b,
                   int off,
                   int len)
len chars to this buffer from the given source
 array starting at index off. The capacity of the buffer
 is increased if necessary to accommodate all len chars.
 The chars are converted to bytes using simple cast.
b - the chars to be appended.off - the index of the first char to append.len - the number of bytes to append.IndexOutOfBoundsException - if off if out of
 range, len is negative, or
 off + len is out of range.public void append(CharArrayBuffer b, int off, int len)
len chars to this buffer from the given source
 char array buffer starting at index off. The capacity
 of the buffer is increased if necessary to accommodate all
 len chars.
 The chars are converted to bytes using simple cast.
b - the chars to be appended.off - the index of the first char to append.len - the number of bytes to append.IndexOutOfBoundsException - if off if out of
 range, len is negative, or
 off + len is out of range.public void append(ByteBuffer buffer)
public void clear()
public byte[] toByteArray()
public int byteAt(int i)
byte value in this buffer at the specified
 index. The index argument must be greater than or equal to
 0, and less than the length of this buffer.i - the index of the desired byte value.IndexOutOfBoundsException - if index is
             negative or greater than or equal to length().public int capacity()
public int length()
public void ensureCapacity(int required)
required
 argument is non-positive, this method takes no action.required - the minimum required capacity.public byte[] array()
public void setLength(int len)
0.len - the new lengthIndexOutOfBoundsException - if the
               len argument is greater than the current
               capacity of the buffer or less than 0.public boolean isEmpty()
true if this buffer is empty, false
   otherwise.public boolean isFull()
true if this buffer is full, false
   otherwise.public int indexOf(byte b,
                   int from,
                   int to)
beginIndex and finishing at endIndex.
 If no such byte occurs in this buffer within the specified bounds,
 -1 is returned.
 
 There is no restriction on the value of beginIndex and
 endIndex. If beginIndex is negative,
 it has the same effect as if it were zero. If endIndex is
 greater than length(), it has the same effect as if it were
 length(). If the beginIndex is greater than
 the endIndex, -1 is returned.
b - the byte to search for.from - the index to start the search from.to - the index to finish the search at.-1 if the byte does
   not occur.public int indexOf(byte b)
0 and finishing
 at length(). If no such byte occurs in this buffer within
 those bounds, -1 is returned.b - the byte to search for.-1 if the byte does not occur.Copyright © 2005–2021 The Apache Software Foundation. All rights reserved.