diff --git a/source/net/sourceforge/filebot/MediaTypes.java b/source/net/sourceforge/filebot/MediaTypes.java index 0c55b6a0..5b8b6f3e 100644 --- a/source/net/sourceforge/filebot/MediaTypes.java +++ b/source/net/sourceforge/filebot/MediaTypes.java @@ -6,7 +6,9 @@ import static java.util.Collections.*; import java.io.FileFilter; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; @@ -48,6 +50,9 @@ public class MediaTypes { } + private Map filters = synchronizedMap(new HashMap()); + + public List getExtensionList(String name) { List list = new ArrayList(); @@ -62,7 +67,14 @@ public class MediaTypes { public FileFilter getFilter(String name) { - return new ExtensionFileFilter(getExtensionList(name)); + ExtensionFileFilter filter = filters.get(name); + + if (filter == null) { + filter = new ExtensionFileFilter(getExtensionList(name)); + filters.put(name, filter); + } + + return filter; } diff --git a/source/net/sourceforge/filebot/format/ExpressionFormat.java b/source/net/sourceforge/filebot/format/ExpressionFormat.java index c3e45dcb..0aff5436 100644 --- a/source/net/sourceforge/filebot/format/ExpressionFormat.java +++ b/source/net/sourceforge/filebot/format/ExpressionFormat.java @@ -54,11 +54,9 @@ public class ExpressionFormat extends Format { protected ScriptEngine initScriptEngine() throws ScriptException { - // use groovy script engine + // use Groovy script engine ScriptEngine engine = new GroovyScriptEngineFactory().getScriptEngine(); - engine.eval(new InputStreamReader(ExpressionFormat.class.getResourceAsStream("ExpressionFormat.lib.groovy"))); - return engine; } @@ -159,7 +157,7 @@ public class ExpressionFormat extends Format { // initialize script context with the privileged bindings ScriptContext context = new SimpleScriptContext(); - context.setBindings(priviledgedBindings, ScriptContext.GLOBAL_SCOPE); + context.setBindings(priviledgedBindings, ScriptContext.ENGINE_SCOPE); // reset exception state lastException = null; diff --git a/source/net/sourceforge/tuned/FileUtilities.java b/source/net/sourceforge/tuned/FileUtilities.java index 4531c995..6f777d3f 100644 --- a/source/net/sourceforge/tuned/FileUtilities.java +++ b/source/net/sourceforge/tuned/FileUtilities.java @@ -73,6 +73,19 @@ public final class FileUtilities { } + public static String readAll(Reader source) throws IOException { + StringBuilder text = new StringBuilder(); + char[] buffer = new char[2048]; + + int read = 0; + while ((read = source.read(buffer)) >= 0) { + text.append(buffer, 0, read); + } + + return text.toString(); + } + + public static void writeFile(ByteBuffer data, File destination) throws IOException { FileChannel fileChannel = new FileOutputStream(destination).getChannel();