Xj3D VRML/X3D Code API

org.web3d.vrml.export.compressors
Class CodeInputUnpacker

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

public class CodeInputUnpacker
extends java.lang.Object

Unpacks N bit codes from source bytes, provided as either an array or stream. N may be more or less than (or equal) to 8 bits, and may be as much as 16 bits, and of course must be what was actually packed.

Since code width N may be greater than 8, unpacked codes are always returned as ints. 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.2 $

Constructor Summary
CodeInputUnpacker(byte[] bytes)
          Constructor from array of packed bytes, for default code width.
CodeInputUnpacker(byte[] bytes, int N)
          Constructor from array of packed bytes.
CodeInputUnpacker(java.io.InputStream stream)
          Constructor from input stream of packed bytes, for default code width.
CodeInputUnpacker(java.io.InputStream stream, int N)
          Constructor from input stream of packed bytes.
 
Method Summary
 boolean atEnd()
          True when no more codes available 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.
 int fillNArray(int[] codearray)
          Fill (or partly fill) a given array with N bit codes, according to set or default code width, which of course must be what was actually packed.
 int getN()
          Get next N bit code, according to set or default code width, which of course must be what was actually packed.
 int[] getNArray(int maxcodes)
          Get array of all N bit codes, according to set or default code width, which of course must be what was actually packed.
 void reset()
          Doing reset () on Unpacker means use buffer from the top, the assumption is that it has different data in it now.
 void setWidth(int width)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CodeInputUnpacker

public CodeInputUnpacker(byte[] bytes)
Constructor from array of packed bytes, for default code width.

Parameters:
bytes - the data array.

CodeInputUnpacker

public CodeInputUnpacker(java.io.InputStream stream)
Constructor from input stream of packed bytes, for default code width.

Parameters:
stream - the data stream.

CodeInputUnpacker

public CodeInputUnpacker(byte[] bytes,
                         int N)
Constructor from array of packed bytes.

Parameters:
bytes - the data array.
N - the expected code width in bits, which of course must be what was actually packed.

CodeInputUnpacker

public CodeInputUnpacker(java.io.InputStream stream,
                         int N)
Constructor from input stream of packed bytes.

Parameters:
stream - the data stream.
N - the expected code width in bits, which of course must be what was actually packed.
Method Detail

setWidth

public void setWidth(int width)

getN

public int getN()
         throws java.io.IOException
Get next N bit code, according to set or default code width, which of course must be what was actually packed.

Since code width N may be greater than 8, unpacked codes are always returned as ints.

Throws:
java.io.IOException - possible only if based on a stream.

getNArray

public int[] getNArray(int maxcodes)
                throws java.io.IOException
Get array of all N bit codes, according to set or default code width, which of course must be what was actually packed.

Since code width N may be greater than 8, unpacked codes are always returned as ints.

Parameters:
maxcodes - maximum number of codes expected. Any codes beyond this length will be discarded!
Returns:
array sized and filled with codes as unpacked.
Throws:
java.io.IOException - possible only if based on a stream.

fillNArray

public int fillNArray(int[] codearray)
               throws java.io.IOException
Fill (or partly fill) a given array with N bit codes, according to set or default code width, which of course must be what was actually packed.

Since code width N may be greater than 8, unpacked codes are always returned as ints.

Parameters:
codearray - array to fill sized for maximum number of codes expected. Any codes beyond this length will be discarded!
Returns:
actual count of codes as unpacked.
Throws:
java.io.IOException - possible only if based on a stream.

reset

public void reset()
Doing reset () on Unpacker means use buffer from the top, the assumption is that it has different data in it now. If the Unpacker was constructed on an input stream, and the stream supports reset, that meaning will be used.


atEnd

public boolean atEnd()
              throws java.io.IOException
True when no more codes available 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 - possible only if based on a stream.

Xj3D VRML/X3D Code API

Copyright © 2001 - 2005 Web3D Consortium