Exemplo n.º 1
0
            /**
             * Method compress given input ByteList to the output ByteList.
             *
             * @param readByteList      Input ByteList
             * @param writeByteList     Output ByteList
             */
            public void compress(ByteList readByteList, ByteList writeByteList) // throws Exception
            {
                writeHeader(writeByteList);
                long binaryCounter = 0;

                this.spaceInLong = 64;
                this.buffer      = 0;
                for (int i = 0; i < readByteList.size(); i++)
                {
                    ByteData currentByte      = this.byteDatas[(int)readByteList.get(i) + 128];
                    long     compressedChar   = currentByte.getCompressedChar();
                    int      compressedLength = currentByte.getCompressedLength();
                    binaryCounter += compressedLength;
                    codeByteToWriteByteList(compressedChar, compressedLength, writeByteList);
                }
                if (this.spaceInLong < 64)
                {
                    for (int k = 7; k >= 0; k--)
                    {
                        long toAsByte = this.buffer;
                        toAsByte >>= 8 * k;
                        writeByteList.add((byte)(toAsByte & 0xFF));
                    }
                }
                long toByte = binaryCounter;

                for (int k = 7; k >= 0; k--)
                {
                    writeByteList.set(k, (byte)(toByte & 0xFF));
                    toByte >>= 8;
                }
            }