GiciStream
Class ByteStream

java.lang.Object
  extended by GiciStream.ByteStream

public class ByteStream
extends java.lang.Object

This class is a byte buffer, useful to store a byte stream. When the length of the ByteStream is known a priori, this class should be instantianed using the constructor with the initialSizeBuffer. When the length it is not known, this class begins instantiating a small buffer and duplicates its size (copying all contents) when it is full. The duplication of the buffer length is performed until maxBuffAllocation is reached, then is increased the number of bytes of this variable. Variables initialBuffAllocation and maxBuffAllocation controls the performance of this method; default values ara intialized to be efficient when containing small buffers (not more than 10 KB). If you need larger buffer capacities, you should change these variables.

Version:
1.1
Author:
Group on Interactive Coding of Images (GICI)

Field Summary
private  byte[] byteBuffer
          Byte array used to store bytes.
private  int index
          Index of the current position of the byte buffer (number of bytes saved in byteBuffer minus 1).
private  int initialBuffAllocation
          Initial length of the byte buffer.
private  int maxBuffAllocation
          When the buffer is full, its length is duplicated until maxBuffAllocation is reached.
 
Constructor Summary
ByteStream()
          Class constructor (performs needed initializations).
ByteStream(byte[] byteBuffer, int numBytes)
          Class constructor allowing to insert a byte array (performs needed initializations).
ByteStream(int initialSizeBuffer)
          Class constructor with a specified amount of bytes to allocate initially in the buffer.
 
Method Summary
 void addByte(byte b)
          Inserts a byte in the ByteStream.
 void addBytes(byte[] bytes, int numBytes)
          Inserts bytes in the bytestream.
 void deleteBeginBytes(int num)
          Deletes a number of bytes of the bytestream (at the begining of bytestream).
 void deleteEndBytes(int num)
          Deletes a number of bytes of the bytestream (at the end of bytestream).
 byte getByte(int numByte)
          Return the byte indicated.
 byte[] getByteStream()
          Return the byte stream in an array of bytes (the length of array byte returned is equal or greater than the real bytes contained in byteStream -it can be known using getNumBytes function-).
 int getNumBytes()
          Return the number of bytes in the byte stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

byteBuffer

private byte[] byteBuffer
Byte array used to store bytes.

All values allowed.


index

private int index
Index of the current position of the byte buffer (number of bytes saved in byteBuffer minus 1).

Negative values are not allowed for this field.


initialBuffAllocation

private final int initialBuffAllocation
Initial length of the byte buffer.

Negative values are not allowed for this field.

See Also:
Constant Field Values

maxBuffAllocation

private final int maxBuffAllocation
When the buffer is full, its length is duplicated until maxBuffAllocation is reached. Then the size of the buffer is incremented this amount of bytes.

Negative values are not allowed for this field.

See Also:
Constant Field Values
Constructor Detail

ByteStream

public ByteStream()
Class constructor (performs needed initializations).


ByteStream

public ByteStream(int initialSizeBuffer)
Class constructor with a specified amount of bytes to allocate initially in the buffer.

Parameters:
initialSizeBuffer - number of bytes that initially the buffer will contain

ByteStream

public ByteStream(byte[] byteBuffer,
                  int numBytes)
Class constructor allowing to insert a byte array (performs needed initializations).

Parameters:
byteBuffer - the byte buffer to use
numBytes - of bytes valid in byte buffer
Method Detail

addByte

public void addByte(byte b)
Inserts a byte in the ByteStream.

Parameters:
b - the byte that will be inserted into byte stream

addBytes

public void addBytes(byte[] bytes,
                     int numBytes)
Inserts bytes in the bytestream.

Parameters:
bytes - an array of bytes that will be inserted into byte stream
numBytes - the number of bytes to insert in the bytestream

deleteEndBytes

public void deleteEndBytes(int num)
Deletes a number of bytes of the bytestream (at the end of bytestream). If number of bytes to delete is greater than bytestream, bytestream length will be 0.

Parameters:
num - the number of bytes to delete

deleteBeginBytes

public void deleteBeginBytes(int num)
Deletes a number of bytes of the bytestream (at the begining of bytestream). If number of bytes to delete is greater than bytestream, bytestream length will be 0. ATTENTION: this function compels to copy the whole ByteStream. It is poor efficient!!!

Parameters:
num - the number of bytes to delete

getByte

public byte getByte(int numByte)
             throws WarningException
Return the byte indicated.

Parameters:
numByte - the number of byte in bytestream (starting at 0)
Returns:
the byte asked for
Throws:
WarningException - when numByte is greater than the buffer length

getByteStream

public byte[] getByteStream()
Return the byte stream in an array of bytes (the length of array byte returned is equal or greater than the real bytes contained in byteStream -it can be known using getNumBytes function-).

Returns:
a byte array that contains the byte stream

getNumBytes

public int getNumBytes()
Return the number of bytes in the byte stream.

Returns:
an integer indicating number of bytes in the byte stream


TER - Copyright (C) 2006
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Group on Interactive Coding of Images (GICI) - UAB (Spain)