UnsafeByteSequencepublic class UnsafeByteSequence extends Object Defines the same class as the java.lang.UnsafeByteSequence which was added in
Dalvik VM. This hack, provides a replacement for that class which can't be
loaded in the standard JVM since it's in the java package and standard JVM
doesn't have it.
Extracted from API level 18, file:
platform/libcore/luni/src/main/java/java/lang/UnsafeByteSequence.java |
Fields Summary |
---|
private byte[] | bytes | private int | count |
Constructors Summary |
---|
public UnsafeByteSequence(int initialCapacity)
this.bytes = new byte[initialCapacity];
|
Methods Summary |
---|
public void | rewind()Moves the write pointer back to the beginning of the sequence,
but without resizing or reallocating the buffer.
count = 0;
| public int | size()
return count;
| public byte[] | toByteArray()
if (count == bytes.length) {
return bytes;
}
byte[] result = new byte[count];
System.arraycopy(bytes, 0, result, 0, count);
return result;
| public java.lang.String | toString(java.nio.charset.Charset cs)
return new String(bytes, 0, count, cs);
| public void | write(byte[] buffer, int offset, int length)
if (count + length >= bytes.length) {
byte[] newBytes = new byte[(count + length) * 2];
System.arraycopy(bytes, 0, newBytes, 0, count);
bytes = newBytes;
}
System.arraycopy(buffer, offset, bytes, count, length);
count += length;
| public void | write(int b)
if (count == bytes.length) {
byte[] newBytes = new byte[count * 2];
System.arraycopy(bytes, 0, newBytes, 0, count);
bytes = newBytes;
}
bytes[count++] = (byte) b;
|
|