Output stream that compresses into the BZip2 format : BZIP « File Input Output « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » File Input Output » BZIPScreenshots 
Output stream that compresses into the BZip2 format
   
/*
 * Copyright (C) The Apache Software Foundation. All rights reserved.
 *
 * This software is published under the terms of the Apache Software License
 * version 1.1, a copy of which has been included with this distribution in
 * the LICENSE.txt file.
 */

import java.io.IOException;
import java.io.OutputStream;

/**
 * An output stream that compresses into the BZip2 format (without the file
 * header chars) into another stream. TODO: Update to BZip2 1.0.1
 *
 @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
 */
public class CBZip2OutputStream
    extends OutputStream
    implements BZip2Constants
{
    private static final int LOWER_BYTE_MASK = 0x000000ff;
    private static final int UPPER_BYTE_MASK = 0xffffff00;
    private static final int SETMASK = << 21 );
    private static final int CLEARMASK = ~SETMASK );
    private static final int GREATER_ICOST = 15;
    private static final int LESSER_ICOST = 0;
    private static final int SMALL_THRESH = 20;
    private static final int DEPTH_THRESH = 10;

    /*
     * If you are ever unlucky/improbable enough
     * to get a stack overflow whilst sorting,
     * increase the following constant and try
     * again.  In practice I have never seen the
     * stack go above 27 elems, so the following
     * limit seems very generous.
     */
    private static final int QSORT_STACK_SIZE = 1000;

    private CRC m_crc = new CRC();

    private boolean[] m_inUse = new boolean256 ];

    private char[] m_seqToUnseq = new char256 ];
    private char[] m_unseqToSeq = new char256 ];

    private char[] m_selector = new charMAX_SELECTORS ];
    private char[] m_selectorMtf = new charMAX_SELECTORS ];

    private int[] m_mtfFreq = new intMAX_ALPHA_SIZE ];

    private int m_currentChar = -1;
    private int m_runLength;

    private boolean m_closed;

    /*
     * Knuth's increments seem to work better
     * than Incerpi-Sedgewick here.  Possibly
     * because the number of elems to sort is
     * usually small, typically <= 20.
     */
    private int[] m_incs = new int[]
    {
        14134012136410933280,
        98412952488573265720,
        7971612391484
    };

    private boolean m_blockRandomised;

    /*
     * always: in the range 0 .. 9.
     * The current block size is 100000 * this number.
     */
    private int m_blockSize100k;
    private int m_bsBuff;
    private int m_bsLive;

    /*
     * index of the last char in the block, so
     * the block size == last + 1.
     */
    private int m_last;

    /*
     * index in zptr[] of original string after sorting.
     */
    private int m_origPtr;

    private int m_allowableBlockSize;

    private char[] m_block;

    private int m_blockCRC;
    private int m_combinedCRC;

    private OutputStream m_bsStream;
    private boolean m_firstAttempt;
    private int[] m_ftab;
    private int m_nInUse;

    private int m_nMTF;
    private int[] m_quadrant;
    private short[] m_szptr;
    private int m_workDone;

    /*
     * Used when sorting.  If too many long comparisons
     * happen, we stop sorting, randomise the block
     * slightly, and try again.
     */
    private int m_workFactor;
    private int m_workLimit;
    private int[] m_zptr;

    public CBZip2OutputStreamfinal OutputStream output )
        throws IOException
    {
        thisoutput, );
    }

    public CBZip2OutputStreamfinal OutputStream output, final int blockSize )
        throws IOException
    {
        bsSetStreamoutput );
        m_workFactor = 50;

        int outBlockSize = blockSize;
        ifoutBlockSize > )
        {
            outBlockSize = 9;
        }
        ifoutBlockSize < )
        {
            outBlockSize = 1;
        }
        m_blockSize100k = outBlockSize;
        allocateCompressStructures();
        initialize();
        initBlock();
    }

    private static void hbMakeCodeLengthschar[] len, int[] freq,
                                           int alphaSize, int maxLen )
    {
        /*
         * Nodes and heap entries run from 1.  Entry 0
         * for both the heap and nodes is a sentinel.
         */
        int nNodes;
        /*
         * Nodes and heap entries run from 1.  Entry 0
         * for both the heap and nodes is a sentinel.
         */
        int nHeap;
        /*
         * Nodes and heap entries run from 1.  Entry 0
         * for both the heap and nodes is a sentinel.
         */
        int n1;
        /*
         * Nodes and heap entries run from 1.  Entry 0
         * for both the heap and nodes is a sentinel.
         */
        int n2;
        /*
         * Nodes and heap entries run from 1.  Entry 0
         * for both the heap and nodes is a sentinel.
         */
        int i;
        /*
         * Nodes and heap entries run from 1.  Entry 0
         * for both the heap and nodes is a sentinel.
         */
        int j;
        /*
         * Nodes and heap entries run from 1.  Entry 0
         * for both the heap and nodes is a sentinel.
         */
        int k;
        boolean tooLong;

        int[] heap = new intMAX_ALPHA_SIZE + ];
        int[] weights = new intMAX_ALPHA_SIZE * ];
        int[] parent = new intMAX_ALPHA_SIZE * ];

        fori = 0; i < alphaSize; i++ )
        {
            weightsi + freq== : freq] ) << 8;
        }

        whiletrue )
        {
            nNodes = alphaSize;
            nHeap = 0;

            heap0;
            weights0;
            parent= -2;

            fori = 1; i <= alphaSize; i++ )
            {
                parent= -1;
                nHeap++;
                heapnHeap = i;
                {
                    int zz;
                    int tmp;
                    zz = nHeap;
                    tmp = heapzz ];
                    whileweightstmp < weightsheapzz >> ] ] )
                    {
                        heapzz = heapzz >> ];
                        zz >>= 1;
                    }
                    heapzz = tmp;
                }
            }
            if!nHeap < MAX_ALPHA_SIZE + ) ) )
            {
                panic();
            }

            whilenHeap > )
            {
                n1 = heap];
                heap= heapnHeap ];
                nHeap--;
                {
                    int zz = 0;
                    int yy = 0;
                    int tmp = 0;
                    zz = 1;
                    tmp = heapzz ];
                    whiletrue )
                    {
                        yy = zz << 1;
                        ifyy > nHeap )
                        {
                            break;
                        }
                        ifyy < nHeap &&
                            weightsheapyy + ] ] < weightsheapyy ] ] )
                        {
                            yy++;
                        }
                        ifweightstmp < weightsheapyy ] ] )
                        {
                            break;
                        }
                        heapzz = heapyy ];
                        zz = yy;
                    }
                    heapzz = tmp;
                }
                n2 = heap];
                heap= heapnHeap ];
                nHeap--;
                {
                    int zz = 0;
                    int yy = 0;
                    int tmp = 0;
                    zz = 1;
                    tmp = heapzz ];
                    whiletrue )
                    {
                        yy = zz << 1;
                        ifyy > nHeap )
                        {
                            break;
                        }
                        ifyy < nHeap &&
                            weightsheapyy + ] ] < weightsheapyy ] ] )
                        {
                            yy++;
                        }
                        ifweightstmp < weightsheapyy ] ] )
                        {
                            break;
                        }
                        heapzz = heapyy ];
                        zz = yy;
                    }
                    heapzz = tmp;
                }
                nNodes++;
                parentn1 = nNodes;
                parentn2 = nNodes;

                final int v1 = weightsn1 ];
                final int v2 = weightsn2 ];
                final int weight = calculateWeightv1, v2 );
                weightsnNodes = weight;

                parentnNodes = -1;
                nHeap++;
                heapnHeap = nNodes;
                {
                    int zz = 0;
                    int tmp = 0;
                    zz = nHeap;
                    tmp = heapzz ];
                    whileweightstmp < weightsheapzz >> ] ] )
                    {
                        heapzz = heapzz >> ];
                        zz >>= 1;
                    }
                    heapzz = tmp;
                }
            }
            if!nNodes < MAX_ALPHA_SIZE * ) ) )
            {
                panic();
            }

            tooLong = false;
            fori = 1; i <= alphaSize; i++ )
            {
                j = 0;
                k = i;
                whileparent>= )
                {
                    k = parent];
                    j++;
                }
                leni - (char)j;
                ifj > maxLen )
                {
                    tooLong = true;
                }
            }

            if!tooLong )
            {
                break;
            }

            fori = 1; i < alphaSize; i++ )
            {
                j = weights>> 8;
                j = j / );
                weights= j << 8;
            }
        }
    }

    private static int calculateWeightfinal int v1, final int v2 )
    {
        final int upper = v1 & UPPER_BYTE_MASK v2 & UPPER_BYTE_MASK );
        final int v1Lower = v1 & LOWER_BYTE_MASK );
        final int v2Lower = v2 & LOWER_BYTE_MASK );
        final int nnnn = v1Lower > v2Lower ? v1Lower : v2Lower;
        return upper | + nnnn );
    }

    private static void panic()
    {
        System.out.println"panic" );
        //throw new CError();
    }

    public void close()
        throws IOException
    {
        ifm_closed )
        {
            return;
        }

        ifm_runLength > )
        {
            writeRun();
        }
        m_currentChar = -1;
        endBlock();
        endCompression();
        m_closed = true;
        super.close();
        m_bsStream.close();
    }

    public void finalize()
        throws Throwable
    {
        close();
    }

    public void flush()
        throws IOException
    {
        super.flush();
        m_bsStream.flush();
    }

    /**
     * modified by Oliver Merkel, 010128
     *
     @param bv Description of Parameter
     @exception java.io.IOException Description of Exception
     */
    public void writeint bv )
        throws IOException
    {
        int b = 256 + bv 256;
        ifm_currentChar != -)
        {
            ifm_currentChar == b )
            {
                m_runLength++;
                ifm_runLength > 254 )
                {
                    writeRun();
                    m_currentChar = -1;
                    m_runLength = 0;
                }
            }
            else
            {
                writeRun();
                m_runLength = 1;
                m_currentChar = b;
            }
        }
        else
        {
            m_currentChar = b;
            m_runLength++;
        }
    }

    private void allocateCompressStructures()
    {
        int n = BASE_BLOCK_SIZE * m_blockSize100k;
        m_block = new char[ ( n + + NUM_OVERSHOOT_BYTES ) ];
        m_quadrant = new int[ ( n + NUM_OVERSHOOT_BYTES ) ];
        m_zptr = new int];
        m_ftab = new int65537 ];

        ifm_block == null || m_quadrant == null || m_zptr == null
            || m_ftab == null )
        {
            //int totalDraw = (n + 1 + NUM_OVERSHOOT_BYTES) + (n + NUM_OVERSHOOT_BYTES) + n + 65537;
            //compressOutOfMemory ( totalDraw, n );
        }

        /*
         * The back end needs a place to store the MTF values
         * whilst it calculates the coding tables.  We could
         * put them in the zptr array.  However, these values
         * will fit in a short, so we overlay szptr at the
         * start of zptr, in the hope of reducing the number
         * of cache misses induced by the multiple traversals
         * of the MTF values when calculating coding tables.
         * Seems to improve compression speed by about 1%.
         */
        //    szptr = zptr;

        m_szptr = new short* n ];
    }

    private void bsFinishedWithStream()
        throws IOException
    {
        whilem_bsLive > )
        {
            int ch = m_bsBuff >> 24 );
            try
            {
                m_bsStream.writech );// write 8-bit
            }
            catchIOException e )
            {
                throw e;
            }
            m_bsBuff <<= 8;
            m_bsLive -= 8;
        }
    }

    private void bsPutIntVSint numBits, int )
        throws IOException
    {
        bsWnumBits, c );
    }

    private void bsPutUCharint )
        throws IOException
    {
        bsW8, c );
    }

    private void bsPutintint )
        throws IOException
    {
        bsW8u >> 24 0xff );
        bsW8u >> 16 0xff );
        bsW8u >> 0xff );
        bsW8, u & 0xff );
    }

    private void bsSetStreamOutputStream f )
    {
        m_bsStream = f;
        m_bsLive = 0;
        m_bsBuff = 0;
    }

    private void bsWint n, int )
        throws IOException
    {
        whilem_bsLive >= )
        {
            int ch = m_bsBuff >> 24 );
            try
            {
                m_bsStream.writech );// write 8-bit
            }
            catchIOException e )
            {
                throw e;
            }
            m_bsBuff <<= 8;
            m_bsLive -= 8;
        }
        m_bsBuff |= v << 32 - m_bsLive - n ) );
        m_bsLive += n;
    }

    private void doReversibleTransformation()
    {
        int i;

        m_workLimit = m_workFactor * m_last;
        m_workDone = 0;
        m_blockRandomised = false;
        m_firstAttempt = true;

        mainSort();

        ifm_workDone > m_workLimit && m_firstAttempt )
        {
            randomiseBlock();
            m_workLimit = 0;
            m_workDone = 0;
            m_blockRandomised = true;
            m_firstAttempt = false;
            mainSort();
        }

        m_origPtr = -1;
        fori = 0; i <= m_last; i++ )
        {
            ifm_zptr== )
            {
                m_origPtr = i;
                break;
            }
        }
        ;

        ifm_origPtr == -)
        {
            panic();
        }
    }

    private void endBlock()
        throws IOException
    {
        m_blockCRC = m_crc.getFinalCRC();
        m_combinedCRC = m_combinedCRC << m_combinedCRC >>> 31 );
        m_combinedCRC ^= m_blockCRC;

        /*
         * sort the block and establish posn of original string
         */
        doReversibleTransformation();

        /*
         * A 6-byte block header, the value chosen arbitrarily
         * as 0x314159265359 :-).  A 32 bit value does not really
         * give a strong enough guarantee that the value will not
         * appear by chance in the compressed datastream.  Worst-case
         * probability of this event, for a 900k block, is about
         * 2.0e-3 for 32 bits, 1.0e-5 for 40 bits and 4.0e-8 for 48 bits.
         * For a compressed file of size 100Gb -- about 100000 blocks --
         * only a 48-bit marker will do.  NB: normal compression/
         * decompression do *not* rely on these statistical properties.
         * They are only important when trying to recover blocks from
         * damaged files.
         */
        bsPutUChar0x31 );
        bsPutUChar0x41 );
        bsPutUChar0x59 );
        bsPutUChar0x26 );
        bsPutUChar0x53 );
        bsPutUChar0x59 );

        /*
         * Now the block's CRC, so it is in a known place.
         */
        bsPutintm_blockCRC );

        /*
         * Now a single bit indicating randomisation.
         */
        ifm_blockRandomised )
        {
            bsW1);
        }
        else
        {
            bsW1);
        }

        /*
         * Finally, block's contents proper.
         */
        moveToFrontCodeAndSend();
    }

    private void endCompression()
        throws IOException
    {
        /*
         * Now another magic 48-bit number, 0x177245385090, to
         * indicate the end of the last block.  (sqrt(pi), if
         * you want to know.  I did want to use e, but it contains
         * too much repetition -- 27 18 28 18 28 46 -- for me
         * to feel statistically comfortable.  Call me paranoid.)
         */
        bsPutUChar0x17 );
        bsPutUChar0x72 );
        bsPutUChar0x45 );
        bsPutUChar0x38 );
        bsPutUChar0x50 );
        bsPutUChar0x90 );

        bsPutintm_combinedCRC );

        bsFinishedWithStream();
    }

    private boolean fullGtUint i1, int i2 )
    {
        int k;
        char c1;
        char c2;
        int s1;
        int s2;

        c1 = m_blocki1 + ];
        c2 = m_blocki2 + ];
        ifc1 != c2 )
        {
            return c1 > c2 );
        }
        i1++;
        i2++;

        c1 = m_blocki1 + ];
        c2 = m_blocki2 + ];
        ifc1 != c2 )
        {
            return c1 > c2 );
        }
        i1++;
        i2++;

        c1 = m_blocki1 + ];
        c2 = m_blocki2 + ];
        ifc1 != c2 )
        {
            return c1 > c2 );
        }
        i1++;
        i2++;

        c1 = m_blocki1 + ];
        c2 = m_blocki2 + ];
        ifc1 != c2 )
        {
            return c1 > c2 );
        }
        i1++;
        i2++;

        c1 = m_blocki1 + ];
        c2 = m_blocki2 + ];
        ifc1 != c2 )
        {
            return c1 > c2 );
        }
        i1++;
        i2++;

        c1 = m_blocki1 + ];
        c2 = m_blocki2 + ];
        ifc1 != c2 )
        {
            return c1 > c2 );
        }
        i1++;
        i2++;

        k = m_last + 1;

        do
        {
            c1 = m_blocki1 + ];
            c2 = m_blocki2 + ];
            ifc1 != c2 )
            {
                return c1 > c2 );
            }
            s1 = m_quadranti1 ];
            s2 = m_quadranti2 ];
            ifs1 != s2 )
            {
                return s1 > s2 );
            }
            i1++;
            i2++;

            c1 = m_blocki1 + ];
            c2 = m_blocki2 + ];
            ifc1 != c2 )
            {
                return c1 > c2 );
            }
            s1 = m_quadranti1 ];
            s2 = m_quadranti2 ];
            ifs1 != s2 )
            {
                return s1 > s2 );
            }
            i1++;
            i2++;

            c1 = m_blocki1 + ];
            c2 = m_blocki2 + ];
            ifc1 != c2 )
            {
                return c1 > c2 );
            }
            s1 = m_quadranti1 ];
            s2 = m_quadranti2 ];
            ifs1 != s2 )
            {
                return s1 > s2 );
            }
            i1++;
            i2++;

            c1 = m_blocki1 + ];
            c2 = m_blocki2 + ];
            ifc1 != c2 )
            {
                return c1 > c2 );
            }
            s1 = m_quadranti1 ];
            s2 = m_quadranti2 ];
            ifs1 != s2 )
            {
                return s1 > s2 );
            }
            i1++;
            i2++;

            ifi1 > m_last )
            {
                i1 -= m_last;
                i1--;
            }
            ;
            ifi2 > m_last )
            {
                i2 -= m_last;
                i2--;
            }
            ;

            k -= 4;
            m_workDone++;
        whilek >= );

        return false;
    }

    private void generateMTFValues()
    {
        char[] yy = new char256 ];
        int i;
        int j;
        char tmp;
        char tmp2;
        int zPend;
        int wr;
        int EOB;

        makeMaps();
        EOB = m_nInUse + 1;

        fori = 0; i <= EOB; i++ )
        {
            m_mtfFreq0;
        }

        wr = 0;
        zPend = 0;
        fori = 0; i < m_nInUse; i++ )
        {
            yy(char)i;
        }

        fori = 0; i <= m_last; i++ )
        {
            char ll_i;

            ll_i = m_unseqToSeqm_blockm_zptr] ] ];

            j = 0;
            tmp = yy];
            whilell_i != tmp )
            {
                j++;
                tmp2 = tmp;
                tmp = yy];
                yy= tmp2;
            }
            ;
            yy= tmp;

            ifj == )
            {
                zPend++;
            }
            else
            {
                ifzPend > )
                {
                    zPend--;
                    whiletrue )
                    {
                        switchzPend % )
                        {
                            case 0:
                                m_szptrwr (short)RUNA;
                                wr++;
                                m_mtfFreqRUNA ]++;
                                break;
                            case 1:
                                m_szptrwr (short)RUNB;
                                wr++;
                                m_mtfFreqRUNB ]++;
                                break;
                        }
                        ;
                        ifzPend < )
                        {
                            break;
                        }
                        zPend = zPend - 2;
                    }
                    ;
                    zPend = 0;
                }
                m_szptrwr (short)( j + );
                wr++;
                m_mtfFreqj + ]++;
            }
        }

        ifzPend > )
        {
            zPend--;
            whiletrue )
            {
                switchzPend % )
                {
                    case 0:
                        m_szptrwr (short)RUNA;
                        wr++;
                        m_mtfFreqRUNA ]++;
                        break;
                    case 1:
                        m_szptrwr (short)RUNB;
                        wr++;
                        m_mtfFreqRUNB ]++;
                        break;
                }
                ifzPend < )
                {
                    break;
                }
                zPend = zPend - 2;
            }
        }

        m_szptrwr (short)EOB;
        wr++;
        m_mtfFreqEOB ]++;

        m_nMTF = wr;
    }

    private void hbAssignCodesint[] code, char[] length, int minLen,
                                int maxLen, int alphaSize )
    {
        int n;
        int vec;
        int i;

        vec = 0;
        forn = minLen; n <= maxLen; n++ )
        {
            fori = 0; i < alphaSize; i++ )
            {
                iflength== n )
                {
                    code= vec;
                    vec++;
                }
            }
            ;
            vec <<= 1;
        }
    }

    private void initBlock()
    {
        //        blockNo++;
        m_crc.initialiseCRC();
        m_last = -1;
        //        ch = 0;

        forint i = 0; i < 256; i++ )
        {
            m_inUsefalse;
        }

        /*
         * 20 is just a paranoia constant
         */
        m_allowableBlockSize = BASE_BLOCK_SIZE * m_blockSize100k - 20;
    }

    private void initialize()
        throws IOException
    {
        /*
         * Write `magic' bytes h indicating file-format == huffmanised,
         * followed by a digit indicating blockSize100k.
         */
        bsPutUChar'h' );
        bsPutUChar'0' + m_blockSize100k );

        m_combinedCRC = 0;
    }

    private void mainSort()
    {
        int i;
        int j;
        int ss;
        int sb;
        int[] runningOrder = new int256 ];
        int[] copy = new int256 ];
        boolean[] bigDone = new boolean256 ];
        int c1;
        int c2;

        /*
         * In the various block-sized structures, live data runs
         * from 0 to last+NUM_OVERSHOOT_BYTES inclusive.  First,
         * set up the overshoot area for block.
         */
        //   if (verbosity >= 4) fprintf ( stderr, "        sort initialise ...\n" );
        fori = 0; i < NUM_OVERSHOOT_BYTES; i++ )
        {
            m_blockm_last + i + = m_block[ ( i % m_last + ) ) ];
        }
        fori = 0; i <= m_last + NUM_OVERSHOOT_BYTES; i++ )
        {
            m_quadrant0;
        }

        m_block= m_blockm_last + ];

        ifm_last < 4000 )
        {
            /*
             * Use simpleSort(), since the full sorting mechanism
             * has quite a large constant overhead.
             */
            fori = 0; i <= m_last; i++ )
            {
                m_zptr= i;
            }
            m_firstAttempt = false;
            m_workDone = 0;
            m_workLimit = 0;
            simpleSort0, m_last, );
        }
        else
        {
            fori = 0; i <= 255; i++ )
            {
                bigDonefalse;
            }

            fori = 0; i <= 65536; i++ )
            {
                m_ftab0;
            }

            c1 = m_block];
            fori = 0; i <= m_last; i++ )
            {
                c2 = m_blocki + ];
                m_ftab[ ( c1 << + c2 ]++;
                c1 = c2;
            }

            fori = 1; i <= 65536; i++ )
            {
                m_ftab+= m_ftabi - ];
            }

            c1 = m_block];
            fori = 0; i < m_last; i++ )
            {
                c2 = m_blocki + ];
                j = c1 << + c2;
                c1 = c2;
                m_ftab]--;
                m_zptrm_ftab] ] = i;
            }

            j = ( ( m_blockm_last + ] ) << m_block] );
            m_ftab]--;
            m_zptrm_ftab] ] = m_last;

            /*
             * Now ftab contains the first loc of every small bucket.
             * Calculate the running order, from smallest to largest
             * big bucket.
             */
            fori = 0; i <= 255; i++ )
            {
                runningOrder= i;
            }
            {
                int vv;
                int h = 1;
                do
                {
                    h = * h + 1;
                whileh <= 256 );
                do
                {
                    h = h / 3;
                    fori = h; i <= 255; i++ )
                    {
                        vv = runningOrder];
                        j = i;
                        while( ( m_ftab[ ( ( runningOrderj - h ] ) << ]
                            - m_ftab[ ( runningOrderj - h ] ) << ] ) >
                            m_ftab[ ( ( vv << - m_ftab[ ( vv << ] ) )
                        {
                            runningOrder= runningOrderj - h ];
                            j = j - h;
                            ifj <= h - ) )
                            {
                                break;
                            }
                        }
                        runningOrder= vv;
                    }
                whileh != );
            }

            /*
             * The main sorting loop.
             */
            fori = 0; i <= 255; i++ )
            {

                /*
                 * Process big buckets, starting with the least full.
                 */
                ss = runningOrder];

                /*
                 * Complete the big bucket [ss] by quicksorting
                 * any unsorted small buckets [ss, j].  Hopefully
                 * previous pointer-scanning phases have already
                 * completed many of the small buckets [ss, j], so
                 * we don't have to sort them at all.
                 */
                forj = 0; j <= 255; j++ )
                {
                    sb = ss << + j;
                    if!( ( m_ftabsb & SETMASK == SETMASK ) )
                    {
                        int lo = m_ftabsb & CLEARMASK;
                        int hi = m_ftabsb + & CLEARMASK 1;
                        ifhi > lo )
                        {
                            qSort3lo, hi, );
                            ifm_workDone > m_workLimit && m_firstAttempt )
                            {
                                return;
                            }
                        }
                        m_ftabsb |= SETMASK;
                    }
                }

                /*
                 * The ss big bucket is now done.  Record this fact,
                 * and update the quadrant descriptors.  Remember to
                 * update quadrants in the overshoot area too, if
                 * necessary.  The "if (i < 255)" test merely skips
                 * this updating for the last bucket processed, since
                 * updating for the last bucket is pointless.
                 */
                bigDoness true;

                ifi < 255 )
                {
                    int bbStart = m_ftabss << & CLEARMASK;
                    int bbSize = m_ftab[ ( ss + << & CLEARMASK - bbStart;
                    int shifts = 0;

                    while( ( bbSize >> shifts 65534 )
                    {
                        shifts++;
                    }

                    forj = 0; j < bbSize; j++ )
                    {
                        int a2update = m_zptrbbStart + j ];
                        int qVal = j >> shifts );
                        m_quadranta2update = qVal;
                        ifa2update < NUM_OVERSHOOT_BYTES )
                        {
                            m_quadranta2update + m_last + = qVal;
                        }
                    }

                    if!( ( ( bbSize - >> shifts <= 65535 ) )
                    {
                        panic();
                    }
                }

                /*
                 * Now scan this big bucket so as to synthesise the
                 * sorted order for small buckets [t, ss] for all t != ss.
                 */
                forj = 0; j <= 255; j++ )
                {
                    copy= m_ftab[ ( j << + ss & CLEARMASK;
                }

                forj = m_ftabss << & CLEARMASK;
                     j < m_ftab[ ( ss + << & CLEARMASK ); j++ )
                {
                    c1 = m_blockm_zptr] ];
                    if!bigDonec1 ] )
                    {
                        m_zptrcopyc1 ] ] = m_zptr== ? m_last : m_zptr1;
                        copyc1 ]++;
                    }
                }

                forj = 0; j <= 255; j++ )
                {
                    m_ftab[ ( j << + ss |= SETMASK;
                }
            }
        }
    }

    private void makeMaps()
    {
        int i;
        m_nInUse = 0;
        fori = 0; i < 256; i++ )
        {
            ifm_inUse] )
            {
                m_seqToUnseqm_nInUse (char)i;
                m_unseqToSeq(char)m_nInUse;
                m_nInUse++;
            }
        }
    }

    private char med3char a, char b, char )
    {
        char t;
        ifa > b )
        {
            t = a;
            a = b;
            b = t;
        }
        ifb > c )
        {
            t = b;
            b = c;
            c = t;
        }
        ifa > b )
        {
            b = a;
        }
        return b;
    }

    private void moveToFrontCodeAndSend()
        throws IOException
    {
        bsPutIntVS24, m_origPtr );
        generateMTFValues();
        sendMTFValues();
    }

    private void qSort3int loSt, int hiSt, int dSt )
    {
        int unLo;
        int unHi;
        int ltLo;
        int gtHi;
        int med;
        int n;
        int m;
        int sp;
        int lo;
        int hi;
        int d;
        StackElem[] stack = new StackElemQSORT_STACK_SIZE ];
        forint count = 0; count < QSORT_STACK_SIZE; count++ )
        {
            stackcount new StackElem();
        }

        sp = 0;

        stacksp ].m_ll = loSt;
        stacksp ].m_hh = hiSt;
        stacksp ].m_dd = dSt;
        sp++;

        whilesp > )
        {
            ifsp >= QSORT_STACK_SIZE )
            {
                panic();
            }

            sp--;
            lo = stacksp ].m_ll;
            hi = stacksp ].m_hh;
            d = stacksp ].m_dd;

            ifhi - lo < SMALL_THRESH || d > DEPTH_THRESH )
            {
                simpleSortlo, hi, d );
                ifm_workDone > m_workLimit && m_firstAttempt )
                {
                    return;
                }
                continue;
            }

            med = med3m_blockm_zptrlo + d + ],
                        m_blockm_zptrhi + d + ],
                        m_blockm_zptr[ ( lo + hi >> + d + ] );

            unLo = lo;
            ltLo = lo;
            unHi = hi;
            gtHi = hi;

            whiletrue )
            {
                whiletrue )
                {
                    ifunLo > unHi )
                    {
                        break;
                    }
                    n = m_blockm_zptrunLo + d + - med;
                    ifn == )
                    {
                        int temp = 0;
                        temp = m_zptrunLo ];
                        m_zptrunLo = m_zptrltLo ];
                        m_zptrltLo = temp;
                        ltLo++;
                        unLo++;
                        continue;
                    }
                    ;
                    ifn > )
                    {
                        break;
                    }
                    unLo++;
                }
                whiletrue )
                {
                    ifunLo > unHi )
                    {
                        break;
                    }
                    n = m_blockm_zptrunHi + d + - med;
                    ifn == )
                    {
                        int temp = 0;
                        temp = m_zptrunHi ];
                        m_zptrunHi = m_zptrgtHi ];
                        m_zptrgtHi = temp;
                        gtHi--;
                        unHi--;
                        continue;
                    }
                    ;
                    ifn < )
                    {
                        break;
                    }
                    unHi--;
                }
                ifunLo > unHi )
                {
                    break;
                }
                int temp = 0;
                temp = m_zptrunLo ];
                m_zptrunLo = m_zptrunHi ];
                m_zptrunHi = temp;
                unLo++;
                unHi--;
            }

            ifgtHi < ltLo )
            {
                stacksp ].m_ll = lo;
                stacksp ].m_hh = hi;
                stacksp ].m_dd = d + 1;
                sp++;
                continue;
            }

            n = ( ( ltLo - lo unLo - ltLo ) ) ltLo - lo unLo - ltLo );
            vswaplo, unLo - n, n );
            m = ( ( hi - gtHi gtHi - unHi ) ) hi - gtHi gtHi - unHi );
            vswapunLo, hi - m + 1, m );

            n = lo + unLo - ltLo - 1;
            m = hi - gtHi - unHi 1;

            stacksp ].m_ll = lo;
            stacksp ].m_hh = n;
            stacksp ].m_dd = d;
            sp++;

            stacksp ].m_ll = n + 1;
            stacksp ].m_hh = m - 1;
            stacksp ].m_dd = d + 1;
            sp++;

            stacksp ].m_ll = m;
            stacksp ].m_hh = hi;
            stacksp ].m_dd = d;
            sp++;
        }
    }

    private void randomiseBlock()
    {
        int i;
        int rNToGo = 0;
        int rTPos = 0;
        fori = 0; i < 256; i++ )
        {
            m_inUsefalse;
        }

        fori = 0; i <= m_last; i++ )
        {
            ifrNToGo == )
            {
                rNToGo = (char)RAND_NUMSrTPos ];
                rTPos++;
                ifrTPos == 512 )
                {
                    rTPos = 0;
                }
            }
            rNToGo--;
            m_blocki + ^= ( ( rNToGo == );
            // handle 16 bit signed numbers
            m_blocki + &= 0xFF;

            m_inUsem_blocki + ] ] true;
        }
    }

    private void sendMTFValues()
        throws IOException
    {
        char[][] len = new charN_GROUPS ][ MAX_ALPHA_SIZE ];

        int v;

        int t;

        int i;

        int j;

        int gs;

        int ge;

        int bt;

        int bc;

        int iter;
        int nSelectors = 0;
        int alphaSize;
        int minLen;
        int maxLen;
        int selCtr;
        int nGroups;

        alphaSize = m_nInUse + 2;
        fort = 0; t < N_GROUPS; t++ )
        {
            forv = 0; v < alphaSize; v++ )
            {
                len][ (char)GREATER_ICOST;
            }
        }

        /*
         * Decide how many coding tables to use
         */
        ifm_nMTF <= )
        {
            panic();
        }

        ifm_nMTF < 200 )
        {
            nGroups = 2;
        }
        else ifm_nMTF < 600 )
        {
            nGroups = 3;
        }
        else ifm_nMTF < 1200 )
        {
            nGroups = 4;
        }
        else ifm_nMTF < 2400 )
        {
            nGroups = 5;
        }
        else
        {
            nGroups = 6;
        }
        {
            /*
             * Generate an initial set of coding tables
             */
            int nPart;
            int remF;
            int tFreq;
            int aFreq;

            nPart = nGroups;
            remF = m_nMTF;
            gs = 0;
            whilenPart > )
            {
                tFreq = remF / nPart;
                ge = gs - 1;
                aFreq = 0;
                whileaFreq < tFreq && ge < alphaSize - )
                {
                    ge++;
                    aFreq += m_mtfFreqge ];
                }

                ifge > gs && nPart != nGroups && nPart != 1
                    && ( ( nGroups - nPart == ) )
                {
                    aFreq -= m_mtfFreqge ];
                    ge--;
                }

                forv = 0; v < alphaSize; v++ )
                {
                    ifv >= gs && v <= ge )
                    {
                        lennPart - ][ (char)LESSER_ICOST;
                    }
                    else
                    {
                        lennPart - ][ (char)GREATER_ICOST;
                    }
                }

                nPart--;
                gs = ge + 1;
                remF -= aFreq;
            }
        }

        int[][] rfreq = new intN_GROUPS ][ MAX_ALPHA_SIZE ];
        int[] fave = new intN_GROUPS ];
        short[] cost = new shortN_GROUPS ];
        /*
         * Iterate up to N_ITERS times to improve the tables.
         */
        foriter = 0; iter < N_ITERS; iter++ )
        {
            fort = 0; t < nGroups; t++ )
            {
                fave0;
            }

            fort = 0; t < nGroups; t++ )
            {
                forv = 0; v < alphaSize; v++ )
                {
                    rfreq][ 0;
                }
            }

            nSelectors = 0;
            gs = 0;
            whiletrue )
            {

                /*
                 * Set group start & end marks.
                 */
                ifgs >= m_nMTF )
                {
                    break;
                }
                ge = gs + G_SIZE - 1;
                ifge >= m_nMTF )
                {
                    ge = m_nMTF - 1;
                }

                /*
                 * Calculate the cost of this group as coded
                 * by each of the coding tables.
                 */
                fort = 0; t < nGroups; t++ )
                {
                    cost0;
                }

                ifnGroups == )
                {
                    short cost0 = 0;
                    short cost1 = 0;
                    short cost2 = 0;
                    short cost3 = 0;
                    short cost4 = 0;
                    short cost5 = 0;

                    fori = gs; i <= ge; i++ )
                    {
                        short icv = m_szptr];
                        cost0 += len][ icv ];
                        cost1 += len][ icv ];
                        cost2 += len][ icv ];
                        cost3 += len][ icv ];
                        cost4 += len][ icv ];
                        cost5 += len][ icv ];
                    }
                    cost= cost0;
                    cost= cost1;
                    cost= cost2;
                    cost= cost3;
                    cost= cost4;
                    cost= cost5;
                }
                else
                {
                    fori = gs; i <= ge; i++ )
                    {
                        short icv = m_szptr];
                        fort = 0; t < nGroups; t++ )
                        {
                            cost+= len][ icv ];
                        }
                    }
                }

                /*
                 * Find the coding table which is best for this group,
                 * and record its identity in the selector table.
                 */
                bc = 999999999;
                bt = -1;
                fort = 0; t < nGroups; t++ )
                {
                    ifcost< bc )
                    {
                        bc = cost];
                        bt = t;
                    }
                }
                ;
                favebt ]++;
                m_selectornSelectors (char)bt;
                nSelectors++;

                /*
                 * Increment the symbol frequencies for the selected table.
                 */
                fori = gs; i <= ge; i++ )
                {
                    rfreqbt ][ m_szptr] ]++;
                }

                gs = ge + 1;
            }

            /*
             * Recompute the tables based on the accumulated frequencies.
             */
            fort = 0; t < nGroups; t++ )
            {
                hbMakeCodeLengthslen], rfreq], alphaSize, 20 );
            }
        }

        rfreq = null;
        fave = null;
        cost = null;

        if!nGroups < ) )
        {
            panic();
        }
        if!nSelectors < 32768 && nSelectors <= 900000 / G_SIZE ) ) ) )
        {
            panic();
        }
        {
            /*
             * Compute MTF values for the selectors.
             */
            char[] pos = new charN_GROUPS ];
            char ll_i;
            char tmp2;
            char tmp;
            fori = 0; i < nGroups; i++ )
            {
                pos(char)i;
            }
            fori = 0; i < nSelectors; i++ )
            {
                ll_i = m_selector];
                j = 0;
                tmp = pos];
                whilell_i != tmp )
                {
                    j++;
                    tmp2 = tmp;
                    tmp = pos];
                    pos= tmp2;
                }
                pos= tmp;
                m_selectorMtf(char)j;
            }
        }

        int[][] code = new intN_GROUPS ][ MAX_ALPHA_SIZE ];

        /*
         * Assign actual codes for the tables.
         */
        fort = 0; t < nGroups; t++ )
        {
            minLen = 32;
            maxLen = 0;
            fori = 0; i < alphaSize; i++ )
            {
                iflen][ > maxLen )
                {
                    maxLen = len][ ];
                }
                iflen][ < minLen )
                {
                    minLen = len][ ];
                }
            }
            ifmaxLen > 20 )
            {
                panic();
            }
            ifminLen < )
            {
                panic();
            }
            hbAssignCodescode], len], minLen, maxLen, alphaSize );
        }
        {
            /*
             * Transmit the mapping table.
             */
            boolean[] inUse16 = new boolean16 ];
            fori = 0; i < 16; i++ )
            {
                inUse16false;
                forj = 0; j < 16; j++ )
                {
                    ifm_inUsei * 16 + j ] )
                    {
                        inUse16true;
                    }
                }
            }

            fori = 0; i < 16; i++ )
            {
                ifinUse16] )
                {
                    bsW1);
                }
                else
                {
                    bsW1);
                }
            }

            fori = 0; i < 16; i++ )
            {
                ifinUse16] )
                {
                    forj = 0; j < 16; j++ )
                    {
                        ifm_inUsei * 16 + j ] )
                        {
                            bsW1);
                        }
                        else
                        {
                            bsW1);
                        }
                    }
                }
            }

        }

        /*
         * Now the selectors.
         */
        bsW3, nGroups );
        bsW15, nSelectors );
        fori = 0; i < nSelectors; i++ )
        {
            forj = 0; j < m_selectorMtf]; j++ )
            {
                bsW1);
            }
            bsW1);
        }

        fort = 0; t < nGroups; t++ )
        {
            int curr = len][ ];
            bsW5, curr );
            fori = 0; i < alphaSize; i++ )
            {
                whilecurr < len][ ] )
                {
                    bsW2);
                    curr++;
                    /*
                     * 10
                     */
                }
                whilecurr > len][ ] )
                {
                    bsW2);
                    curr--;
                    /*
                     * 11
                     */
                }
                bsW1);
            }
        }

        /*
         * And finally, the block data proper
         */
        selCtr = 0;
        gs = 0;
        whiletrue )
        {
            ifgs >= m_nMTF )
            {
                break;
            }
            ge = gs + G_SIZE - 1;
            ifge >= m_nMTF )
            {
                ge = m_nMTF - 1;
            }
            fori = gs; i <= ge; i++ )
            {
                bsWlenm_selectorselCtr ] ][ m_szptr] ],
                     codem_selectorselCtr ] ][ m_szptr] ] );
            }

            gs = ge + 1;
            selCtr++;
        }
        if!selCtr == nSelectors ) )
        {
            panic();
        }
    }

    private void simpleSortint lo, int hi, int )
    {
        int i;
        int j;
        int h;
        int bigN;
        int hp;
        int v;

        bigN = hi - lo + 1;
        ifbigN < )
        {
            return;
        }

        hp = 0;
        whilem_incshp < bigN )
        {
            hp++;
        }
        hp--;

        for; hp >= 0; hp-- )
        {
            h = m_incshp ];

            i = lo + h;
            whiletrue )
            {
                /*
                 * copy 1
                 */
                ifi > hi )
                {
                    break;
                }
                v = m_zptr];
                j = i;
                whilefullGtUm_zptrj - h + d, v + d ) )
                {
                    m_zptr= m_zptrj - h ];
                    j = j - h;
                    ifj <= lo + h - ) )
                    {
                        break;
                    }
                }
                m_zptr= v;
                i++;

                /*
                 * copy 2
                 */
                ifi > hi )
                {
                    break;
                }
                v = m_zptr];
                j = i;
                whilefullGtUm_zptrj - h + d, v + d ) )
                {
                    m_zptr= m_zptrj - h ];
                    j = j - h;
                    ifj <= lo + h - ) )
                    {
                        break;
                    }
                }
                m_zptr= v;
                i++;

                /*
                 * copy 3
                 */
                ifi > hi )
                {
                    break;
                }
                v = m_zptr];
                j = i;
                whilefullGtUm_zptrj - h + d, v + d ) )
                {
                    m_zptr= m_zptrj - h ];
                    j = j - h;
                    ifj <= lo + h - ) )
                    {
                        break;
                    }
                }
                m_zptr= v;
                i++;

                ifm_workDone > m_workLimit && m_firstAttempt )
                {
                    return;
                }
            }
        }
    }

    private void vswapint p1, int p2, int )
    {
        int temp = 0;
        whilen > )
        {
            temp = m_zptrp1 ];
            m_zptrp1 = m_zptrp2 ];
            m_zptrp2 = temp;
            p1++;
            p2++;
            n--;
        }
    }

    private void writeRun()
        throws IOException
    {
        ifm_last < m_allowableBlockSize )
        {
            m_inUsem_currentChar true;
            forint i = 0; i < m_runLength; i++ )
            {
                m_crc.updateCRC( (char)m_currentChar );
            }
            switchm_runLength )
            {
                case 1:
                    m_last++;
                    m_blockm_last + (char)m_currentChar;
                    break;
                case 2:
                    m_last++;
                    m_blockm_last + (char)m_currentChar;
                    m_last++;
                    m_blockm_last + (char)m_currentChar;
                    break;
                case 3:
                    m_last++;
                    m_blockm_last + (char)m_currentChar;
                    m_last++;
                    m_blockm_last + (char)m_currentChar;
                    m_last++;
                    m_blockm_last + (char)m_currentChar;
                    break;
                default:
                    m_inUsem_runLength - true;
                    m_last++;
                    m_blockm_last + (char)m_currentChar;
                    m_last++;
                    m_blockm_last + (char)m_currentChar;
                    m_last++;
                    m_blockm_last + (char)m_currentChar;
                    m_last++;
                    m_blockm_last + (char)m_currentChar;
                    m_last++;
                    m_blockm_last + (char)( m_runLength - );
                    break;
            }
        }
        else
        {
            endBlock();
            initBlock();
            writeRun();
        }
    }

    private static class StackElem
    {
        int m_dd;
        int m_hh;
        int m_ll;
    }
}


/*
 * Copyright (C) The Apache Software Foundation. All rights reserved.
 *
 * This software is published under the terms of the Apache Software License
 * version 1.1, a copy of which has been included with this distribution in
 * the LICENSE.txt file.
 */

/**
 * Base class for both the compress and decompress classes. Holds common arrays,
 * and static data.
 *
 @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
 */
interface BZip2Constants
{
    int BASE_BLOCK_SIZE = 100000;
    int MAX_ALPHA_SIZE = 258;
    int MAX_CODE_LEN = 23;
    int RUNA = 0;
    int RUNB = 1;
    int N_GROUPS = 6;
    int G_SIZE = 50;
    int N_ITERS = 4;
    int MAX_SELECTORS = 900000 / G_SIZE ) );
    int NUM_OVERSHOOT_BYTES = 20;

    int[] RAND_NUMS = new int[]
    {
        619720127481931816813233566247,
        985724205454863491741242949214,
        73385933570862157473654730472,
        41943627849686721039968048051,
        878465811169869675611697867561,
        862687507283482129807591733623,
        15023859379684877625169643105,
        170607520932727476693425174647,
        73122335530442853695249445515,
        909545703919874474882500594612,
        641801220162819984589513495799,
        161604958533221400386867600782,
        382596414171516375682485911276,
        98553163354666933424341533870,
        227730475186263647537686600224,
        46968770919190373294822808206,
        184943795384383461404758839887,
        71567618276204918873777604560,
        9511605787227980496409713940,
        652934970447318353859672112785,
        6458638033501399335499820908,
        60977215427458018479626630742,
        65328276262368081927626789125,
        41152193830082178343175128250,
        17077497227599963949578352126,
        857956358619580124737594701612,
        669112134694363992809743168974,
        9443757485260074764218286281,
        344805988739511655814334249515,
        897955664981649113974459893228,
        43383755326892624010265445951,
        686754806760493403415394687700,
        946670656610738392760799887653,
        978321576617626502894679243440,
        68087919457264072492656204700,
        707151457449797195791558945679,
        2975987824713663412693342606,
        134108571364631212174643304329,
        34397430751497314983374822928,
        14020673263980736876478430305,
        17051436469282982855953676246,
        369970294750807827150790288923,
        80437821582859228156555571082,
        89683154726152446229346550256,
        661821976991658869905758745193,
        768550608933378286215979792961,
        61688793644986403106366905644,
        372567466434645210389550919135,
        780773635389707100626958165504,
        92017619371385726520350668108,
        645990626197510357358850858364,
        936638
    };
}


/**
 * A simple class the hold and calculate the CRC for sanity checking of the
 * data.
 *
 @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
 */
class CRC
{
    private static int[] CRC32_TABLE = new int[]
    {
        0x000000000x04c11db70x09823b6e0x0d4326d9,
        0x130476dc0x17c56b6b0x1a864db20x1e475005,
        0x2608edb80x22c9f00f0x2f8ad6d60x2b4bcb61,
        0x350c9b640x31cd86d30x3c8ea00a0x384fbdbd,
        0x4c11db700x48d0c6c70x4593e01e0x4152fda9,
        0x5f15adac0x5bd4b01b0x569796c20x52568b75,
        0x6a1936c80x6ed82b7f0x639b0da60x675a1011,
        0x791d40140x7ddc5da30x709f7b7a0x745e66cd,
        0x9823b6e00x9ce2ab570x91a18d8e0x95609039,
        0x8b27c03c0x8fe6dd8b0x82a5fb520x8664e6e5,
        0xbe2b5b580xbaea46ef0xb7a960360xb3687d81,
        0xad2f2d840xa9ee30330xa4ad16ea0xa06c0b5d,
        0xd4326d900xd0f370270xddb056fe0xd9714b49,
        0xc7361b4c0xc3f706fb0xceb420220xca753d95,
        0xf23a80280xf6fb9d9f0xfbb8bb460xff79a6f1,
        0xe13ef6f40xe5ffeb430xe8bccd9a0xec7dd02d,
        0x348670770x30476dc00x3d044b190x39c556ae,
        0x278206ab0x23431b1c0x2e003dc50x2ac12072,
        0x128e9dcf0x164f80780x1b0ca6a10x1fcdbb16,
        0x018aeb130x054bf6a40x0808d07d0x0cc9cdca,
        0x7897ab070x7c56b6b00x711590690x75d48dde,
        0x6b93dddb0x6f52c06c0x6211e6b50x66d0fb02,
        0x5e9f46bf0x5a5e5b080x571d7dd10x53dc6066,
        0x4d9b30630x495a2dd40x44190b0d0x40d816ba,
        0xaca5c6970xa864db200xa527fdf90xa1e6e04e,
        0xbfa1b04b0xbb60adfc0xb6238b250xb2e29692,
        0x8aad2b2f0x8e6c36980x832f10410x87ee0df6,
        0x99a95df30x9d6840440x902b669d0x94ea7b2a,
        0xe0b41de70xe47500500xe93626890xedf73b3e,
        0xf3b06b3b0xf771768c0xfa3250550xfef34de2,
        0xc6bcf05f0xc27dede80xcf3ecb310xcbffd686,
        0xd5b886830xd1799b340xdc3abded0xd8fba05a,
        0x690ce0ee0x6dcdfd590x608edb800x644fc637,
        0x7a0896320x7ec98b850x738aad5c0x774bb0eb,
        0x4f040d560x4bc510e10x468636380x42472b8f,
        0x5c007b8a0x58c1663d0x558240e40x51435d53,
        0x251d3b9e0x21dc26290x2c9f00f00x285e1d47,
        0x36194d420x32d850f50x3f9b762c0x3b5a6b9b,
        0x0315d6260x07d4cb910x0a97ed480x0e56f0ff,
        0x1011a0fa0x14d0bd4d0x19939b940x1d528623,
        0xf12f560e0xf5ee4bb90xf8ad6d600xfc6c70d7,
        0xe22b20d20xe6ea3d650xeba91bbc0xef68060b,
        0xd727bbb60xd3e6a6010xdea580d80xda649d6f,
        0xc423cd6a0xc0e2d0dd0xcda1f6040xc960ebb3,
        0xbd3e8d7e0xb9ff90c90xb4bcb6100xb07daba7,
        0xae3afba20xaafbe6150xa7b8c0cc0xa379dd7b,
        0x9b3660c60x9ff77d710x92b45ba80x9675461f,
        0x8832161a0x8cf30bad0x81b02d740x857130c3,
        0x5d8a90990x594b8d2e0x5408abf70x50c9b640,
        0x4e8ee6450x4a4ffbf20x470cdd2b0x43cdc09c,
        0x7b827d210x7f4360960x7200464f0x76c15bf8,
        0x68860bfd0x6c47164a0x610430930x65c52d24,
        0x119b4be90x155a565e0x181970870x1cd86d30,
        0x029f3d350x065e20820x0b1d065b0x0fdc1bec,
        0x3793a6510x3352bbe60x3e119d3f0x3ad08088,
        0x2497d08d0x2056cd3a0x2d15ebe30x29d4f654,
        0xc5a926790xc1683bce0xcc2b1d170xc8ea00a0,
        0xd6ad50a50xd26c4d120xdf2f6bcb0xdbee767c,
        0xe3a1cbc10xe760d6760xea23f0af0xeee2ed18,
        0xf0a5bd1d0xf464a0aa0xf92786730xfde69bc4,
        0x89b8fd090x8d79e0be0x803ac6670x84fbdbd0,
        0x9abc8bd50x9e7d96620x933eb0bb0x97ffad0c,
        0xafb010b10xab710d060xa6322bdf0xa2f33668,
        0xbcb4666d0xb8757bda0xb5365d030xb1f740b4
    };

    private int m_globalCrc;

    protected CRC()
    {
        initialiseCRC();
    }

    int getFinalCRC()
    {
        return ~m_globalCrc;
    }

    void initialiseCRC()
    {
        m_globalCrc = 0xffffffff;
    }

    void updateCRCfinal int inCh )
    {
        int temp = m_globalCrc >> 24 ^ inCh;
        iftemp < )
        {
            temp = 256 + temp;
        }
        m_globalCrc = m_globalCrc << ^ CRC32_TABLEtemp ];
    }
}

   
    
    
  
Related examples in the same category
1. BZip2 format
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.