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.bytecode;
18:
19: import java.io.DataOutputStream;
20: import java.io.IOException;
21:
22: public class ClassFile {
23: public int major;
24: public int minor;
25: private int magic = 0xCAFEBABE;
26: public ClassConstantPool pool = new ClassConstantPool();
27: public int accessFlags;
28: public int this Class;
29: public int super Class;
30: public int[] interfaces;
31: public ClassFileEntry[] fields;
32: public ClassFileEntry[] methods;
33: public Attribute[] attributes;
34:
35: public void write(DataOutputStream dos) throws IOException {
36: dos.writeInt(magic);
37: dos.writeShort(minor);
38: dos.writeShort(major);
39: dos.writeShort(pool.size() + 1);
40: for (int i = 1; i <= pool.size(); i++) {
41: ConstantPoolEntry entry;
42: (entry = (ConstantPoolEntry) pool.get(i)).doWrite(dos);
43: // Doubles and longs take up two spaces in the pool, but only one gets written
44: if (entry.getTag() == ConstantPoolEntry.CP_Double
45: || entry.getTag() == ConstantPoolEntry.CP_Long)
46: i++;
47: }
48: ;
49: dos.writeShort(accessFlags);
50: dos.writeShort(this Class);
51: dos.writeShort(super Class);
52: dos.writeShort(interfaces.length);
53: for (int i = 0; i < interfaces.length; i++) {
54: dos.writeShort(interfaces[i]);
55: }
56: dos.writeShort(fields.length);
57: for (int i = 0; i < fields.length; i++) {
58: fields[i].write(dos);
59: }
60: dos.writeShort(methods.length);
61: for (int i = 0; i < methods.length; i++) {
62: methods[i].write(dos);
63: }
64: dos.writeShort(attributes.length);
65: for (int i = 0; i < attributes.length; i++) {
66: attributes[i].write(dos);
67: }
68: }
69: }
|