* minor changes

This commit is contained in:
Reinhard Pointner 2011-10-29 20:19:53 +00:00
parent d77adc6776
commit 0a12c1ea5a
3 changed files with 28 additions and 5 deletions

View File

@ -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<String, ExtensionFileFilter> filters = synchronizedMap(new HashMap<String, ExtensionFileFilter>());
public List<String> getExtensionList(String name) {
List<String> list = new ArrayList<String>();
@ -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;
}

View File

@ -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;

View File

@ -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();