flex2.compiler.CompilerAPI.useAS3();
// setup the path resolver
flex2.compiler.CompilerAPI.usePathResolver();
LocalizationManager l10n = new LocalizationManager();
l10n.addLocalizer( new ResourceBundleLocalizer() );
ThreadLocalToolkit.setLocalizationManager(l10n);
flex2.compiler.CompilerAPI.useConsoleLogger();
// create of list of options that we want. All the other options that
// we inherit will be filtered out.
final String[] configVars = new String[]{"help", "version", "load-config", "input", "output",
"compiler.keep-as3-metadata", "compiler.debug"};
Arrays.sort(configVars);
ConfigurationBuffer cfgbuf = new ConfigurationBuffer(OptimizerConfiguration.class,
new HashMap<String, String>(),
new ConfigurationFilter() {
public boolean select(String name)
{
return Arrays.binarySearch(configVars, name) >= 0;
}
});
cfgbuf.setDefaultVar("input");
try
{
DefaultsConfigurator.loadMinimumDefaults(cfgbuf);
OptimizerConfiguration configuration = (OptimizerConfiguration) Mxmlc.processConfiguration(
l10n, "optimizer", args, cfgbuf, OptimizerConfiguration.class, "input", true);
// user is not allowed to control "debug" and "optimize" settings so
// set them here.
configuration.setDebug(configuration.debug());
configuration.setOptimize(true);
//OptimizerConfiguration configuration = (OptimizerConfiguration) processConfiguration(cfgbuf, args, l10n);
String input = configuration.getInput(), output = configuration.getOutput();
File inputFile = FileUtil.openFile(input), outputFile = FileUtil.openFile(output);
if (inputFile.exists())
{
InputStream in = new BufferedInputStream(new FileInputStream(inputFile));
System.out.println(input + " (" + inputFile.length() + " bytes)");
// decoder
Movie movie = new Movie();
TagDecoder tagDecoder = new TagDecoder(in);
MovieDecoder movieDecoder = new MovieDecoder(movie);
tagDecoder.parse(movieDecoder);
if (movie.version > 0) {
// optimize
flex2.tools.WebTierAPI.optimize(movie, configuration);
//TODO PERFORMANCE: A lot of unnecessary recopying and buffering here
// encode
TagEncoder handler = new TagEncoder();
MovieEncoder encoder = new MovieEncoder(handler);
encoder.export(movie, true);
ByteArrayOutputStream out = new ByteArrayOutputStream();
handler.writeTo(out);
FileUtil.writeBinaryFile(output, out.toByteArray());
System.out.println(output + " (" + outputFile.length() + " bytes)");
}
else
{
ThreadLocalToolkit.logError(l10n.getLocalizedTextString(new NotAValidSwfFile(inputFile.getAbsolutePath())));
}
}
}
catch (ConfigurationException ex)