Class CodeInputUnpacker
java.lang.Object
org.web3d.vrml.export.compressors.CodeInputUnpacker
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
ConstructorsConstructorDescriptionCodeInputUnpacker
(byte[] bytes) Constructor from array of packed bytes, for default code width.CodeInputUnpacker
(byte[] bytes, int N) Constructor from array of packed bytes.CodeInputUnpacker
(InputStream stream) Constructor from input stream of packed bytes, for default code width.CodeInputUnpacker
(InputStream stream, int N) Constructor from input stream of packed bytes. -
Method Summary
Modifier and TypeMethodDescriptionboolean
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)
-
Constructor Details
-
CodeInputUnpacker
public CodeInputUnpacker(byte[] bytes) Constructor from array of packed bytes, for default code width.- Parameters:
bytes
- the data array.
-
CodeInputUnpacker
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
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 Details
-
setWidth
public void setWidth(int width) -
getN
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.
- Returns:
- Throws:
IOException
- possible only if based on a stream.
-
getNArray
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:
IOException
- possible only if based on a stream.
-
fillNArray
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:
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
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.- Returns:
- Throws:
IOException
- possible only if based on a stream.
-