Class StreamManipulator

java.lang.Object
net.sf.jazzlib.StreamManipulator

class StreamManipulator extends Object
This 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 Details

    • window

      private byte[] window
    • window_start

      private int window_start
    • window_end

      private int window_end
    • buffer

      private int buffer
    • bits_in_buffer

      private int bits_in_buffer
  • Constructor Details

    • StreamManipulator

      public StreamManipulator()
  • Method Details

    • 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)