Class LZWDecoder

  • All Implemented Interfaces:
    Decoder
    Direct Known Subclasses:
    LZWDecoder.LZWCompatibilityDecoder, LZWDecoder.LZWSpecDecoder

    abstract class LZWDecoder
    extends java.lang.Object
    implements Decoder
    Lempel–Ziv–Welch (LZW) decompression. LZW is a universal loss-less data compression algorithm created by Abraham Lempel, Jacob Ziv, and Terry Welch. Inspired by libTiff's LZW decompression.
    Version:
    $Id: LZWDecoder.java,v 1.0 08.05.12 21:11 haraldk Exp$
    See Also:
    LZW (Wikipedia)
    • Field Detail

      • tableLength

        private int tableLength
      • bitsPerCode

        int bitsPerCode
      • oldCode

        private int oldCode
      • maxCode

        private int maxCode
      • bitMask

        int bitMask
      • maxString

        private int maxString
      • eofReached

        boolean eofReached
      • nextData

        int nextData
      • nextBits

        int nextBits
    • Constructor Detail

      • LZWDecoder

        protected LZWDecoder​(int tableSize)
    • Method Detail

      • bitmaskFor

        private static int bitmaskFor​(int bits)
      • init

        private void init()
      • decode

        public int decode​(java.io.InputStream stream,
                          java.nio.ByteBuffer buffer)
                   throws java.io.IOException
        Description copied from interface: Decoder
        Decodes up to buffer.length bytes from the given input stream, into the given buffer.
        Specified by:
        decode in interface Decoder
        Parameters:
        stream - the input stream to decode data from
        buffer - buffer to store the read data
        Returns:
        the total number of bytes read into the buffer, or 0 if there is no more data because the end of the stream has been reached.
        Throws:
        DecodeException - if encoded data is corrupt.
        java.io.IOException - if an I/O error occurs.
        java.io.EOFException - if a premature end-of-file is encountered.
      • addStringToTable

        private void addStringToTable​(LZWDecoder.LZWString string)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • maxCode

        protected abstract int maxCode()
      • isInTable

        private boolean isInTable​(int code)
      • getNextCode

        protected abstract int getNextCode​(java.io.InputStream stream)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • isOldBitReversedStream

        static boolean isOldBitReversedStream​(java.io.InputStream stream)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • create

        public static Decoder create​(boolean oldBitReversedStream)