FileDocCategorySizeDatePackage
MultiClass.javaAPI DocJ2ME CLDC 1.15751Wed Feb 05 15:56:02 GMT 2003jcc

MultiClass

public class MultiClass extends Object

Fields Summary
public String
fileName
public boolean
didRead
public Exception
failureMode
public boolean
verbose
PrintStream
log
InputStream
istream
public ConstantPool
consts
public ClassInfo[]
classes
public static final int
MULTICLASS_MAGIC
static final short
MAJOR
static final short
MINOR
Constructors Summary
public MultiClass(ConstantPool p, ClassInfo[] c, boolean v)


    // create from a collection of classes we read elsewhere
            
    consts  = p;
    classes = c;
    verbose = v;
    
public MultiClass(String name, ConstantPool p, boolean v)

    fileName = name;
    consts   = p;
    verbose  = v;
    istream  = null;
    
public MultiClass(String name, InputStream i, ConstantPool p, boolean v)

    fileName = name;
    consts   = p;
    verbose  = v;
    istream  = i;
    
Methods Summary
public voiddump(java.io.PrintStream o)

    o.println(Localizer.getString("multiclass.file", fileName));
    if ( failureMode != null ){
        o.println(Localizer.getString("multiclass.could_not_be_read_because_of"));
        failureMode.printStackTrace( o );
        return;
    }
    o.println(Localizer.getString("multiclass.shared_constant_table"));
    consts.dump(o);
    o.println(Localizer.getString("multiclass.classes"));
    for( int i = 0; i < classes.length; i++ ){
        classes[i].dump(o);
    }
    
public voidoutputMultiClass(java.io.DataOutputStream out)

    // write header info
    writeHeader( out );
    // write constant pool
    consts.write( out );
    int  nclasses = classes.length;
    // write classes
    out.writeShort(nclasses);
    for( int i = 0; i < nclasses; i++ ){
        classes[i].write(out);
    }
    out.close();
    
voidreadHeader(java.io.DataInput in)

    int    magic;
    int    minor;
    int    major;
    if ((magic = in.readInt()) != MULTICLASS_MAGIC) {
        throw new IOException(Localizer.getString("multiclass.bad_magic.ioexception"));
    }
    minor = in.readShort();
    major = in.readShort();
    if (minor != MINOR) {
        throw new IOException(Localizer.getString("multiclass.bad_minor_version_number.ioexception"));
    }
    if (major != MAJOR) {
        throw new IOException(Localizer.getString("multiclass.bad_major_version_number.ioexception"));
    }
    if(verbose){
        log.println(Localizer.getString(
               "multiclass.multiclass", fileName)+
            Localizer.getString("multiclass._magic/major/minor",
                        Integer.toHexString( magic ),
                        Integer.toHexString( major ),
                        Integer.toHexString( minor )));
    }
    
public booleanreadMultiClassFile()

    boolean myConstPool = false;
    DataInputStream in = null;
    failureMode = null;
    didRead = false;
    if ( consts == null ){
        consts = new ConstantPool();
        myConstPool = true;
    }
    try {
        if ( istream == null ){
        istream = new java.io.BufferedInputStream( new java.io.FileInputStream( fileName ) );
        }
        in = new DataInputStream( istream );
        readHeader( in );
        int n = consts.read( in );
        if ( verbose ){
        System.out.println(Localizer.getString(
                   "multiclass.symbols_into_constant_pool", 
                   Integer.toString(n)));
        }
        //consts.dump( System.out );//DEBUG
        if ( myConstPool )
        consts.lock();
        n = in.readUnsignedShort( );
        if (verbose){
        System.out.println(Localizer.getString(
                   "multiclass.reading_classes",
                    Integer.toString(n)));
        }
        classes = new ClassInfo[n];
        for( int i = 0; i < n; i++ ){
        classes[i] = new ClassInfo( verbose );
            classes[i].readMultiClass( in, true, consts );
        }
        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;
    
static voidwriteHeader(java.io.DataOutput o)

    o.writeInt( MULTICLASS_MAGIC );
    o.writeShort( MINOR );
    o.writeShort( MAJOR );
    
public booleanwriteMultiClass(java.lang.String fileName)

    java.io.DataOutputStream out;
    try {
        out = new java.io.DataOutputStream( new java.io.BufferedOutputStream( new java.io.FileOutputStream( fileName ) ) );
        outputMultiClass( out );
        return true;
    } catch ( IOException e ){
        System.err.println(Localizer.getString("multiclass.writing",
                fileName));
        e.printStackTrace();
        return false;
    }