Class CodeOutputPacker
java.lang.Object
org.web3d.vrml.export.compressors.CodeOutputPacker
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
ConstructorsConstructorDescriptionCodeOutputPacker
(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
(OutputStream stream) Constructor to output bytes to a stream, for default code width.CodeOutputPacker
(OutputStream stream, int N) Constructor to output bytes to a stream, -
Method Summary
Modifier and TypeMethodDescriptionvoid
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 codevoid
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[]
Copy to Byte Array sized for actual data contained, valid only if an array was used, otherwise returns null.
-
Constructor Details
-
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
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
Constructor to output bytes to a stream,- Parameters:
stream
- the data stream.N
- the code width in bits, default 12 bits
-
-
Method Details
-
flush
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:
IOException
-
putNArray
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:
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.- Returns:
-
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
Write or accumulate another N bit code- Parameters:
code
-- Throws:
IOException
-