Xj3D VRML/X3D Code API

org.web3d.vrml.export.compressors
Class CodeOutputPacker

java.lang.Object
  extended byorg.web3d.vrml.export.compressors.CodeOutputPacker

public class CodeOutputPacker
extends java.lang.Object

Packs N bit codes into destination bytes, either an array or stream. N may be more or less than (or equal) to 8. Packing order as shown for some widths:

 Width = 12 x 2 codes = 8 x 3
 |BA987654|
 |3210/BA98|
 |76543210|
 Width = 10 x 4 codes = 8 x 5
 |98765432|
 |10/987654|
 |3210/9876|
 |543210/98|
 |76543210|
 Width = 8,
 |76543210|
 Width = 7 x 8 codes = 8 x 7
 |6543210/6|
 |543210/65|
 |43210/654|
 |3210/6543|
 |210/65432|
 |10/654321|
 |0/6543210|
 Width = 6 x 4 codes = 8 x 3
 |543210/54|
 |3210/5432|
 |10/543210|
 

Version:
$Revision: 1.3 $
Author:
Alan Hudson

Constructor Summary
CodeOutputPacker(byte[] bytes)
          Constructor to fill a byte array, for default code width.
CodeOutputPacker(byte[] bytes, int N)
          Constructor to fill a byte array,
CodeOutputPacker(int nbytes)
          Constructor to make and fill a byte array, for default code width.
CodeOutputPacker(int nbytes, int N)
          Constructor to make and fill a byte array,
CodeOutputPacker(java.io.OutputStream stream)
          Constructor to output bytes to a stream, for default code width.
CodeOutputPacker(java.io.OutputStream stream, int N)
          Constructor to output bytes to a stream,
 
Method Summary
 void flush()
          Make sure any pending bits are output.
 int getCount()
          Return how many bytes of packed data were written, to the array or stream.
 void putN(int code)
          Write or accumulate another N bit code
 void putNArray(int[] codes)
          Put and pack an array of all N bit codes, according to set or default code width.
 void reset()
          Doing reset () on Packer means fill buffer from the top, the assumption here is that it has been written somewhere.
 void setWidth(int width)
           
 byte[] toByteArray()
          Copy to Byte Array sized for actual data contained, valid only if an array was used, otherwise returns null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CodeOutputPacker

public CodeOutputPacker(byte[] bytes)
Constructor to fill a byte array, for default code width.

Parameters:
bytes - the data array

CodeOutputPacker

public CodeOutputPacker(int nbytes)
Constructor to make and fill a byte array, for default code width.

Parameters:
nbytes - the max expected size of data array

CodeOutputPacker

public CodeOutputPacker(java.io.OutputStream stream)
Constructor to output bytes to a stream, for default code width.

Parameters:
stream - the data stream

CodeOutputPacker

public CodeOutputPacker(byte[] bytes,
                        int N)
Constructor to fill a byte array,

Parameters:
bytes - the data array.
N - the code width in bits, default 12 bits.

CodeOutputPacker

public CodeOutputPacker(int nbytes,
                        int N)
Constructor to make and fill a byte array,

Parameters:
nbytes - the data array size.
N - the code width in bits, default 12 bits.

CodeOutputPacker

public CodeOutputPacker(java.io.OutputStream stream,
                        int N)
Constructor to output bytes to a stream,

Parameters:
stream - the data stream.
N - the code width in bits, default 12 bits
Method Detail

flush

public void flush()
           throws java.io.IOException
Make sure any pending bits are output. No further codes will be added to this output.

Note that for some code widths, packing may result in the appearance of one or more final codes, which actually are empty fill in the final byte. A caller must be able to recognize these by a special value, or otherwise know how many valid codes are expected.

Throws:
java.io.IOException

putNArray

public void putNArray(int[] codes)
               throws java.io.IOException
Put and pack an array of all N bit codes, according to set or default code width.

Note that this call may (but need not) be the only source of data. Either or both putN and putNArray may be called one or more times, followed by a call to flush when no more data will be added.

Parameters:
codes - the array of codes to be packed.
Throws:
java.io.IOException - possible only if based on a stream.

reset

public void reset()
Doing reset () on Packer means fill buffer from the top, the assumption here is that it has been written somewhere.


setWidth

public void setWidth(int width)

getCount

public int getCount()
Return how many bytes of packed data were written, to the array or stream.


toByteArray

public byte[] toByteArray()
Copy to Byte Array sized for actual data contained, valid only if an array was used, otherwise returns null.

Returns:
array sized for actual data contained.

putN

public void putN(int code)
          throws java.io.IOException
Write or accumulate another N bit code

Throws:
java.io.IOException

Xj3D VRML/X3D Code API

Copyright © 2001 - 2005 Web3D Consortium