EncodedByteArraypublic class EncodedByteArray extends Object Simple byte array with variable array length, used within the
XMLEncoder.
It is used as a ByteArrayOutputStream replacement to limit
the size of created temporary objects |
Fields Summary |
---|
private byte[] | array | private int | pointer | private final double | PADDING |
Constructors Summary |
---|
public EncodedByteArray(byte[] bytes, int startPos, int length)
// string length will be at least the size of the byte array
array = new byte[(int) (bytes.length * PADDING)];
System.arraycopy(bytes, startPos, array, 0, length);
pointer = length;
| public EncodedByteArray(int size)
array = new byte[size];
|
Methods Summary |
---|
public void | append(int aByte)
if (pointer + 1 >= array.length) {
byte[] newArray = new byte[(int) (array.length * PADDING)];
System.arraycopy(array, 0, newArray, 0, pointer);
array = newArray;
}
array[pointer] = (byte) aByte;
pointer++;
| public void | append(byte[] byteArray)
if (pointer + byteArray.length >= array.length) {
byte[] newArray = new byte[((int)(array.length * PADDING)) + byteArray.length];
System.arraycopy(array, 0, newArray, 0, pointer);
array = newArray;
}
System.arraycopy(byteArray, 0, array, pointer, byteArray.length);
pointer += byteArray.length;
| public void | append(byte[] byteArray, int pos, int length)
if (pointer + length >= array.length) {
byte[] newArray = new byte[((int) (array.length * PADDING)) + byteArray.length];
System.arraycopy(array, 0, newArray, 0, pointer);
array = newArray;
}
System.arraycopy(byteArray, pos, array, pointer, length);
pointer += length;
| public java.lang.String | toString()convert to a string using the platform's default charset
return new String(array, 0, pointer);
| public java.lang.String | toString(java.lang.String charsetName)convert the encoded byte array to a string according to the given charset
return new String(array, 0, pointer, charsetName);
|
|