FileDocCategorySizeDatePackage
ClassFile.javaAPI DocphoneME MR2 API (J2ME)4998Wed May 02 17:59:48 BST 2007util

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 ) // IMPL_NOTE: consider whether this
                                       // should be fixed 
		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();
	    //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;