FileDocCategorySizeDatePackage
ByteVector.javaAPI DocGlassfish v2 API8060Thu Mar 02 11:51:12 GMT 2006oracle.toplink.libraries.asm

ByteVector

public class ByteVector extends Object
A dynamically extensible vector of bytes. This class is roughly equivalent to a DataOutputStream on top of a ByteArrayOutputStream, but is more efficient.
author
Eric Bruneton

Fields Summary
byte[]
data
The content of this vector.
int
length
Actual number of bytes in this vector.
Constructors Summary
public ByteVector()
Constructs a new {@link ByteVector ByteVector} with a default initial size.

    data = new byte[64];
  
public ByteVector(int initialSize)
Constructs a new {@link ByteVector ByteVector} with the given initial size.

param
initialSize the initial size of the byte vector to be constructed.

    data = new byte[initialSize];
  
Methods Summary
private voidenlarge(int size)
Enlarge this byte vector so that it can receive n more bytes.

param
size number of additional bytes that this byte vector should be able to receive.

    int length1 = 2 * data.length;
    int length2 = length + size;
    byte[] newData = new byte[length1 > length2 ? length1 : length2];
    System.arraycopy(data, 0, newData, 0, length);
    data = newData;
  
oracle.toplink.libraries.asm.ByteVectorput11(int b1, int b2)
Puts two bytes into this byte vector. The byte vector is automatically enlarged if necessary.

param
b1 a byte.
param
b2 another byte.
return
this byte vector.

    int length = this.length;
    if (length + 2 > data.length) {
      enlarge(2);
    }
    byte[] data = this.data;
    data[length++] = (byte)b1;
    data[length++] = (byte)b2;
    this.length = length;
    return this;
  
oracle.toplink.libraries.asm.ByteVectorput12(int b, int s)
Puts a byte and a short into this byte vector. The byte vector is automatically enlarged if necessary.

param
b a byte.
param
s a short.
return
this byte vector.

    int length = this.length;
    if (length + 3 > data.length) {
      enlarge(3);
    }
    byte[] data = this.data;
    data[length++] = (byte)b;
    data[length++] = (byte)(s >>> 8);
    data[length++] = (byte)s;
    this.length = length;
    return this;
  
public oracle.toplink.libraries.asm.ByteVectorputByte(int b)
Puts a byte into this byte vector. The byte vector is automatically enlarged if necessary.

param
b a byte.
return
this byte vector.

    int length = this.length;
    if (length + 1 > data.length) {
      enlarge(1);
    }
    data[length++] = (byte)b;
    this.length = length;
    return this;
  
public oracle.toplink.libraries.asm.ByteVectorputByteArray(byte[] b, int off, int len)
Puts an array of bytes into this byte vector. The byte vector is automatically enlarged if necessary.

param
b an array of bytes. May be null to put len null bytes into this byte vector.
param
off index of the fist byte of b that must be copied.
param
len number of bytes of b that must be copied.
return
this byte vector.

    if (length + len > data.length) {
      enlarge(len);
    }
    if (b != null) {
      System.arraycopy(b, off, data, length, len);
    }
    length += len;
    return this;
  
public oracle.toplink.libraries.asm.ByteVectorputInt(int i)
Puts an int into this byte vector. The byte vector is automatically enlarged if necessary.

param
i an int.
return
this byte vector.

    int length = this.length;
    if (length + 4 > data.length) {
      enlarge(4);
    }
    byte[] data = this.data;
    data[length++] = (byte)(i >>> 24);
    data[length++] = (byte)(i >>> 16);
    data[length++] = (byte)(i >>> 8);
    data[length++] = (byte)i;
    this.length = length;
    return this;
  
public oracle.toplink.libraries.asm.ByteVectorputLong(long l)
Puts a long into this byte vector. The byte vector is automatically enlarged if necessary.

param
l a long.
return
this byte vector.

    int length = this.length;
    if (length + 8 > data.length) {
      enlarge(8);
    }
    byte[] data = this.data;
    int i = (int)(l >>> 32);
    data[length++] = (byte)(i >>> 24);
    data[length++] = (byte)(i >>> 16);
    data[length++] = (byte)(i >>> 8);
    data[length++] = (byte)i;
    i = (int)l;
    data[length++] = (byte)(i >>> 24);
    data[length++] = (byte)(i >>> 16);
    data[length++] = (byte)(i >>> 8);
    data[length++] = (byte)i;
    this.length = length;
    return this;
  
public oracle.toplink.libraries.asm.ByteVectorputShort(int s)
Puts a short into this byte vector. The byte vector is automatically enlarged if necessary.

param
s a short.
return
this byte vector.

    int length = this.length;
    if (length + 2 > data.length) {
      enlarge(2);
    }
    byte[] data = this.data;
    data[length++] = (byte)(s >>> 8);
    data[length++] = (byte)s;
    this.length = length;
    return this;
  
public oracle.toplink.libraries.asm.ByteVectorputUTF8(java.lang.String s)
Puts an UTF8 string into this byte vector. The byte vector is automatically enlarged if necessary.

param
s a String.
return
this byte vector.

    int charLength = s.length();
    int byteLength = 0;
    for (int i = 0; i < charLength; ++i) {
      char c = s.charAt(i);
      if (c >= '\001" && c <= '\177") {
        byteLength++;
      } else if (c > '\u07FF") {
        byteLength += 3;
      } else {
        byteLength += 2;
      }
    }
    if (byteLength > 65535) {
      throw new IllegalArgumentException();
    }
    int length = this.length;
    if (length + 2 + byteLength > data.length) {
      enlarge(2 + byteLength);
    }
    byte[] data = this.data;
    data[length++] = (byte)(byteLength >>> 8);
    data[length++] = (byte)(byteLength);
    for (int i = 0; i < charLength; ++i) {
      char c = s.charAt(i);
      if (c >= '\001" && c <= '\177") {
        data[length++] = (byte)c;
      } else if (c > '\u07FF") {
        data[length++] = (byte)(0xE0 | c >> 12 & 0xF);
        data[length++] = (byte)(0x80 | c >> 6 & 0x3F);
        data[length++] = (byte)(0x80 | c & 0x3F);
      } else {
        data[length++] = (byte)(0xC0 | c >> 6 & 0x1F);
        data[length++] = (byte)(0x80 | c & 0x3F);
      }
    }
    this.length = length;
    return this;