1 | /* |
2 | |
3 | Derby - Class org.apache.derby.iapi.services.classfile.AttributeEntry |
4 | |
5 | Copyright 2000, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.iapi.services.classfile; |
22 | |
23 | import java.io.IOException; |
24 | |
25 | class AttributeEntry { |
26 | |
27 | private int attribute_name_index; |
28 | private ClassFormatOutput infoOut; |
29 | byte[] infoIn; |
30 | |
31 | AttributeEntry(int name_index, ClassFormatOutput info) { |
32 | super(); |
33 | |
34 | attribute_name_index = name_index; |
35 | this.infoOut = info; |
36 | } |
37 | |
38 | |
39 | AttributeEntry(ClassInput in) throws IOException { |
40 | attribute_name_index = in.getU2(); |
41 | infoIn = in.getU1Array(in.getU4()); |
42 | } |
43 | |
44 | int getNameIndex() { return attribute_name_index; } |
45 | |
46 | void put(ClassFormatOutput out) throws IOException { |
47 | out.putU2(attribute_name_index); |
48 | if (infoOut != null) { |
49 | out.putU4(infoOut.size()); |
50 | infoOut.writeTo(out); |
51 | } else { |
52 | out.putU4(infoIn.length); |
53 | out.write(infoIn); |
54 | } |
55 | } |
56 | |
57 | /** |
58 | This is exact. |
59 | */ |
60 | int classFileSize() { |
61 | return 2 + 4 + |
62 | ((infoOut != null) ? infoOut.size() : infoIn.length); |
63 | } |
64 | } |