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 
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.InputStream;

/**
 * An input stream that decompresses from the BZip2 format (without the file
 * header chars) to be read as any other stream.
 *
 @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
 */
public class CBZip2InputStream
    extends InputStream
    implements BZip2Constants
{
    private static final int START_BLOCK_STATE = 1;
    private static final int RAND_PART_A_STATE = 2;
    private static final int RAND_PART_B_STATE = 3;
    private static final int RAND_PART_C_STATE = 4;
    private static final int NO_RAND_PART_A_STATE = 5;
    private static final int NO_RAND_PART_B_STATE = 6;
    private static final int NO_RAND_PART_C_STATE = 7;

    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 ];

    /*
     * freq table collected to save a pass over the data
     * during decompression.
     */
    private int[] m_unzftab = new int256 ];

    private int[][] m_limit = new intN_GROUPS ][ MAX_ALPHA_SIZE ];
    private int[][] m_base = new intN_GROUPS ][ MAX_ALPHA_SIZE ];
    private int[][] m_perm = new intN_GROUPS ][ MAX_ALPHA_SIZE ];
    private int[] m_minLens = new intN_GROUPS ];

    private boolean m_streamEnd;
    private int m_currentChar = -1;

    private int m_currentState = START_BLOCK_STATE;
    private int m_rNToGo;
    private int m_rTPos;
    private int m_tPos;

    private int i2;
    private int count;
    private int chPrev;
    private int ch2;
    private int j2;
    private char z;

    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;

    private InputStream m_input;

    private int m_computedBlockCRC;
    private int m_computedCombinedCRC;

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

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

    private int m_storedBlockCRC;
    private int m_storedCombinedCRC;
    private int[] m_tt;

    public CBZip2InputStreamfinal InputStream input )
    {
        bsSetStreaminput );
        initialize();
        initBlock();
        setupBlock();
    }

    private static void badBlockHeader()
    {
        cadvise();
    }

    private static void blockOverrun()
    {
        cadvise();
    }

    private static void cadvise()
    {
        System.out.println"CRC Error" );
        //throw new CCoruptionError();
    }

    private static void compressedStreamEOF()
    {
        cadvise();
    }

    private static void crcError()
    {
        cadvise();
    }

    public int read()
    {
        ifm_streamEnd )
        {
            return -1;
        }
        else
        {
            int retChar = m_currentChar;
            switchm_currentState )
            {
                case START_BLOCK_STATE:
                    break;
                case RAND_PART_A_STATE:
                    break;
                case RAND_PART_B_STATE:
                    setupRandPartB();
                    break;
                case RAND_PART_C_STATE:
                    setupRandPartC();
                    break;
                case NO_RAND_PART_A_STATE:
                    break;
                case NO_RAND_PART_B_STATE:
                    setupNoRandPartB();
                    break;
                case NO_RAND_PART_C_STATE:
                    setupNoRandPartC();
                    break;
                default:
                    break;
            }
            return retChar;
        }
    }

    private void setDecompressStructureSizesint newSize100k )
    {
        if!<= newSize100k && newSize100k <= && <= m_blockSize100k
            && m_blockSize100k <= ) )
        {
            // throw new IOException("Invalid block size");
        }

        m_blockSize100k = newSize100k;

        ifnewSize100k == )
        {
            return;
        }

        int n = BASE_BLOCK_SIZE * newSize100k;
        m_ll8 = new char];
        m_tt = new int];
    }

    private void setupBlock()
    {
        int[] cftab = new int257 ];
        char ch;

        cftab0;
        forint i = 1; i <= 256; i++ )
        {
            cftab= m_unzftabi - ];
        }
        forint i = 1; i <= 256; i++ )
        {
            cftab+= cftabi - ];
        }

        forint i = 0; i <= m_last; i++ )
        {
            ch = m_ll8];
            m_ttcftabch ] ] = i;
            cftabch ]++;
        }
        cftab = null;

        m_tPos = m_ttm_origPtr ];

        count = 0;
        i2 = 0;
        ch2 = 256;
        /*
         * not a char and not EOF
         */
        ifm_blockRandomised )
        {
            m_rNToGo = 0;
            m_rTPos = 0;
            setupRandPartA();
        }
        else
        {
            setupNoRandPartA();
        }
    }

    private void setupNoRandPartA()
    {
        ifi2 <= m_last )
        {
            chPrev = ch2;
            ch2 = m_ll8m_tPos ];
            m_tPos = m_ttm_tPos ];
            i2++;

            m_currentChar = ch2;
            m_currentState = NO_RAND_PART_B_STATE;
            m_crc.updateCRCch2 );
        }
        else
        {
            endBlock();
            initBlock();
            setupBlock();
        }
    }

    private void setupNoRandPartB()
    {
        ifch2 != chPrev )
        {
            m_currentState = NO_RAND_PART_A_STATE;
            count = 1;
            setupNoRandPartA();
        }
        else
        {
            count++;
            ifcount >= )
            {
                z = m_ll8m_tPos ];
                m_tPos = m_ttm_tPos ];
                m_currentState = NO_RAND_PART_C_STATE;
                j2 = 0;
                setupNoRandPartC();
            }
            else
            {
                m_currentState = NO_RAND_PART_A_STATE;
                setupNoRandPartA();
            }
        }
    }

    private void setupNoRandPartC()
    {
        ifj2 < z )
        {
            m_currentChar = ch2;
            m_crc.updateCRCch2 );
            j2++;
        }
        else
        {
            m_currentState = NO_RAND_PART_A_STATE;
            i2++;
            count = 0;
            setupNoRandPartA();
        }
    }

    private void setupRandPartA()
    {
        ifi2 <= m_last )
        {
            chPrev = ch2;
            ch2 = m_ll8m_tPos ];
            m_tPos = m_ttm_tPos ];
            ifm_rNToGo == )
            {
                m_rNToGo = RAND_NUMSm_rTPos ];
                m_rTPos++;
                ifm_rTPos == 512 )
                {
                    m_rTPos = 0;
                }
            }
            m_rNToGo--;
            ch2 ^= ( ( m_rNToGo == );
            i2++;

            m_currentChar = ch2;
            m_currentState = RAND_PART_B_STATE;
            m_crc.updateCRCch2 );
        }
        else
        {
            endBlock();
            initBlock();
            setupBlock();
        }
    }

    private void setupRandPartB()
    {
        ifch2 != chPrev )
        {
            m_currentState = RAND_PART_A_STATE;
            count = 1;
            setupRandPartA();
        }
        else
        {
            count++;
            ifcount >= )
            {
                z = m_ll8m_tPos ];
                m_tPos = m_ttm_tPos ];
                ifm_rNToGo == )
                {
                    m_rNToGo = RAND_NUMSm_rTPos ];
                    m_rTPos++;
                    ifm_rTPos == 512 )
                    {
                        m_rTPos = 0;
                    }
                }
                m_rNToGo--;
                z ^= ( ( m_rNToGo == );
                j2 = 0;
                m_currentState = RAND_PART_C_STATE;
                setupRandPartC();
            }
            else
            {
                m_currentState = RAND_PART_A_STATE;
                setupRandPartA();
            }
        }
    }

    private void setupRandPartC()
    {
        ifj2 < z )
        {
            m_currentChar = ch2;
            m_crc.updateCRCch2 );
            j2++;
        }
        else
        {
            m_currentState = RAND_PART_A_STATE;
            i2++;
            count = 0;
            setupRandPartA();
        }
    }

    private void getAndMoveToFrontDecode()
    {
        int nextSym;

        int limitLast = BASE_BLOCK_SIZE * m_blockSize100k;
        m_origPtr = readVariableSizedInt24 );

        recvDecodingTables();
        int EOB = m_nInUse + 1;
        int groupNo = -1;
        int groupPos = 0;

        /*
         * Setting up the unzftab entries here is not strictly
         * necessary, but it does save having to do it later
         * in a separate pass, and so saves a block's worth of
         * cache misses.
         */
        forint i = 0; i <= 255; i++ )
        {
            m_unzftab0;
        }

        final char[] yy = new char256 ];
        forint i = 0; i <= 255; i++ )
        {
            yy(char)i;
        }

        m_last = -1;
        int zt;
        int zn;
        int zvec;
        int zj;
        groupNo++;
        groupPos = G_SIZE - 1;

        zt = m_selectorgroupNo ];
        zn = m_minLenszt ];
        zvec = bsRzn );
        whilezvec > m_limitzt ][ zn ] )
        {
            zn++;

            whilem_bsLive < )
            {
                int zzi;
                try
                {
                    zzi = m_input.read();
                }
                catchIOException e )
                {
                    compressedStreamEOF();
          break;
                }
                ifzzi == -)
                {
                    compressedStreamEOF();
          break;
                }
                m_bsBuff = m_bsBuff << zzi & 0xff );
                m_bsLive += 8;
            }

            zj = m_bsBuff >> m_bsLive - ) ) 1;
            m_bsLive--;

            zvec = zvec << | zj;
        }
        nextSym = m_permzt ][ zvec - m_basezt ][ zn ] ];

        whiletrue )
        {
            ifnextSym == EOB )
            {
                break;
            }

            ifnextSym == RUNA || nextSym == RUNB )
            {
                char ch;
                int s = -1;
                int N = 1;
                do
                {
                    ifnextSym == RUNA )
                    {
                        s = s + * N;
                    }
                    else// if( nextSym == RUNB )
                    {
                        s = s + * N;
                    }
                    N = N * 2;

                    ifgroupPos == )
                    {
                        groupNo++;
                        groupPos = G_SIZE;
                    }
                    groupPos--;
                    zt = m_selectorgroupNo ];
                    zn = m_minLenszt ];
                    zvec = bsRzn );
                    whilezvec > m_limitzt ][ zn ] )
                    {
                        zn++;

                        whilem_bsLive < )
                        {
                            int zzi;
                            char thech = 0;
                            try
                            {
                                thech = (char)m_input.read();
                            }
                            catchIOException e )
                            {
                                compressedStreamEOF();
                            }
                            ifthech == -)
                            {
                                compressedStreamEOF();
                            }
                            zzi = thech;
                            m_bsBuff = m_bsBuff << zzi & 0xff );
                            m_bsLive += 8;
                        }

                        zj = m_bsBuff >> m_bsLive - ) ) 1;
                        m_bsLive--;
                        zvec = zvec << | zj;
                    }

                    nextSym = m_permzt ][ zvec - m_basezt ][ zn ] ];

                whilenextSym == RUNA || nextSym == RUNB );

                s++;
                ch = m_seqToUnseqyy] ];
                m_unzftabch += s;

                whiles > )
                {
                    m_last++;
                    m_ll8m_last = ch;
                    s--;
                }

                ifm_last >= limitLast )
                {
                    blockOverrun();
                }
                continue;
            }
            else
            {
                char tmp;
                m_last++;
                ifm_last >= limitLast )
                {
                    blockOverrun();
                }

                tmp = yynextSym - ];
                m_unzftabm_seqToUnseqtmp ] ]++;
                m_ll8m_last = m_seqToUnseqtmp ];

                /*
                 * This loop is hammered during decompression,
                 * hence the unrolling.
                 * for (j = nextSym-1; j > 0; j--) yy[j] = yy[j-1];
                 */
                int j = nextSym - 1;
                for; j > 3; j -= )
                {
                    yy= yyj - ];
                    yyj - = yyj - ];
                    yyj - = yyj - ];
                    yyj - = yyj - ];
                }
                for; j > 0; j-- )
                {
                    yy= yyj - ];
                }

                yy= tmp;

                ifgroupPos == )
                {
                    groupNo++;
                    groupPos = G_SIZE;
                }
                groupPos--;
                zt = m_selectorgroupNo ];
                zn = m_minLenszt ];
                zvec = bsRzn );
                whilezvec > m_limitzt ][ zn ] )
                {
                    zn++;

                    whilem_bsLive < )
                    {
                        char ch = 0;
                        try
                        {
                            ch = (char)m_input.read();
                        }
                        catchIOException e )
                        {
                            compressedStreamEOF();
                        }

                        m_bsBuff = m_bsBuff << ch & 0xff );
                        m_bsLive += 8;
                    }

                    zj = m_bsBuff >> m_bsLive - ) ) 1;
                    m_bsLive--;

                    zvec = zvec << | zj;
                }
                nextSym = m_permzt ][ zvec - m_basezt ][ zn ] ];

                continue;
            }
        }
    }

    private void bsFinishedWithStream()
    {
        m_input = null;
    }

    private int readVariableSizedIntfinal int numBits )
    {
        return bsRnumBits );
    }

    private char readUnsignedChar()
    {
        return (char)bsR);
    }

    private int readInt()
    {
        int u = 0;
        u = u << | bsR);
        u = u << | bsR);
        u = u << | bsR);
        u = u << | bsR);
        return u;
    }

    private int bsRfinal int )
    {
        whilem_bsLive < n )
        {
            char ch = 0;
            try
            {
                ch = (char)m_input.read();
            }
            catchfinal IOException ioe )
            {
                compressedStreamEOF();
            }

            ifch == -)
            {
                compressedStreamEOF();
            }

            m_bsBuff = m_bsBuff << ch & 0xff );
            m_bsLive += 8;
        }

        final int result = m_bsBuff >> m_bsLive - n ) ) ( ( << n );
        m_bsLive -= n;
        return result;
    }

    private void bsSetStreamfinal InputStream input )
    {
        m_input = input;
        m_bsLive = 0;
        m_bsBuff = 0;
    }

    private void complete()
    {
        m_storedCombinedCRC = readInt();
        ifm_storedCombinedCRC != m_computedCombinedCRC )
        {
            crcError();
        }

        bsFinishedWithStream();
        m_streamEnd = true;
    }

    private void endBlock()
    {
        m_computedBlockCRC = m_crc.getFinalCRC();
        /*
         * A bad CRC is considered a fatal error.
         */
        ifm_storedBlockCRC != m_computedBlockCRC )
        {
            crcError();
        }

        m_computedCombinedCRC = m_computedCombinedCRC << )
            m_computedCombinedCRC >>> 31 );
        m_computedCombinedCRC ^= m_computedBlockCRC;
    }

    private void hbCreateDecodeTablesfinal int[] limit,
                                       final int[] base,
                                       final int[] perm,
                                       final char[] length,
                                       final int minLen,
                                       final int maxLen,
                                       final int alphaSize )
    {
        int pp = 0;
        forint i = minLen; i <= maxLen; i++ )
        {
            forint j = 0; j < alphaSize; j++ )
            {
                iflength== i )
                {
                    permpp = j;
                    pp++;
                }
            }
        }

        forint i = 0; i < MAX_CODE_LEN; i++ )
        {
            base0;
        }

        forint i = 0; i < alphaSize; i++ )
        {
            baselength]++;
        }

        forint i = 1; i < MAX_CODE_LEN; i++ )
        {
            base+= basei - ];
        }

        forint i = 0; i < MAX_CODE_LEN; i++ )
        {
            limit0;
        }

        int vec = 0;
        forint i = minLen; i <= maxLen; i++ )
        {
            vec += basei + - base] );
            limit= vec - 1;
            vec <<= 1;
        }

        forint i = minLen + 1; i <= maxLen; i++ )
        {
            base( ( limiti - << - base];
        }
    }

    private void initBlock()
    {
        final char magic1 = readUnsignedChar();
        final char magic2 = readUnsignedChar();
        final char magic3 = readUnsignedChar();
        final char magic4 = readUnsignedChar();
        final char magic5 = readUnsignedChar();
        final char magic6 = readUnsignedChar();
        ifmagic1 == 0x17 && magic2 == 0x72 && magic3 == 0x45 &&
            magic4 == 0x38 && magic5 == 0x50 && magic6 == 0x90 )
        {
            complete();
            return;
        }

        ifmagic1 != 0x31 || magic2 != 0x41 || magic3 != 0x59 ||
            magic4 != 0x26 || magic5 != 0x53 || magic6 != 0x59 )
        {
            badBlockHeader();
            m_streamEnd = true;
            return;
        }

        m_storedBlockCRC = readInt();

        ifbsR== )
        {
            m_blockRandomised = true;
        }
        else
        {
            m_blockRandomised = false;
        }

        //        currBlockNo++;
        getAndMoveToFrontDecode();

        m_crc.initialiseCRC();
        m_currentState = START_BLOCK_STATE;
    }

    private void initialize()
    {
        final char magic3 = readUnsignedChar();
        final char magic4 = readUnsignedChar();
        ifmagic3 != 'h' || magic4 < '1' || magic4 > '9' )
        {
            bsFinishedWithStream();
            m_streamEnd = true;
            return;
        }

        setDecompressStructureSizesmagic4 - '0' );
        m_computedCombinedCRC = 0;
    }

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

    private void recvDecodingTables()
    {
        buildInUseTable();
        makeMaps();
        final int alphaSize = m_nInUse + 2;

        /*
         * Now the selectors
         */
        final int groupCount = bsR);
        final int selectorCount = bsR15 );
        forint i = 0; i < selectorCount; i++ )
        {
            int run = 0;
            whilebsR== )
            {
                run++;
            }
            m_selectorMtf(char)run;
        }

        /*
         * Undo the MTF values for the selectors.
         */
        final char[] pos = new charN_GROUPS ];
        forchar v = 0; v < groupCount; v++ )
        {
            pos= v;
        }

        forint i = 0; i < selectorCount; i++ )
        {
            int v = m_selectorMtf];
            final char tmp = pos];
            whilev > )
            {
                pos= posv - ];
                v--;
            }
            pos= tmp;
            m_selector= tmp;
        }

        final char[][] len = new charN_GROUPS ][ MAX_ALPHA_SIZE ];
        /*
         * Now the coding tables
         */
        forint i = 0; i < groupCount; i++ )
        {
            int curr = bsR);
            forint j = 0; j < alphaSize; j++ )
            {
                whilebsR== )
                {
                    ifbsR== )
                    {
                        curr++;
                    }
                    else
                    {
                        curr--;
                    }
                }
                len][ (char)curr;
            }
        }

        /*
         * Create the Huffman decoding tables
         */
        forint k = 0; k < groupCount; k++ )
        {
            int minLen = 32;
            int maxLen = 0;
            forint i = 0; i < alphaSize; i++ )
            {
                iflen][ > maxLen )
                {
                    maxLen = len][ ];
                }
                iflen][ < minLen )
                {
                    minLen = len][ ];
                }
            }
            hbCreateDecodeTablesm_limit], m_base], m_perm], len], minLen,
                                  maxLen, alphaSize );
            m_minLens= minLen;
        }
    }

    private void buildInUseTable()
    {
        final boolean[] inUse16 = new boolean16 ];

        /*
         * Receive the mapping table
         */
        forint i = 0; i < 16; i++ )
        {
            ifbsR== )
            {
                inUse16true;
            }
            else
            {
                inUse16false;
            }
        }

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

        forint i = 0; i < 16; i++ )
        {
            ifinUse16] )
            {
                forint j = 0; j < 16; j++ )
                {
                    ifbsR== )
                    {
                        m_inUsei * 16 + j true;
                    }
                }
            }
        }
    }
}

/*
 * 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. Output stream that compresses into the 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.