Package net.sf.jazzlib
Class StreamManipulator
- java.lang.Object
-
- net.sf.jazzlib.StreamManipulator
-
class StreamManipulator extends java.lang.ObjectThis class allows us to retrieve a specified amount of bits from the input buffer, as well as copy big byte blocks. It uses an int buffer to store up to 31 bits for direct manipulation. This guarantees that we can get at least 16 bits, but we only need at most 15, so this is all safe. There are some optimizations in this class, for example, you must never peek more then 8 bits more than needed, and you must first peek bits before you may drop them. This is not a general purpose class but optimized for the behaviour of the Inflater.
-
-
Field Summary
Fields Modifier and Type Field Description private intbits_in_bufferprivate intbufferprivate byte[]windowprivate intwindow_endprivate intwindow_start
-
Constructor Summary
Constructors Constructor Description StreamManipulator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcopyBytes(byte[] output, int offset, int length)voiddropBits(int n)intgetAvailableBits()Gets the number of bits available in the bit buffer.intgetAvailableBytes()Gets the number of bytes available.intgetBits(int n)Gets the next n bits and increases input pointer.booleanneedsInput()intpeekBits(int n)Get the next n bits but don't increase input pointer.voidreset()voidsetInput(byte[] buf, int off, int len)voidskipToByteBoundary()Skips to the next byte boundary.
-
-
-
Method Detail
-
peekBits
public final int peekBits(int n)
Get the next n bits but don't increase input pointer. n must be less or equal 16 and if you if this call succeeds, you must drop at least n-8 bits in the next call.- Returns:
- the value of the bits, or -1 if not enough bits available.
-
dropBits
public final void dropBits(int n)
-
getBits
public final int getBits(int n)
Gets the next n bits and increases input pointer. This is equivalent to peekBits followed by dropBits, except for correct error handling.- Returns:
- the value of the bits, or -1 if not enough bits available.
-
getAvailableBits
public final int getAvailableBits()
Gets the number of bits available in the bit buffer. This must be only called when a previous peekBits() returned -1.- Returns:
- the number of bits available.
-
getAvailableBytes
public final int getAvailableBytes()
Gets the number of bytes available.- Returns:
- the number of bytes available.
-
skipToByteBoundary
public void skipToByteBoundary()
Skips to the next byte boundary.
-
needsInput
public final boolean needsInput()
-
copyBytes
public int copyBytes(byte[] output, int offset, int length)
-
reset
public void reset()
-
setInput
public void setInput(byte[] buf, int off, int len)
-
-