Cramfull Compiled Resources v2.00

be.arci.cramfull
Class ClassCompiler

java.lang.Object
  |
  +--be.arci.cramfull.ClassCompiler

public class ClassCompiler
extends java.lang.Object

Encodes resource files and serializable Objects, and compiles them into a Java .class file that is a subclass of Cramfull.

A ClassCompiler instance should be created and invoked through user interfaces like be.arci.pub.ResourceCompiler. Such user interface defines the Cramfull subclass name as well as the collection of resources to be encoded and compiled into that class. The procedure that a user interface to ClassCompiler must follow is simple:

  1. Create an instance of ClassCompiler
  2. Add any needed resources to it, either as files defined in a CompilerEntry object, or as Object to be serialized.
  3. invoke compile

ClassCompiler adheres strictly to Java's class-file format specification: Cramfull subclasses compiled by ClassCompiler pass the strict class-file format checks of JDK13's -Xfuture flag.

Evaluation version

See Also:
ResourceCompiler

Field Summary
static char JOKER
          Matches many char in a filename pattern (the character '*')
static java.lang.String sCopy
          Copyright notice; none of the Cramfull Compiled Resources license types allows you to change this.
static char WILDCARD
          Matches any char in a filename pattern (the character '?')
 
Constructor Summary
ClassCompiler(java.io.File flBaseDir, java.lang.String sOutputClass, boolean swNestedData, boolean swReplace, boolean swVerbose)
          Opens a Cramfull subclass's .class file for writing resources in to.
 
Method Summary
 void addResource(CompilerEntry ce)
          Encodes a resource defined by a CompilerEntry object into the Cramfull subclass.
 void addSerialized(java.lang.String sResourceName, java.lang.String sEncoder, java.lang.Object oSerializable)
          Encodes a serializable object into the Cramfull subclass.
 void compile()
          Compiles the Java methods needed to decode the resources added to the Cramfull subclass, and closes that subclass's .class file.
static boolean matchesWildcardPattern(java.lang.String sFile, java.lang.String sPattern, boolean swIgnoreCase)
          Utility method that performs wildcard filename matches on behalf of user interfaces to ClassCompiler.
 void setVerbose(boolean swVerbose)
          Sets verbose mode on or off
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sCopy

public static final java.lang.String sCopy
Copyright notice; none of the Cramfull Compiled Resources license types allows you to change this.

WILDCARD

public static final char WILDCARD
Matches any char in a filename pattern (the character '?')
See Also:
matchesWildcardPattern(java.lang.String, java.lang.String, boolean)

JOKER

public static final char JOKER
Matches many char in a filename pattern (the character '*')
See Also:
matchesWildcardPattern(java.lang.String, java.lang.String, boolean)
Constructor Detail

ClassCompiler

public ClassCompiler(java.io.File flBaseDir,
                     java.lang.String sOutputClass,
                     boolean swNestedData,
                     boolean swReplace,
                     boolean swVerbose)
              throws java.io.IOException
Opens a Cramfull subclass's .class file for writing resources in to.

Parameters:
flBaseDir - base directory to write the compiled class file in; this directory and a subdirectory tree for the class's package will be created as necessary.
sOutputClass - qualified Java class name for the Cramfull subclass to compile with the resources encoded in it
swNestedData - encode the resource data into a nested class sOutputClass + "$Data" of sOutputClass; this nested class can be garbage collected immediately after sOutputClass is successfully instantiated. This option has no effect in the evaluation version of the Cramfull Compiled Resources library.
swReplace - if the output class exists, it will only be overwritten if this parameter is true.
swVerbose - give a verbose report of the progress of the class file compilation on System.err
Throws:
java.io.IOException - if an error is encountered on writing a Cramfull class
java.lang.IllegalArgumentException - if sOutputClass is null or "".
See Also:
Cramfull
Method Detail

matchesWildcardPattern

public static boolean matchesWildcardPattern(java.lang.String sFile,
                                             java.lang.String sPattern,
                                             boolean swIgnoreCase)
Utility method that performs wildcard filename matches on behalf of user interfaces to ClassCompiler. Returns true if the filename matches the specified sPattern. The sPattern may contain the usual wildcard characters JOKER ('*') and WILDCARD ('?'). Matching can be case sensitive or case insensitive.

Parameters:
sFile - the filename to test
sPattern - the sPattern to match against
swIgnoreCase - if true case is ignored when comparing characters
Returns:
true if sFile matches sPattern.
See Also:
WILDCARD, JOKER

addResource

public void addResource(CompilerEntry ce)
                 throws java.io.IOException
Encodes a resource defined by a CompilerEntry object into the Cramfull subclass.

Parameters:
ce - resource to encode into the Cramfull subclass file. In the evaluation version a maximum of about 100 resources can be encoded in 1 class file, each resource being limited to some 300kB (depending on the encoding and the type of data).
Throws:
java.io.IOException - if an error is encountered on reading a resource file or writing the Cramfull class
java.lang.IllegalArgumentException - if ce == null.
See Also:
addSerialized(java.lang.String, java.lang.String, java.lang.Object),
CompilerEntry

addSerialized

public void addSerialized(java.lang.String sResourceName,
                          java.lang.String sEncoder,
                          java.lang.Object oSerializable)
                   throws java.io.IOException
Encodes a serializable object into the Cramfull subclass.

Objects that are serialized to a file in advance, can also be compiled into a Cramfull subclass just as any other resource file with the addResource(CompilerEntry) method.

Parameters:
sResourceName - name for the resource
sEncoder - qualified class name of the Encoder for the resource
oSerializable - object to serialize and encode into the Cramfull subclass file. In the evaluation version a maximum of about 100 resources or objects can be encoded in 1 class file, each resource or serialized object being limited to some 300kB (depending on the encoding and the type of data).
Throws:
java.io.IOException - if an error is encountered on serializing an object or writing the Cramfull class
See Also:
Cramfull.getDeserialized(String sResource),
addResource(CompilerEntry ce)
,
SerializingResourceCompiler example

compile

public void compile()
             throws java.io.IOException
Compiles the Java methods needed to decode the resources added to the Cramfull subclass, and closes that subclass's .class file.

Throws:
java.io.IOException - if an error is encountered on writing the Cramfull subclass
See Also:
addResource(CompilerEntry ce)

setVerbose

public void setVerbose(boolean swVerbose)
Sets verbose mode on or off

Cramfull Compiled Resources v2.00