Mercurial > 510Connectbot
annotate src/com/jcraft/jzlib/Inflate.java @ 392:7ac1a0b02f44
add test buffer changed when input stream runs dry, similar to async test
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Tue, 16 Sep 2014 16:22:41 -0700 |
parents | 46c2115ae1c8 |
children |
rev | line source |
---|---|
0 | 1 /* -*-mode:java; c-basic-offset:2; -*- */ |
2 /* | |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
3 Copyright (c) 2000-2011 ymnk, JCraft,Inc. All rights reserved. |
0 | 4 |
5 Redistribution and use in source and binary forms, with or without | |
6 modification, are permitted provided that the following conditions are met: | |
7 | |
8 1. Redistributions of source code must retain the above copyright notice, | |
9 this list of conditions and the following disclaimer. | |
10 | |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
11 2. Redistributions in binary form must reproduce the above copyright |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
12 notice, this list of conditions and the following disclaimer in |
0 | 13 the documentation and/or other materials provided with the distribution. |
14 | |
15 3. The names of the authors may not be used to endorse or promote products | |
16 derived from this software without specific prior written permission. | |
17 | |
18 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, | |
19 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
20 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, | |
21 INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, | |
22 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | |
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
25 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | |
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 */ | |
29 /* | |
30 * This program is based on zlib-1.1.3, so all credit should go authors | |
31 * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu) | |
32 * and contributors of zlib. | |
33 */ | |
34 | |
35 package com.jcraft.jzlib; | |
36 | |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
37 final class Inflate{ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
38 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
39 static final private int MAX_WBITS=15; // 32K LZ77 window |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
40 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
41 // preset dictionary flag in zlib header |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
42 static final private int PRESET_DICT=0x20; |
0 | 43 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
44 static final int Z_NO_FLUSH=0; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
45 static final int Z_PARTIAL_FLUSH=1; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
46 static final int Z_SYNC_FLUSH=2; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
47 static final int Z_FULL_FLUSH=3; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
48 static final int Z_FINISH=4; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
49 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
50 static final private int Z_DEFLATED=8; |
0 | 51 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
52 static final private int Z_OK=0; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
53 static final private int Z_STREAM_END=1; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
54 static final private int Z_NEED_DICT=2; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
55 static final private int Z_ERRNO=-1; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
56 static final private int Z_STREAM_ERROR=-2; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
57 static final private int Z_DATA_ERROR=-3; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
58 static final private int Z_MEM_ERROR=-4; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
59 static final private int Z_BUF_ERROR=-5; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
60 static final private int Z_VERSION_ERROR=-6; |
0 | 61 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
62 static final private int METHOD=0; // waiting for method byte |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
63 static final private int FLAG=1; // waiting for flag byte |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
64 static final private int DICT4=2; // four dictionary check bytes to go |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
65 static final private int DICT3=3; // three dictionary check bytes to go |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
66 static final private int DICT2=4; // two dictionary check bytes to go |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
67 static final private int DICT1=5; // one dictionary check byte to go |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
68 static final private int DICT0=6; // waiting for inflateSetDictionary |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
69 static final private int BLOCKS=7; // decompressing blocks |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
70 static final private int CHECK4=8; // four check bytes to go |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
71 static final private int CHECK3=9; // three check bytes to go |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
72 static final private int CHECK2=10; // two check bytes to go |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
73 static final private int CHECK1=11; // one check byte to go |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
74 static final private int DONE=12; // finished check, done |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
75 static final private int BAD=13; // got an error--stay here |
0 | 76 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
77 static final private int HEAD=14; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
78 static final private int LENGTH=15; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
79 static final private int TIME=16; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
80 static final private int OS=17; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
81 static final private int EXLEN=18; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
82 static final private int EXTRA=19; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
83 static final private int NAME=20; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
84 static final private int COMMENT=21; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
85 static final private int HCRC=22; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
86 static final private int FLAGS=23; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
87 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
88 static final int INFLATE_ANY=0x40000000; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
89 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
90 int mode; // current inflate mode |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
91 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
92 // mode dependent information |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
93 int method; // if FLAGS, method byte |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
94 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
95 // if CHECK, check values to compare |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
96 long was = -1; // computed check value |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
97 long need; // stream check value |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
98 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
99 // if BAD, inflateSync's marker bytes count |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
100 int marker; |
0 | 101 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
102 // mode independent information |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
103 int wrap; // flag for no wrapper |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
104 // 0: no wrapper |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
105 // 1: zlib header |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
106 // 2: gzip header |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
107 // 4: auto detection |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
108 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
109 int wbits; // log2(window size) (8..15, defaults to 15) |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
110 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
111 InfBlocks blocks; // current inflate_blocks state |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
112 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
113 private final ZStream z; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
114 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
115 private int flags; |
0 | 116 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
117 private int need_bytes = -1; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
118 private byte[] crcbuf=new byte[4]; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
119 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
120 GZIPHeader gheader = null; |
0 | 121 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
122 int inflateReset(){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
123 if(z == null) return Z_STREAM_ERROR; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
124 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
125 z.total_in = z.total_out = 0; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
126 z.msg = null; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
127 this.mode = HEAD; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
128 this.need_bytes = -1; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
129 this.blocks.reset(); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
130 return Z_OK; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
131 } |
0 | 132 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
133 int inflateEnd(){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
134 if(blocks != null){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
135 blocks.free(); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
136 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
137 return Z_OK; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
138 } |
0 | 139 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
140 Inflate(ZStream z){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
141 this.z=z; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
142 } |
0 | 143 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
144 int inflateInit(int w){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
145 z.msg = null; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
146 blocks = null; |
0 | 147 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
148 // handle undocumented wrap option (no zlib header or check) |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
149 wrap = 0; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
150 if(w < 0){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
151 w = - w; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
152 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
153 else if((w&INFLATE_ANY) != 0){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
154 wrap = 4; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
155 w &= ~INFLATE_ANY; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
156 if(w < 48) |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
157 w &= 15; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
158 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
159 else if((w & ~31) != 0) { // for example, DEF_WBITS + 32 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
160 wrap = 4; // zlib and gzip wrapped data should be accepted. |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
161 w &= 15; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
162 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
163 else { |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
164 wrap = (w >> 4) + 1; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
165 if(w < 48) |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
166 w &= 15; |
0 | 167 } |
168 | |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
169 if(w<8 ||w>15){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
170 inflateEnd(); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
171 return Z_STREAM_ERROR; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
172 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
173 if(blocks != null && wbits != w){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
174 blocks.free(); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
175 blocks=null; |
0 | 176 } |
177 | |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
178 // set window size |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
179 wbits=w; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
180 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
181 this.blocks=new InfBlocks(z, 1<<w); |
0 | 182 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
183 // reset state |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
184 inflateReset(); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
185 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
186 return Z_OK; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
187 } |
0 | 188 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
189 int inflate(int f){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
190 int hold = 0; |
0 | 191 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
192 int r; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
193 int b; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
194 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
195 if(z == null || z.next_in == null){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
196 if(f == Z_FINISH && this.mode==HEAD) |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
197 return Z_OK; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
198 return Z_STREAM_ERROR; |
0 | 199 } |
200 | |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
201 f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
202 r = Z_BUF_ERROR; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
203 while (true){ |
0 | 204 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
205 switch (this.mode){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
206 case HEAD: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
207 if(wrap==0){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
208 this.mode = BLOCKS; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
209 break; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
210 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
211 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
212 try { r=readBytes(2, r, f); } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
213 catch(Return e){ return e.r; } |
0 | 214 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
215 if((wrap == 4 || (wrap&2)!=0) && |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
216 this.need == 0x8b1fL) { // gzip header |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
217 if(wrap == 4){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
218 wrap = 2; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
219 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
220 z.adler=new CRC32(); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
221 checksum(2, this.need); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
222 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
223 if(gheader==null) |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
224 gheader=new GZIPHeader(); |
0 | 225 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
226 this.mode = FLAGS; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
227 break; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
228 } |
0 | 229 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
230 if((wrap&2) != 0){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
231 this.mode = BAD; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
232 z.msg = "incorrect header check"; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
233 break; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
234 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
235 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
236 flags = 0; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
237 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
238 this.method = ((int)this.need)&0xff; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
239 b=((int)(this.need>>8))&0xff; |
0 | 240 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
241 if(((wrap&1)==0 || // check if zlib header allowed |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
242 (((this.method << 8)+b) % 31)!=0) && |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
243 (this.method&0xf)!=Z_DEFLATED){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
244 if(wrap == 4){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
245 z.next_in_index -= 2; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
246 z.avail_in += 2; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
247 z.total_in -= 2; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
248 wrap = 0; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
249 this.mode = BLOCKS; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
250 break; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
251 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
252 this.mode = BAD; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
253 z.msg = "incorrect header check"; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
254 // since zlib 1.2, it is allowted to inflateSync for this case. |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
255 /* |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
256 this.marker = 5; // can't try inflateSync |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
257 */ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
258 break; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
259 } |
0 | 260 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
261 if((this.method&0xf)!=Z_DEFLATED){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
262 this.mode = BAD; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
263 z.msg="unknown compression method"; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
264 // since zlib 1.2, it is allowted to inflateSync for this case. |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
265 /* |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
266 this.marker = 5; // can't try inflateSync |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
267 */ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
268 break; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
269 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
270 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
271 if(wrap == 4){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
272 wrap = 1; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
273 } |
0 | 274 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
275 if((this.method>>4)+8>this.wbits){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
276 this.mode = BAD; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
277 z.msg="invalid window size"; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
278 // since zlib 1.2, it is allowted to inflateSync for this case. |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
279 /* |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
280 this.marker = 5; // can't try inflateSync |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
281 */ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
282 break; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
283 } |
0 | 284 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
285 z.adler=new Adler32(); |
0 | 286 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
287 if((b&PRESET_DICT)==0){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
288 this.mode = BLOCKS; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
289 break; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
290 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
291 this.mode = DICT4; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
292 case DICT4: |
0 | 293 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
294 if(z.avail_in==0)return r;r=f; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
295 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
296 z.avail_in--; z.total_in++; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
297 this.need=((z.next_in[z.next_in_index++]&0xff)<<24)&0xff000000L; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
298 this.mode=DICT3; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
299 case DICT3: |
0 | 300 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
301 if(z.avail_in==0)return r;r=f; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
302 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
303 z.avail_in--; z.total_in++; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
304 this.need+=((z.next_in[z.next_in_index++]&0xff)<<16)&0xff0000L; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
305 this.mode=DICT2; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
306 case DICT2: |
0 | 307 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
308 if(z.avail_in==0)return r;r=f; |
0 | 309 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
310 z.avail_in--; z.total_in++; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
311 this.need+=((z.next_in[z.next_in_index++]&0xff)<<8)&0xff00L; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
312 this.mode=DICT1; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
313 case DICT1: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
314 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
315 if(z.avail_in==0)return r;r=f; |
0 | 316 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
317 z.avail_in--; z.total_in++; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
318 this.need += (z.next_in[z.next_in_index++]&0xffL); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
319 z.adler.reset(this.need); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
320 this.mode = DICT0; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
321 return Z_NEED_DICT; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
322 case DICT0: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
323 this.mode = BAD; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
324 z.msg = "need dictionary"; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
325 this.marker = 0; // can try inflateSync |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
326 return Z_STREAM_ERROR; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
327 case BLOCKS: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
328 r = this.blocks.proc(r); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
329 if(r == Z_DATA_ERROR){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
330 this.mode = BAD; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
331 this.marker = 0; // can try inflateSync |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
332 break; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
333 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
334 if(r == Z_OK){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
335 r = f; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
336 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
337 if(r != Z_STREAM_END){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
338 return r; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
339 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
340 r = f; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
341 this.was=z.adler.getValue(); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
342 this.blocks.reset(); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
343 if(this.wrap==0){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
344 this.mode=DONE; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
345 break; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
346 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
347 this.mode=CHECK4; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
348 case CHECK4: |
0 | 349 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
350 if(z.avail_in==0)return r;r=f; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
351 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
352 z.avail_in--; z.total_in++; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
353 this.need=((z.next_in[z.next_in_index++]&0xff)<<24)&0xff000000L; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
354 this.mode=CHECK3; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
355 case CHECK3: |
0 | 356 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
357 if(z.avail_in==0)return r;r=f; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
358 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
359 z.avail_in--; z.total_in++; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
360 this.need+=((z.next_in[z.next_in_index++]&0xff)<<16)&0xff0000L; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
361 this.mode = CHECK2; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
362 case CHECK2: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
363 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
364 if(z.avail_in==0)return r;r=f; |
0 | 365 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
366 z.avail_in--; z.total_in++; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
367 this.need+=((z.next_in[z.next_in_index++]&0xff)<<8)&0xff00L; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
368 this.mode = CHECK1; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
369 case CHECK1: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
370 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
371 if(z.avail_in==0)return r;r=f; |
0 | 372 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
373 z.avail_in--; z.total_in++; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
374 this.need+=(z.next_in[z.next_in_index++]&0xffL); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
375 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
376 if(flags!=0){ // gzip |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
377 this.need = ((this.need&0xff000000)>>24 | |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
378 (this.need&0x00ff0000)>>8 | |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
379 (this.need&0x0000ff00)<<8 | |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
380 (this.need&0x0000ffff)<<24)&0xffffffffL; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
381 } |
0 | 382 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
383 if(((int)(this.was)) != ((int)(this.need))){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
384 z.msg = "incorrect data check"; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
385 // chack is delayed |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
386 /* |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
387 this.mode = BAD; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
388 this.marker = 5; // can't try inflateSync |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
389 break; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
390 */ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
391 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
392 else if(flags!=0 && gheader!=null){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
393 gheader.crc = this.need; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
394 } |
0 | 395 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
396 this.mode = LENGTH; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
397 case LENGTH: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
398 if (wrap!=0 && flags!=0) { |
0 | 399 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
400 try { r=readBytes(4, r, f); } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
401 catch(Return e){ return e.r; } |
0 | 402 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
403 if(z.msg!=null && z.msg.equals("incorrect data check")){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
404 this.mode = BAD; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
405 this.marker = 5; // can't try inflateSync |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
406 break; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
407 } |
0 | 408 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
409 if (this.need != (z.total_out & 0xffffffffL)) { |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
410 z.msg = "incorrect length check"; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
411 this.mode = BAD; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
412 break; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
413 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
414 z.msg = null; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
415 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
416 else { |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
417 if(z.msg!=null && z.msg.equals("incorrect data check")){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
418 this.mode = BAD; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
419 this.marker = 5; // can't try inflateSync |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
420 break; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
421 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
422 } |
0 | 423 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
424 this.mode = DONE; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
425 case DONE: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
426 return Z_STREAM_END; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
427 case BAD: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
428 return Z_DATA_ERROR; |
0 | 429 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
430 case FLAGS: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
431 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
432 try { r=readBytes(2, r, f); } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
433 catch(Return e){ return e.r; } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
434 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
435 flags = ((int)this.need)&0xffff; |
0 | 436 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
437 if ((flags & 0xff) != Z_DEFLATED) { |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
438 z.msg = "unknown compression method"; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
439 this.mode = BAD; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
440 break; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
441 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
442 if ((flags & 0xe000)!=0) { |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
443 z.msg = "unknown header flags set"; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
444 this.mode = BAD; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
445 break; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
446 } |
0 | 447 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
448 if ((flags & 0x0200)!=0){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
449 checksum(2, this.need); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
450 } |
0 | 451 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
452 this.mode = TIME; |
0 | 453 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
454 case TIME: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
455 try { r=readBytes(4, r, f); } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
456 catch(Return e){ return e.r; } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
457 if(gheader!=null) |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
458 gheader.time = this.need; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
459 if ((flags & 0x0200)!=0){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
460 checksum(4, this.need); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
461 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
462 this.mode = OS; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
463 case OS: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
464 try { r=readBytes(2, r, f); } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
465 catch(Return e){ return e.r; } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
466 if(gheader!=null){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
467 gheader.xflags = ((int)this.need)&0xff; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
468 gheader.os = (((int)this.need)>>8)&0xff; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
469 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
470 if ((flags & 0x0200)!=0){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
471 checksum(2, this.need); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
472 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
473 this.mode = EXLEN; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
474 case EXLEN: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
475 if ((flags & 0x0400)!=0) { |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
476 try { r=readBytes(2, r, f); } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
477 catch(Return e){ return e.r; } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
478 if(gheader!=null){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
479 gheader.extra = new byte[((int)this.need)&0xffff]; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
480 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
481 if ((flags & 0x0200)!=0){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
482 checksum(2, this.need); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
483 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
484 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
485 else if(gheader!=null){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
486 gheader.extra=null; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
487 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
488 this.mode = EXTRA; |
0 | 489 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
490 case EXTRA: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
491 if ((flags & 0x0400)!=0) { |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
492 try { |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
493 r=readBytes(r, f); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
494 if(gheader!=null){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
495 byte[] foo = tmp_string.toByteArray(); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
496 tmp_string=null; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
497 if(foo.length == gheader.extra.length){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
498 System.arraycopy(foo, 0, gheader.extra, 0, foo.length); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
499 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
500 else{ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
501 z.msg = "bad extra field length"; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
502 this.mode = BAD; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
503 break; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
504 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
505 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
506 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
507 catch(Return e){ return e.r; } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
508 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
509 else if(gheader!=null){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
510 gheader.extra=null; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
511 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
512 this.mode = NAME; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
513 case NAME: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
514 if ((flags & 0x0800)!=0) { |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
515 try { |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
516 r=readString(r, f); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
517 if(gheader!=null){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
518 gheader.name=tmp_string.toByteArray(); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
519 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
520 tmp_string=null; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
521 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
522 catch(Return e){ return e.r; } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
523 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
524 else if(gheader!=null){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
525 gheader.name=null; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
526 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
527 this.mode = COMMENT; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
528 case COMMENT: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
529 if ((flags & 0x1000)!=0) { |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
530 try { |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
531 r=readString(r, f); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
532 if(gheader!=null){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
533 gheader.comment=tmp_string.toByteArray(); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
534 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
535 tmp_string=null; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
536 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
537 catch(Return e){ return e.r; } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
538 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
539 else if(gheader!=null){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
540 gheader.comment=null; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
541 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
542 this.mode = HCRC; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
543 case HCRC: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
544 if ((flags & 0x0200)!=0) { |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
545 try { r=readBytes(2, r, f); } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
546 catch(Return e){ return e.r; } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
547 if(gheader!=null){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
548 gheader.hcrc=(int)(this.need&0xffff); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
549 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
550 if(this.need != (z.adler.getValue()&0xffffL)){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
551 this.mode = BAD; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
552 z.msg = "header crc mismatch"; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
553 this.marker = 5; // can't try inflateSync |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
554 break; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
555 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
556 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
557 z.adler = new CRC32(); |
0 | 558 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
559 this.mode = BLOCKS; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
560 break; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
561 default: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
562 return Z_STREAM_ERROR; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
563 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
564 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
565 } |
0 | 566 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
567 int inflateSetDictionary(byte[] dictionary, int dictLength){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
568 if(z==null || (this.mode != DICT0 && this.wrap != 0)){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
569 return Z_STREAM_ERROR; |
0 | 570 } |
571 | |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
572 int index=0; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
573 int length = dictLength; |
0 | 574 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
575 if(this.mode==DICT0){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
576 long adler_need=z.adler.getValue(); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
577 z.adler.reset(); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
578 z.adler.update(dictionary, 0, dictLength); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
579 if(z.adler.getValue()!=adler_need){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
580 return Z_DATA_ERROR; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
581 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
582 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
583 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
584 z.adler.reset(); |
0 | 585 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
586 if(length >= (1<<this.wbits)){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
587 length = (1<<this.wbits)-1; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
588 index=dictLength - length; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
589 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
590 this.blocks.set_dictionary(dictionary, index, length); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
591 this.mode = BLOCKS; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
592 return Z_OK; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
593 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
594 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
595 static private byte[] mark = {(byte)0, (byte)0, (byte)0xff, (byte)0xff}; |
0 | 596 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
597 int inflateSync(){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
598 int n; // number of bytes to look at |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
599 int p; // pointer to bytes |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
600 int m; // number of marker bytes found in a row |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
601 long r, w; // temporaries to save total_in and total_out |
0 | 602 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
603 // set up |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
604 if(z == null) |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
605 return Z_STREAM_ERROR; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
606 if(this.mode != BAD){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
607 this.mode = BAD; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
608 this.marker = 0; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
609 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
610 if((n=z.avail_in)==0) |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
611 return Z_BUF_ERROR; |
0 | 612 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
613 p=z.next_in_index; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
614 m=this.marker; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
615 // search |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
616 while (n!=0 && m < 4){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
617 if(z.next_in[p] == mark[m]){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
618 m++; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
619 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
620 else if(z.next_in[p]!=0){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
621 m = 0; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
622 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
623 else{ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
624 m = 4 - m; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
625 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
626 p++; n--; |
0 | 627 } |
628 | |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
629 // restore |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
630 z.total_in += p-z.next_in_index; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
631 z.next_in_index = p; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
632 z.avail_in = n; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
633 this.marker = m; |
0 | 634 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
635 // return no joy or set up to restart on a new block |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
636 if(m != 4){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
637 return Z_DATA_ERROR; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
638 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
639 r=z.total_in; w=z.total_out; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
640 inflateReset(); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
641 z.total_in=r; z.total_out = w; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
642 this.mode = BLOCKS; |
0 | 643 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
644 return Z_OK; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
645 } |
0 | 646 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
647 // Returns true if inflate is currently at the end of a block generated |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
648 // by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
649 // implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
650 // but removes the length bytes of the resulting empty stored block. When |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
651 // decompressing, PPP checks that at the end of input packet, inflate is |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
652 // waiting for these length bytes. |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
653 int inflateSyncPoint(){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
654 if(z == null || this.blocks == null) |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
655 return Z_STREAM_ERROR; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
656 return this.blocks.sync_point(); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
657 } |
0 | 658 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
659 private int readBytes(int n, int r, int f) throws Return{ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
660 if(need_bytes == -1){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
661 need_bytes=n; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
662 this.need=0; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
663 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
664 while(need_bytes>0){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
665 if(z.avail_in==0){ throw new Return(r); }; r=f; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
666 z.avail_in--; z.total_in++; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
667 this.need = this.need | |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
668 ((z.next_in[z.next_in_index++]&0xff)<<((n-need_bytes)*8)); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
669 need_bytes--; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
670 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
671 if(n==2){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
672 this.need&=0xffffL; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
673 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
674 else if(n==4) { |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
675 this.need&=0xffffffffL; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
676 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
677 need_bytes=-1; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
678 return r; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
679 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
680 class Return extends Exception{ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
681 int r; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
682 Return(int r){this.r=r; } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
683 } |
0 | 684 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
685 private java.io.ByteArrayOutputStream tmp_string = null; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
686 private int readString(int r, int f) throws Return{ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
687 if(tmp_string == null){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
688 tmp_string=new java.io.ByteArrayOutputStream(); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
689 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
690 int b=0; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
691 do { |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
692 if(z.avail_in==0){ throw new Return(r); }; r=f; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
693 z.avail_in--; z.total_in++; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
694 b = z.next_in[z.next_in_index]; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
695 if(b!=0) tmp_string.write(z.next_in, z.next_in_index, 1); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
696 z.adler.update(z.next_in, z.next_in_index, 1); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
697 z.next_in_index++; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
698 }while(b!=0); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
699 return r; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
700 } |
0 | 701 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
702 private int readBytes(int r, int f) throws Return{ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
703 if(tmp_string == null){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
704 tmp_string=new java.io.ByteArrayOutputStream(); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
705 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
706 int b=0; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
707 while(this.need>0){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
708 if(z.avail_in==0){ throw new Return(r); }; r=f; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
709 z.avail_in--; z.total_in++; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
710 b = z.next_in[z.next_in_index]; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
711 tmp_string.write(z.next_in, z.next_in_index, 1); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
712 z.adler.update(z.next_in, z.next_in_index, 1); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
713 z.next_in_index++; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
714 this.need--; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
715 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
716 return r; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
717 } |
0 | 718 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
719 private void checksum(int n, long v){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
720 for(int i=0; i<n; i++){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
721 crcbuf[i]=(byte)(v&0xff); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
722 v>>=8; |
0 | 723 } |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
724 z.adler.update(crcbuf, 0, n); |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
725 } |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
726 |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
727 public GZIPHeader getGZIPHeader(){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
728 return gheader; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
729 } |
0 | 730 |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
731 boolean inParsingHeader(){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
732 switch(mode){ |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
733 case HEAD: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
734 case DICT4: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
735 case DICT3: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
736 case DICT2: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
737 case DICT1: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
738 case FLAGS: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
739 case TIME: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
740 case OS: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
741 case EXLEN: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
742 case EXTRA: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
743 case NAME: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
744 case COMMENT: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
745 case HCRC: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
746 return true; |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
747 default: |
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
748 return false; |
0 | 749 } |
357
46c2115ae1c8
update jzlib to a21be20213d66eff15904d925e9b721956a01ef7
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
750 } |
0 | 751 } |