From 0a12c1ea5a1d25d057addc0709da5db0e41ec64a Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 29 Oct 2011 20:19:53 +0000 Subject: [PATCH] * minor changes --- source/net/sourceforge/filebot/MediaTypes.java | 14 +++++++++++++- .../filebot/format/ExpressionFormat.java | 6 ++---- source/net/sourceforge/tuned/FileUtilities.java | 13 +++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) 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();