Rebasing the Inflater support on jzlib which, unlike GNU ClassPath, has correct implementation of Huffman code. Making the implementation more easily testable by turning Inflater and ZipInputStream into pure delegates. Current implementation is going to need proper long support.
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
26 package org.apidesign.javap;
28 import static org.apidesign.javap.RuntimeConstants.ITEM_Bogus;
29 import static org.apidesign.javap.RuntimeConstants.ITEM_Integer;
30 import static org.apidesign.javap.RuntimeConstants.ITEM_Float;
31 import static org.apidesign.javap.RuntimeConstants.ITEM_Double;
32 import static org.apidesign.javap.RuntimeConstants.ITEM_Long;
33 import static org.apidesign.javap.RuntimeConstants.ITEM_Null;
34 import static org.apidesign.javap.RuntimeConstants.ITEM_InitObject;
35 import static org.apidesign.javap.RuntimeConstants.ITEM_Object;
36 import static org.apidesign.javap.RuntimeConstants.ITEM_NewObject;
38 public final class TypeArray {
39 private static final int CAPACITY_INCREMENT = 16;
47 public TypeArray(final TypeArray initialTypes) {
51 public void add(final int newType) {
52 ensureCapacity(size + 1);
53 types[size++] = newType;
56 public void addAll(final TypeArray newTypes) {
57 addAll(newTypes.types, 0, newTypes.size);
60 public void addAll(final int[] newTypes) {
61 addAll(newTypes, 0, newTypes.length);
64 public void addAll(final int[] newTypes,
68 ensureCapacity(size + count);
69 arraycopy(newTypes, offset, types, size, count);
74 public void set(final int index, final int newType) {
75 types[index] = newType;
78 public void setAll(final TypeArray newTypes) {
79 setAll(newTypes.types, 0, newTypes.size);
82 public void setAll(final int[] newTypes) {
83 setAll(newTypes, 0, newTypes.length);
86 public void setAll(final int[] newTypes,
90 ensureCapacity(count);
91 arraycopy(newTypes, offset, types, 0, count);
98 public void setSize(final int newSize) {
99 if (size != newSize) {
100 ensureCapacity(newSize);
102 for (int i = size; i < newSize; ++i) {
109 public void clear() {
113 public int getSize() {
117 public int get(final int index) {
121 public static String typeString(final int type) {
122 switch (type & 0xff) {
135 case ITEM_InitObject: // UninitializedThis
139 case ITEM_NewObject: // Uninitialized
142 throw new IllegalArgumentException("Unknown type");
147 public String toString() {
148 final StringBuilder sb = new StringBuilder("[");
150 sb.append(typeString(types[0]));
151 for (int i = 1; i < size; ++i) {
153 sb.append(typeString(types[i]));
157 return sb.append(']').toString();
160 private void ensureCapacity(final int minCapacity) {
161 if ((minCapacity == 0)
162 || (types != null) && (minCapacity <= types.length)) {
166 final int newCapacity =
167 ((minCapacity + CAPACITY_INCREMENT - 1) / CAPACITY_INCREMENT)
168 * CAPACITY_INCREMENT;
169 final int[] newTypes = new int[newCapacity];
172 arraycopy(types, 0, newTypes, 0, size);
178 // no System.arraycopy
179 private void arraycopy(final int[] src, final int srcPos,
180 final int[] dest, final int destPos,
182 for (int i = 0; i < length; ++i) {
183 dest[destPos + i] = src[srcPos + i];