⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 infcodes.java

📁 j2me解压缩j2me解压缩j2me解压缩j2me解压缩j2me解压缩j2me解压缩j2me解压缩j2me解压缩
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* -*-mode:java; c-basic-offset:2; -*- *//*Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions are met:1. Redistributions of source code must retain the above copyright notice,this list of conditions and the following disclaimer.2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.3. The names of the authors may not be used to endorse or promote productsderived from this software without specific prior written permission.THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY ANDFITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOTLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDINGNEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *//* * This program is based on zlib-1.1.3, so all credit should go authors * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu) * and contributors of zlib. *//*                                                                               *Modified by Asoft ltd. at 2003 for running on J2ME platform                    *www.asoft.ru                                                                   *Alexandre Rusev rusev@asoft.ru                                                 *Alexey Soloviev soloviev@asoft.ru                                              */package com.asoft.midp.jzlib;import com.asoft.midp.dynarray.*;final class InfCodes{    static final private int[] inflate_mask = {        0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f,        0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff,        0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff,        0x00007fff, 0x0000ffff    };    static final private int Z_OK = 0;    static final private int Z_STREAM_END = 1;    static final private int Z_NEED_DICT = 2;    static final private int Z_ERRNO = -1;    static final private int Z_STREAM_ERROR = -2;    static final private int Z_DATA_ERROR = -3;    static final private int Z_MEM_ERROR = -4;    static final private int Z_BUF_ERROR = -5;    static final private int Z_VERSION_ERROR = -6;    // waiting for "i:"=input,    //             "o:"=output,    //             "x:"=nothing    static final private int START = 0;  // x: set up for LEN    static final private int LEN = 1;    // i: get length/literal/eob next    static final private int LENEXT = 2; // i: getting length extra (have base)    static final private int DIST = 3;   // i: get distance next    static final private int DISTEXT = 4;// i: getting distance extra    static final private int COPY = 5;   // o: copying bytes in window, waiting for space    static final private int LIT = 6;    // o: got literal, waiting for output space    static final private int WASH = 7;   // o: got eob, possibly still output waiting    static final private int END = 8;    // x: got eob and all data flushed    static final private int BADCODE = 9;// x: got error    int mode;      // current inflate_codes mode    // mode dependent information    int len;    int_AccessibleArray tree; // pointer into tree    int tree_index = 0;    int need;   // bits needed    int lit;    // if EXT or COPY, where and how much    int get;              // bits to get for extra    int dist;             // distance back to copy from    byte lbits;           // ltree bits decoded per branch    byte dbits;           // dtree bits decoder per branch    int_AccessibleArray ltree;          // literal/length/eob tree    int ltree_index;      // literal/length/eob tree    int_AccessibleArray dtree;          // distance tree    int dtree_index;      // distance tree    InfCodes(int bl, int bd,             int_AccessibleArray tl, int tl_index,             int_AccessibleArray td, int td_index, ZStream z)    {        mode = START;        lbits = (byte) bl;        dbits = (byte) bd;        ltree = tl;        ltree_index = tl_index;        dtree = td;        dtree_index = td_index;    }    InfCodes(int bl, int bd, int_AccessibleArray tl, int_AccessibleArray td, ZStream z)    {        mode = START;        lbits = (byte) bl;        dbits = (byte) bd;        ltree = tl;        ltree_index = 0;        dtree = td;        dtree_index = 0;    }    int proc(InfBlocks s, ZStream z, int r)    {        int j;              // temporary storage        int[] t;            // temporary pointer        int tindex;         // temporary pointer        int e;              // extra bits or operation        int b = 0;            // bit buffer        int k = 0;            // bits in bit buffer        int p = 0;            // input data pointer        int n;              // bytes available there        int q;              // output window write pointer        int m;              // bytes to end of window or read pointer        int f;              // pointer to copy strings from        // copy input/output information to locals (UPDATE macro restores)        p = z.next_in_index;        n = z.avail_in;        b = s.bitb;        k = s.bitk;        q = s.write;        m = q < s.read ? s.read - q - 1 : s.end - q;        // process input and output based on current state        while (true)        {            switch (mode)            {                // waiting for "i:"=input, "o:"=output, "x:"=nothing                case START:         // x: set up for LEN                    if (m >= 258 && n >= 10)                    {                        s.bitb = b;                        s.bitk = k;                        z.avail_in = n;                        z.total_in += p - z.next_in_index;                        z.next_in_index = p;                        s.write = q;                        r = inflate_fast(lbits, dbits,                                         ltree, ltree_index,                                         dtree, dtree_index,                                         s, z);                        p = z.next_in_index;                        n = z.avail_in;                        b = s.bitb;                        k = s.bitk;                        q = s.write;                        m = q < s.read ? s.read - q - 1 : s.end - q;                        if (r != Z_OK)                        {                            mode = r == Z_STREAM_END ? WASH : BADCODE;                            break;                        }                    }                    need = lbits;                    tree = ltree;                    tree_index = ltree_index;                    mode = LEN;                case LEN:           // i: get length/literal/eob next                    j = need;                    while (k < (j))                    {                        if (n != 0)                        {                            r = Z_OK;                        }                        else                        {                            s.bitb = b;                            s.bitk = k;                            z.avail_in = n;                            z.total_in += p - z.next_in_index;                            z.next_in_index = p;                            s.write = q;                            return s.inflate_flush(z, r);                        }                        n--;                        b |= (z.next_in[p++] & 0xff) << k;                        k += 8;                    }                    tindex = (tree_index + (b & inflate_mask[j])) * 3;                    //b>>>=(tree[tindex+1]);                    b >>>= (tree.get(tindex + 1));                    //k-=(tree[tindex+1]);                    k -= (tree.get(tindex + 1));                    //e=tree[tindex];                    e = tree.get(tindex);                    if (e == 0)                    {               // literal                        //lit = tree[tindex+2];                        lit = tree.get(tindex + 2);                        mode = LIT;                        break;                    }                    if ((e & 16) != 0)                    {          // length                        get = e & 15;                        //len = tree[tindex+2];                        len = tree.get(tindex + 2);                        mode = LENEXT;                        break;                    }                    if ((e & 64) == 0)                    {        // next table                        need = e;                        //tree_index = tindex/3+tree[tindex+2];                        tree_index = tindex / 3 + tree.get(tindex + 2);                        break;                    }                    if ((e & 32) != 0)                    {               // end of block                        mode = WASH;                        break;                    }                    mode = BADCODE;        // invalid code                    z.msg = "invalid literal/length code";                    r = Z_DATA_ERROR;                    s.bitb = b;                    s.bitk = k;                    z.avail_in = n;                    z.total_in += p - z.next_in_index;                    z.next_in_index = p;                    s.write = q;                    return s.inflate_flush(z, r);                case LENEXT:        // i: getting length extra (have base)                    j = get;                    while (k < (j))                    {                        if (n != 0)                        {                            r = Z_OK;                        }                        else                        {                            s.bitb = b;                            s.bitk = k;                            z.avail_in = n;                            z.total_in += p - z.next_in_index;                            z.next_in_index = p;                            s.write = q;                            return s.inflate_flush(z, r);                        }                        n--;                        b |= (z.next_in[p++] & 0xff) << k;                        k += 8;                    }                    len += (b & inflate_mask[j]);                    b >>= j;                    k -= j;                    need = dbits;                    tree = dtree;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -