jdk/test/com/sun/jdi/ConstantPoolInfo.java
author jjg
Thu, 22 May 2008 15:51:41 -0700
changeset 655 1ebc7ce89018
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6705945: com.sun.tools.javac.zip files do not have valid copyright Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2005 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 *  @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 *  @bug 5024104
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *  @summary Test ReferenceType.majorVersion(), minorVersion, constantPoolCount and ConstantPool apis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *  @author Swamy Venkataramanappa
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *  @run build TestScaffold VMConnection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *  @run compile -g ConstantPoolInfo.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *  @run main ConstantPoolInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /********** target program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
class ConstantPoolTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public static void main(String[] args){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        System.out.println("Howdy!"); // don't change the string value "Howdy!" it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
                                      // used to test the constant pool entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /********** test program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public class ConstantPoolInfo extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    ReferenceType targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    ThreadReference mainThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    int cpool_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    byte[] cpbytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    static int expectedMajorVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static int expectedMinorVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    static int expectedCpoolCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /* Class File Constants */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static final int JAVA_MAGIC                   = 0xcafebabe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /* Constant table :  copied from sun/javap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public static final int CONSTANT_UTF8                = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public static final int CONSTANT_UNICODE             = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public static final int CONSTANT_INTEGER             = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public static final int CONSTANT_FLOAT               = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public static final int CONSTANT_LONG                = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public static final int CONSTANT_DOUBLE              = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public static final int CONSTANT_CLASS               = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public static final int CONSTANT_STRING              = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public static final int CONSTANT_FIELD               = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public static final int CONSTANT_METHOD              = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public static final int CONSTANT_INTERFACEMETHOD     = 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public static final int CONSTANT_NAMEANDTYPE         = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    ConstantPoolInfo (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        new ConstantPoolInfo(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /********** test core **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
         * to determine targetClass and mainThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        BreakpointEvent bpe = startToMain("ConstantPoolTarg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        targetClass = bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        mainThread = bpe.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        String targPathname = System.getProperty("test.classes") + File.separator + "ConstantPoolTarg.class";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        readClassData(new FileInputStream(targPathname));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        /* Test constant pool apis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (vm().canGetClassFileVersion()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            if (expectedMajorVersion != targetClass.majorVersion()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                failure("unexpected major version: actual value: " + targetClass.majorVersion()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                        + "expected value :" + expectedMajorVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            if (expectedMinorVersion != targetClass.minorVersion()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                failure("unexpected minor version: actual value: " + targetClass.minorVersion()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                        + "expected value :" + expectedMinorVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            System.out.println("can get class version not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (vm().canGetConstantPool()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            cpool_count = targetClass.constantPoolCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            cpbytes = targetClass.constantPool();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                printcp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            } catch (IOException x){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                System.out.println("IOexception reading cpool bytes " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            if (expectedCpoolCount != cpool_count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                failure("unexpected constant pool count: actual value: " + cpool_count
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                        + "expected value :" + expectedCpoolCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            System.out.println("can get constant pool version not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
         * resume until end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
         * deal with results of test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
         * if anything has called failure("foo") testFailed will be true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            println("ConstantPoolInfo: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            throw new Exception("ConstantPoolInfo: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public void printcp() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        boolean found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        ByteArrayInputStream bytesStream = new ByteArrayInputStream(cpbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        DataInputStream in = new DataInputStream(bytesStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        for (int i = 1; i < cpool_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            int tag = in.readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            System.out.print("const #" + i + ":   ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            switch(tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    case CONSTANT_UTF8:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    String str=in.readUTF();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    System.out.println("Asciz " + str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    // "Howdy!" is an expected constant pool entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    // of test program. It should exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    if (str.compareTo("Howdy!") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                        found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                case CONSTANT_INTEGER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    System.out.println("int " + in.readInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                case CONSTANT_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    System.out.println("Float " + in.readFloat());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                case CONSTANT_LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                    System.out.println("Long " + in.readLong());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                case CONSTANT_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                    System.out.println("Double " + in.readDouble());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                case CONSTANT_CLASS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    System.out.println("Class " + in.readUnsignedShort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                case CONSTANT_STRING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    System.out.println("String " + in.readUnsignedShort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                case CONSTANT_FIELD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    System.out.println("Field " + in.readUnsignedShort() + " " + in.readUnsignedShort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                case CONSTANT_METHOD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    System.out.println("Method " + in.readUnsignedShort() + " " + in.readUnsignedShort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                case CONSTANT_INTERFACEMETHOD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    System.out.println("InterfaceMethod " + in.readUnsignedShort() + " " + in.readUnsignedShort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                case CONSTANT_NAMEANDTYPE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    System.out.println("NameAndType " + in.readUnsignedShort() + " " + in.readUnsignedShort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    System.out.println("class format error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (!found) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            failure("expected string \"Howdy!\" not found in constant pool");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Read classfile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    void readClassData(InputStream infile){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        try{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            this.read(new DataInputStream(infile));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }catch (FileNotFoundException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            failure("cant read file");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }catch (Error ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            ee.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            failure("fatal error");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        } catch (Exception ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            ee.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            failure("fatal exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
         * Read major, minor and cp count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public void read(DataInputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        int magic = in.readInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (magic != JAVA_MAGIC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            failure("fatal bad class file format");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        expectedMinorVersion = in.readShort();;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        expectedMajorVersion = in.readShort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        expectedCpoolCount = in.readUnsignedShort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    } // end read()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
}