1 /* java.util.zip.InflaterDynHeader
2 Copyright (C) 2001 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package java
.util
.zip
;
40 class InflaterDynHeader
42 private static final int LNUM
= 0;
43 private static final int DNUM
= 1;
44 private static final int BLNUM
= 2;
45 private static final int BLLENS
= 3;
46 private static final int LENS
= 4;
47 private static final int REPS
= 5;
49 private static final int repMin
[] = { 3, 3, 11 };
50 private static final int repBits
[] = { 2, 3, 7 };
53 private byte[] blLens
;
54 private byte[] litdistLens
;
56 private InflaterHuffmanTree blTree
;
59 private int lnum
, dnum
, blnum
, num
;
60 private int repSymbol
;
64 private static final int[] BL_ORDER
=
65 { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
67 public InflaterDynHeader()
71 public boolean decode(StreamManipulator input
) throws DataFormatException
79 lnum
= input
.peekBits(5);
84 // System.err.println("LNUM: "+lnum);
88 dnum
= input
.peekBits(5);
93 // System.err.println("DNUM: "+dnum);
95 litdistLens
= new byte[num
];
99 blnum
= input
.peekBits(4);
104 blLens
= new byte[19];
106 // System.err.println("BLNUM: "+blnum);
112 int len
= input
.peekBits(3);
116 // System.err.println("blLens["+BL_ORDER[ptr]+"]: "+len);
117 blLens
[BL_ORDER
[ptr
]] = (byte) len
;
120 blTree
= new InflaterHuffmanTree(blLens
);
128 while (((symbol
= blTree
.getSymbol(input
)) & ~
15) == 0)
130 /* Normal case: symbol in [0..15] */
132 // System.err.println("litdistLens["+ptr+"]: "+symbol);
133 litdistLens
[ptr
++] = lastLen
= (byte) symbol
;
142 /* need more input ? */
146 /* otherwise repeat code */
150 // System.err.println("repeating zero");
156 throw new DataFormatException();
158 repSymbol
= symbol
-16;
165 int bits
= repBits
[repSymbol
];
166 int count
= input
.peekBits(bits
);
169 input
.dropBits(bits
);
170 count
+= repMin
[repSymbol
];
171 // System.err.println("litdistLens repeated: "+count);
173 if (ptr
+ count
> num
)
174 throw new DataFormatException();
176 litdistLens
[ptr
++] = lastLen
;
185 continue decode_loop
;
190 public InflaterHuffmanTree
buildLitLenTree() throws DataFormatException
192 byte[] litlenLens
= new byte[lnum
];
193 System
.arraycopy(litdistLens
, 0, litlenLens
, 0, lnum
);
194 return new InflaterHuffmanTree(litlenLens
);
197 public InflaterHuffmanTree
buildDistTree() throws DataFormatException
199 byte[] distLens
= new byte[dnum
];
200 System
.arraycopy(litdistLens
, lnum
, distLens
, 0, dnum
);
201 return new InflaterHuffmanTree(distLens
);