cz.cuni.jagrlib.piece
Class ZLIBCodec

java.lang.Object
  extended by cz.cuni.jagrlib.DefaultProperty
      extended by cz.cuni.jagrlib.Piece
          extended by cz.cuni.jagrlib.piece.ZLIBCodec
All Implemented Interfaces:
Breakable, EntropyCodec, Property, Template

public class ZLIBCodec
extends Piece
implements EntropyCodec

ZLIB codec. Uses built-in Java ZLIB port from java.util.zip package.

Since:
0.24
See Also:
ZLIBCodec.java

Nested Class Summary
protected  class ZLIBCodec.InStream
          InputStream proxy (for InflaterInputStream).
protected  class ZLIBCodec.OutStream
          OutputStream proxy (for DeflaterOutputStream).
 
Field Summary
protected  int actualCtx
          Id of the actual context.
protected static java.lang.String CATEGORY
          Object category.
static java.lang.String COMPRESSION_LEVEL
           
static java.lang.String COMPRESSION_STRATEGY
           
protected  java.util.zip.InflaterInputStream iCtx
          The actual context (decoder).
protected  ZLIBCodec.InStream iStream
          Actual input stream (for InflaterInputStream link).
protected  int level
          Compression level.
protected  java.util.zip.DeflaterOutputStream oCtx
          The actual context (coder).
protected  ZLIBCodec.OutStream oStream
          Actual output stream (for DeflaterOutputStream link).
protected  boolean output
          Opened for output (encoding)?
protected  long position
          Actual position in original (logical) stream.
protected  long rawBits
          Actual position in compressed (binary) stream.
static RegPiece reg
          Static registration instance for this class.
protected  int strategy
          Deflater compression strategy.
protected  BitStream stream
          Associated I/O stream.
protected static java.lang.String TEMPLATE_NAME
          Object template identifier.
 
Fields inherited from class cz.cuni.jagrlib.Piece
channels, info, pl, plugs, TEMPLATE_TYPE, userBreak
 
Fields inherited from interface cz.cuni.jagrlib.iface.Property
LOGGING, STATISTICS, TEXT_DESCRIPTION
 
Fields inherited from interface cz.cuni.jagrlib.Template
ALL_PLUGS, C_1D, C_2D, C_3D, C_ALPHA, C_BINARY, C_BREP, C_CAMERA, C_CIRCLE, C_CLIP, C_COMPRESSION, C_CURVE, C_DATA, C_DRAW, C_EDITOR, C_ELLIPSE, C_FILL, C_FILTER, C_FLOAT, C_FUNCTION, C_IMAGE, C_INTEGER, C_IO, C_LIGHT, C_LINE, C_METRIC, C_POLYGON, C_PROJECTION, C_RADIOSITY, C_RASTER, C_RENDER, C_SAMPLE, C_SCENE, C_SET, C_SOLID, C_TEXT, C_TRANSFORM, C_VECTOR, C_VIEWER, C_WORKER, CAT_EMPTY, EMPTY, IFACE, JAGRLIB, JAGRLIB2, MANIPULATOR_COMBO, MANIPULATOR_CUSTOM, MANIPULATOR_DEFAULT, MANIPULATOR_MULTILINE, PL_ALPHAMASK, PL_BITMASK, PL_CAUSTIC, PL_CODEC, PL_COLORMAP, PL_COMPARE, PL_DATA, PL_DIRECT, PL_EDITOR, PL_FILTER, PL_FUNCTION, PL_IMAGE, PL_IMPORT, PL_INPUT, PL_INTERSECTION, PL_LIGHTSOURCE, PL_ORDER, PL_OUTPUT, PL_PALETTE, PL_PHOTON, PL_PROPERTY, PL_QUANTIZER, PL_RASTER, PL_RENDER, PL_SHADOW, PL_STREAM, PL_TRANSFORM, PL_TRIGGER, PL_VOLUME, PL_WINDOW, TYPE_BOOLEAN, TYPE_DOUBLE, TYPE_FLOAT, TYPE_INTEGER, TYPE_LONG, TYPE_OBJECT, TYPE_STRING
 
Constructor Summary
ZLIBCodec()
           
 
Method Summary
 boolean available()
          Are they any input symbols (bits) available?
 void close()
          Close the stream..
 long compressed()
          Actual codec compressed position in bits (total amount in all contexts).
 void flush()
          Codec flush.
 int get()
          Get next character from compressed stream.
 java.lang.Object get(java.lang.String key)
          Gets the given property.
 int get(WheelOfFortune wheel)
          Decodes one subinterval from the given WheelOfFortune.
 long getBits(int length)
          Reads the given amount of "raw" bits (by-passes the entropy decoder).
 int getMaxSymbol()
          Retrieves maximal symbol value for the actual context.
 void open(boolean output, int ctx)
          Codec initialization.
 long position()
          Actual codec external position in symbols (total amount in all contexts).
 void put(int symbol)
          Puts the given symbol into the stream.
 void put(WheelOfFortune wheel, int s)
          Encodes one subinterval from the given WheelOfFortune.
 void putBits(long bits, int length)
          Writes the given "raw" bits (by-passes the entropy encoder).
 void set(java.lang.String key, java.lang.Object value)
          Sets the given property.
 int setContext(int ctx)
          Sets the given context as current.
 void setMaxSymbol(int maxSymbol)
          Sets maximal symbol value for the actual context.
static int setTemplate(Template t, int ord)
          General-purpose registration routine.
 
Methods inherited from class cz.cuni.jagrlib.Piece
className, connect, findPlug, findPlug, getInfo, getInterface, getInterface, getPlug, getReg, init, isCompatible, isCompatible, isConnected, logError, logWarning, myInterface, newInputPlug, newOptOutputPlug, newOutputPlug, newPlug, noTemplates, propBegin, propBounds, propDefault, propEnd, propEnum, propManipulator, propManipulator, setProgressListener, setRegStrings, setTemplateDynamic, stop
 
Methods inherited from class cz.cuni.jagrlib.DefaultProperty
booleanProperty, booleanProperty, colorDoubleProperty, colorProperty, commit, doubleProperty, doubleProperty, doubleProperty, enumProperty, floatProperty, floatProperty, floatProperty, intProperty, intProperty, intProperty, longProperty, longProperty, longProperty, set, stringProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cz.cuni.jagrlib.iface.Property
commit
 

Field Detail

stream

protected BitStream stream
Associated I/O stream. null if the codec is not opened.


output

protected boolean output
Opened for output (encoding)?


oStream

protected ZLIBCodec.OutStream oStream
Actual output stream (for DeflaterOutputStream link).


iStream

protected ZLIBCodec.InStream iStream
Actual input stream (for InflaterInputStream link).


actualCtx

protected int actualCtx
Id of the actual context.


oCtx

protected java.util.zip.DeflaterOutputStream oCtx
The actual context (coder).


iCtx

protected java.util.zip.InflaterInputStream iCtx
The actual context (decoder).


level

protected int level
Compression level. Must be between 0 (fastest) and 9 (best compression).

See Also:
Deflater.setLevel(int)

strategy

protected int strategy
Deflater compression strategy.

See Also:
Deflater.setStrategy(int)

position

protected long position
Actual position in original (logical) stream.


rawBits

protected long rawBits
Actual position in compressed (binary) stream.


COMPRESSION_LEVEL

public static final java.lang.String COMPRESSION_LEVEL
See Also:
Constant Field Values

COMPRESSION_STRATEGY

public static final java.lang.String COMPRESSION_STRATEGY
See Also:
Constant Field Values

TEMPLATE_NAME

protected static final java.lang.String TEMPLATE_NAME
Object template identifier.

See Also:
Constant Field Values

CATEGORY

protected static final java.lang.String CATEGORY
Object category.

See Also:
Constant Field Values

reg

public static final RegPiece reg
Static registration instance for this class. Automatically initialized in class-loading time.

Constructor Detail

ZLIBCodec

public ZLIBCodec()
Method Detail

available

public boolean available()
                  throws java.io.IOException
Description copied from interface: EntropyCodec
Are they any input symbols (bits) available?

Specified by:
available in interface EntropyCodec
Returns:
Any symbols (bits) are ready to read.
Throws:
java.io.IOException
See Also:
EntropyCodec.position(), EntropyCodec.compressed()

close

public void close()
           throws java.io.IOException
Close the stream..

Specified by:
close in interface EntropyCodec
Throws:
java.io.IOException
See Also:
EntropyCodec.open(boolean, int), EntropyCodec.flush()

compressed

public long compressed()
                throws java.io.IOException
Description copied from interface: EntropyCodec
Actual codec compressed position in bits (total amount in all contexts).

Specified by:
compressed in interface EntropyCodec
Returns:
Actual codec compressed position in bits.
Throws:
java.io.IOException
See Also:
EntropyCodec.position()

flush

public void flush()
           throws java.io.IOException
Description copied from interface: EntropyCodec
Codec flush.

Specified by:
flush in interface EntropyCodec
Throws:
java.io.IOException
See Also:
EntropyCodec.open(boolean, int), EntropyCodec.close()

get

public int get()
        throws java.io.IOException
Get next character from compressed stream.

Specified by:
get in interface EntropyCodec
Returns:
Read symbol (-1 if no symbol is available).
Throws:
java.io.IOException
See Also:
EntropyCodec.getBits(int), EntropyCodec.put(int), EntropyCodec.available()

get

public int get(WheelOfFortune wheel)
        throws java.io.IOException
Decodes one subinterval from the given WheelOfFortune. Uses the actual context!

Specified by:
get in interface EntropyCodec
Parameters:
wheel - Set of intervals (wheel of fortune).
Returns:
Index of the relevant interval.
Throws:
java.io.IOException

getBits

public long getBits(int length)
             throws java.io.IOException
Description copied from interface: EntropyCodec
Reads the given amount of "raw" bits (by-passes the entropy decoder).

Specified by:
getBits in interface EntropyCodec
Parameters:
length - Number of bits to read.
Returns:
Read bits (or -1 if no bits are available).
Throws:
java.io.IOException
See Also:
EntropyCodec.get(), EntropyCodec.putBits(long, int), EntropyCodec.available()

open

public void open(boolean output,
                 int ctx)
          throws java.io.IOException
Description copied from interface: EntropyCodec
Codec initialization.

Specified by:
open in interface EntropyCodec
Parameters:
output - Open for output?
ctx - Initial context.
Throws:
java.io.IOException
See Also:
BitStream, EntropyCodec.setContext(int)

getMaxSymbol

public int getMaxSymbol()
Retrieves maximal symbol value for the actual context.

Specified by:
getMaxSymbol in interface EntropyCodec
Returns:
Maximal symbol value (255 for ZLIBCodec class).

setMaxSymbol

public void setMaxSymbol(int maxSymbol)
Sets maximal symbol value for the actual context.

Specified by:
setMaxSymbol in interface EntropyCodec
Parameters:
maxSymbol - New maximal symbol value.

position

public long position()
Description copied from interface: EntropyCodec
Actual codec external position in symbols (total amount in all contexts).

Specified by:
position in interface EntropyCodec
Returns:
Actual codec external position in symbols.
See Also:
EntropyCodec.compressed()

put

public void put(int symbol)
         throws java.io.IOException
Puts the given symbol into the stream.

Specified by:
put in interface EntropyCodec
Parameters:
symbol - Symbol to encode.
Throws:
java.io.IOException
See Also:
EntropyCodec.putBits(long, int), EntropyCodec.get()

put

public void put(WheelOfFortune wheel,
                int s)
         throws java.io.IOException
Encodes one subinterval from the given WheelOfFortune. Uses the actual context!

Specified by:
put in interface EntropyCodec
Parameters:
wheel - Set of intervals (wheel of fortune).
s - Index of an interval to encode.
Throws:
java.io.IOException

putBits

public void putBits(long bits,
                    int length)
             throws java.io.IOException
Description copied from interface: EntropyCodec
Writes the given "raw" bits (by-passes the entropy encoder).

Specified by:
putBits in interface EntropyCodec
Parameters:
bits - Bits to be written ("MSB first" order).
length - Number of bits to write.
Throws:
java.io.IOException
See Also:
EntropyCodec.put(int), EntropyCodec.getBits(int)

setContext

public int setContext(int ctx)
               throws java.io.IOException
Description copied from interface: EntropyCodec
Sets the given context as current.

Specified by:
setContext in interface EntropyCodec
Parameters:
ctx - Id of the new context.
Returns:
The old context's id.
Throws:
java.io.IOException

set

public void set(java.lang.String key,
                java.lang.Object value)
Sets the given property.

Specified by:
set in interface Property
Overrides:
set in class DefaultProperty
Parameters:
key - Key string.
value - The new value.
See Also:
Property.commit()

get

public java.lang.Object get(java.lang.String key)
Gets the given property.

Specified by:
get in interface Property
Overrides:
get in class DefaultProperty
Parameters:
key - Key string.
Returns:
The actual value or null.

setTemplate

public static int setTemplate(Template t,
                              int ord)
General-purpose registration routine. Sets all plugs, strings, etc. to the given Template.