01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.harmony.pack200;
18:
19: import java.io.IOException;
20: import java.io.InputStream;
21:
22: /**
23: *
24: */
25: public class AttrDefinitionBands extends BandSet {
26:
27: private int[] attributeDefinitionHeader;
28:
29: private String[] attributeDefinitionLayout;
30:
31: private String[] attributeDefinitionName;
32:
33: private AttributeLayoutMap attributeDefinitionMap;
34:
35: private String[] cpUTF8;
36:
37: public AttrDefinitionBands(Segment segment) {
38: super (segment);
39: this .cpUTF8 = segment.getCpBands().getCpUTF8();
40: }
41:
42: /* (non-Javadoc)
43: * @see org.apache.harmony.pack200.BandSet#unpack(java.io.InputStream)
44: */
45: public void unpack(InputStream in) throws IOException,
46: Pack200Exception {
47: int attributeDefinitionCount = header
48: .getAttributeDefinitionCount();
49: attributeDefinitionHeader = decodeBandInt(
50: "attr_definition_headers", in, Codec.BYTE1,
51: attributeDefinitionCount);
52: attributeDefinitionName = parseReferences(
53: "attr_definition_name", in, Codec.UNSIGNED5,
54: attributeDefinitionCount, cpUTF8);
55: attributeDefinitionLayout = parseReferences(
56: "attr_definition_layout", in, Codec.UNSIGNED5,
57: attributeDefinitionCount, cpUTF8);
58:
59: attributeDefinitionMap = new AttributeLayoutMap();
60:
61: int overflowIndex = 32;
62: if (segment.getSegmentHeader().getOptions().hasClassFlagsHi()) {
63: overflowIndex = 63;
64: }
65: for (int i = 0; i < attributeDefinitionCount; i++) {
66: int context = attributeDefinitionHeader[i] & 0x03;
67: int index = (attributeDefinitionHeader[i] >> 2) - 1;
68: if (index == -1) {
69: index = overflowIndex++;
70: }
71: AttributeLayout layout = new AttributeLayout(
72: attributeDefinitionName[i], context,
73: attributeDefinitionLayout[i], index, false);
74: NewAttributeBands newBands = new NewAttributeBands(segment,
75: layout);
76: attributeDefinitionMap.add(layout, newBands);
77: }
78: attributeDefinitionMap.checkMap();
79: }
80:
81: public AttributeLayoutMap getAttributeDefinitionMap() {
82: return attributeDefinitionMap;
83: }
84:
85: }
|