public byte[] decompress(InputStream is, int expectedLength)
            throws IOException
    {
        int code, oldCode = -1;
        MyBitInputStream mbis = new MyBitInputStream(is, byteOrder);
        if (tiffLZWMode)
            mbis.setTiffLZWMode();

        ByteArrayOutputStream baos = new ByteArrayOutputStream(expectedLength);

        clearTable();

        while ((code = getNextCode(mbis)) != eoiCode)
        {
            if (code == clearCode)
            {
                clearTable();

                if (written >= expectedLength)
                    break;
                code = getNextCode(mbis);

                if (code == eoiCode)
                {
                    break;
                }
                writeToResult(baos, stringFromCode(code));

                oldCode = code;
            } // end of ClearCode case
            else
            {
                if (isInTable(code))
                {
                    writeToResult(baos, stringFromCode(code));

                    addStringToTable(appendBytes(stringFromCode(oldCode),
                            firstChar(stringFromCode(code))));
                    oldCode = code;
                } else
                {
                    byte OutString[] = appendBytes(stringFromCode(oldCode),
                            firstChar(stringFromCode(oldCode)));
                    writeToResult(baos, OutString);
                    addStringToTable(OutString);
                    oldCode = code;
                }
            } // end of not-ClearCode case

            if (written >= expectedLength)
                break;
        } // end of while loop

        byte result[] = baos.toByteArray();

        return result;
    }