FileDocCategorySizeDatePackage
ClassFile.javaAPI DocJ2ME CLDC 1.14487Wed Feb 05 15:56:04 GMT 2003util

ClassFile

public class ClassFile extends Object

Fields Summary
public String
fileName
public boolean
didRead
public Exception
failureMode
public boolean
verbose
public ClassInfo
clas
PrintStream
log
InputStream
istream
int
minorID
int
majorID
Constructors Summary
public ClassFile(String name, boolean v)


          
    fileName = name;
    verbose     = v;
    clas     = new ClassInfo( v );
    istream  = null;
    
public ClassFile(String name, InputStream i, boolean v)

    fileName = name;
    verbose     = v;
    clas     = new ClassInfo( v );
    istream  = i;
    
Methods Summary
public voiddump(java.io.PrintStream o)

    o.println(Localizer.getString("classfile.file", fileName));
    if ( ! didRead ){
        o.println(Localizer.getString(
              "classfile.could_not_be_read_because_of", 
              failureMode));
        if ( failureMode != null ) // stupid.
        failureMode.printStackTrace( o );
        return;
    }
    clas.dump( o );
    
public static voidmain(java.lang.String[] clist)

    for( int i = 0; i < clist.length; i++ ){
        ClassFile f = new ClassFile( clist[i], true );
        if (f.readClassFile( null ) != true ){
        System.out.println(Localizer.getString(
                        "classfile.read_of",
                        clist[i]));
        f.dump( System.out );
        continue;
        }
        f.clas.countReferences( true );
        f.dump( System.out );
    }
    
public booleanreadClassFile(ConstantPool t)

    DataInputStream in = null;
    failureMode = null;
    done:
    try {
        int magic;
        if ( istream == null ){
        istream = new java.io.BufferedInputStream( new java.io.FileInputStream( fileName ) );
        }
        in = new DataInputStream( istream );
        if ((magic = in.readInt()) != Const.JAVA_MAGIC) {
        failureMode = new IOException(Localizer.getString("classfile.bad_magic.ioexception"));
        break done; // bad magic -- bail immediately.
        }

        minorID = in.readShort();
        majorID = in.readShort();

            /* Ignore the major and minor versions for JDK 1.4 compatibility */

            /*
        if (minorID != Const.JAVA_MINOR_VERSION) {
        failureMode = new IOException(Localizer.getString("classfile.bad_minor_version_number.ioexception"));
        break done; // bad magic -- bail immediately.
        }

        if (majorID != Const.JAVA_VERSION) {
        failureMode = new IOException(Localizer.getString("classfile.bad_major_version_number.ioexception"));
        break done; // bad magic -- bail immediately.
        }
            */

        if(verbose){
        log.println(Localizer.getString("classfile._file", fileName)+
                Localizer.getString("classfile._magic/major/minor",
                                        Integer.toHexString( magic ),
                                        Integer.toHexString( majorID ),
                                        Integer.toHexString( minorID )));
        }
        clas.read( in, true, t );
        didRead = true;
    } catch ( Exception e ){
        failureMode = e;
    }
    if ( in != null ){
        try{
        in.close();
        } catch ( IOException e ){
        if (didRead==true){
            didRead=false;
            failureMode=e;
        }
        }
    }
    return didRead;