org.curjent.impl.asm
Class ByteVector

java.lang.Object
  extended by org.curjent.impl.asm.ByteVector

final 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

Field Summary
(package private)  byte[] data
          The content of this vector.
(package private)  int length
          Actual number of bytes in this vector.
 
Constructor Summary
ByteVector()
          Constructs a new { @link ByteVector ByteVector} with a default initial size.
ByteVector(int initialSize)
          Constructs a new { @link ByteVector ByteVector} with the given initial size.
 
Method Summary
private  void enlarge(int size)
          Enlarge this byte vector so that it can receive n more bytes.
(package private)  ByteVector put11(int b1, int b2)
          Puts two bytes into this byte vector.
(package private)  ByteVector put12(int b, int s)
          Puts a byte and a short into this byte vector.
(package private)  ByteVector putByte(int b)
          Puts a byte into this byte vector.
(package private)  ByteVector putByteArray(byte[] b, int off, int len)
          Puts an array of bytes into this byte vector.
(package private)  ByteVector putInt(int i)
          Puts an int into this byte vector.
 ByteVector putLong(long l)
          Puts a long into this byte vector.
(package private)  ByteVector putShort(int s)
          Puts a short into this byte vector.
(package private)  ByteVector putUTF8(String s)
          Puts an UTF8 string into this byte vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

byte[] data
The content of this vector.


length

int length
Actual number of bytes in this vector.

Constructor Detail

ByteVector

ByteVector()
Constructs a new { @link ByteVector ByteVector} with a default initial size.


ByteVector

ByteVector(int initialSize)
Constructs a new { @link ByteVector ByteVector} with the given initial size.

Parameters:
initialSize - the initial size of the byte vector to be constructed.
Method Detail

putByte

ByteVector putByte(int b)
Puts a byte into this byte vector. The byte vector is automatically enlarged if necessary.

Parameters:
b - a byte.
Returns:
this byte vector.

put11

ByteVector put11(int b1,
                 int b2)
Puts two bytes into this byte vector. The byte vector is automatically enlarged if necessary.

Parameters:
b1 - a byte.
b2 - another byte.
Returns:
this byte vector.

putShort

ByteVector putShort(int s)
Puts a short into this byte vector. The byte vector is automatically enlarged if necessary.

Parameters:
s - a short.
Returns:
this byte vector.

put12

ByteVector put12(int b,
                 int s)
Puts a byte and a short into this byte vector. The byte vector is automatically enlarged if necessary.

Parameters:
b - a byte.
s - a short.
Returns:
this byte vector.

putInt

ByteVector putInt(int i)
Puts an int into this byte vector. The byte vector is automatically enlarged if necessary.

Parameters:
i - an int.
Returns:
this byte vector.

putLong

public ByteVector putLong(long l)
Puts a long into this byte vector. The byte vector is automatically enlarged if necessary.

Parameters:
l - a long.
Returns:
this byte vector.

putUTF8

ByteVector putUTF8(String s)
Puts an UTF8 string into this byte vector. The byte vector is automatically enlarged if necessary.

Parameters:
s - a String.
Returns:
this byte vector.

putByteArray

ByteVector putByteArray(byte[] b,
                        int off,
                        int len)
Puts an array of bytes into this byte vector. The byte vector is automatically enlarged if necessary.

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

enlarge

private void enlarge(int size)
Enlarge this byte vector so that it can receive n more bytes.

Parameters:
size - number of additional bytes that this byte vector should be able to receive.


Copyright 2009-2011 Tom Landon
Apache License 2.0