com.lizardtech.djvu
Class ByteVector

java.lang.Object
  extended by com.lizardtech.djvu.ByteVector
All Implemented Interfaces:
java.lang.Cloneable

public final class ByteVector
extends java.lang.Object
implements java.lang.Cloneable

This class implements a block vector of bytes.

Version:
$Revision: 1.4 $
Author:
Bill C. Riemers

Field Summary
static int blocksizeDefault
          The default size of each block.
 
Constructor Summary
ByteVector()
          Creates a new ByteVector object.
ByteVector(int blocksize)
          Creates a new ByteVector object.
 
Method Summary
 void addByte(byte value)
          Append a byte to the vector.
 java.lang.Object clone()
          Create a copy by value of this vector.
 int getBlocksize()
          Query the blocksize used for this object.
 byte getByte(int position)
          Query the byte value at a particular offset.
 int getBytes(int position, byte[] data, int offset, int size)
          Copy a range of byte values.
 int readData(java.io.InputStream input, int size)
          Read data into the buffer.
 void setByte(int position, byte value)
          Set a byte at a particular position.
 int size()
          Query the size of this vector.
 byte[] toByteArray()
          Convert the vector to a byte array.
 byte[] toByteArray(int start, int end)
          Convert this vector to a byte array
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

blocksizeDefault

public static final int blocksizeDefault
The default size of each block.

See Also:
Constant Field Values
Constructor Detail

ByteVector

public ByteVector(int blocksize)
Creates a new ByteVector object.

Parameters:
blocksize - DOCUMENT ME!

ByteVector

public ByteVector()
Creates a new ByteVector object.

Method Detail

getBlocksize

public int getBlocksize()
Query the blocksize used for this object.

Returns:
the size of each block

setByte

public void setByte(int position,
                    byte value)
             throws java.lang.ArrayIndexOutOfBoundsException
Set a byte at a particular position. Note that legal values of position are 0 to size() inclusive. If the offset is equal to the size() the byte will be appended.

Parameters:
position - data offset to set
value - data value to set
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the position is outside the valid range

getByte

public byte getByte(int position)
Query the byte value at a particular offset.

Parameters:
position - data offset to query
Returns:
data value
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the position is outside the valid range

getBytes

public int getBytes(int position,
                    byte[] data,
                    int offset,
                    int size)
Copy a range of byte values.

Parameters:
position - data offset to start copying
data - byte array to copy data to
offset - byte array offset to start copying to
size - maximum number of bytes to copy
Returns:
number of bytes copied

addByte

public void addByte(byte value)
Append a byte to the vector.

Parameters:
value - byte value to append

clone

public java.lang.Object clone()
Create a copy by value of this vector. This method assumes ByteVector is final.

Overrides:
clone in class java.lang.Object
Returns:
The newly created copy

readData

public int readData(java.io.InputStream input,
                    int size)
             throws java.io.IOException
Read data into the buffer.

Parameters:
input - stream to read
size - maximum amount of data to read
Returns:
amount of data to read
Throws:
java.io.IOException - if an error occurs

size

public int size()
Query the size of this vector.

Returns:
the size of this vector

toByteArray

public byte[] toByteArray(int start,
                          int end)
Convert this vector to a byte array

Parameters:
start - position to start copying from
end - position to copy to
Returns:
the newly created byte array

toByteArray

public byte[] toByteArray()
Convert the vector to a byte array.

Returns:
the newly created byte array