use of java.io.Reader in project hackpad by dropbox.
the class CachingModuleScriptProviderBase method getModuleScript.
public ModuleScript getModuleScript(Context cx, String moduleId, URI moduleUri, Scriptable paths) throws Exception {
final CachedModuleScript cachedModule1 = getLoadedModule(moduleId);
final Object validator1 = getValidator(cachedModule1);
final ModuleSource moduleSource = (moduleUri == null) ? moduleSourceProvider.loadSource(moduleId, paths, validator1) : moduleSourceProvider.loadSource(moduleUri, validator1);
if (moduleSource == ModuleSourceProvider.NOT_MODIFIED) {
return cachedModule1.getModule();
}
if (moduleSource == null) {
return null;
}
final Reader reader = moduleSource.getReader();
try {
final int idHash = moduleId.hashCode();
synchronized (loadLocks[(idHash >>> loadLockShift) & loadLockMask]) {
final CachedModuleScript cachedModule2 = getLoadedModule(moduleId);
if (cachedModule2 != null) {
if (!equal(validator1, getValidator(cachedModule2))) {
return cachedModule2.getModule();
}
}
final URI sourceUri = moduleSource.getUri();
final ModuleScript moduleScript = new ModuleScript(cx.compileReader(reader, sourceUri.toString(), 1, moduleSource.getSecurityDomain()), sourceUri, moduleSource.getBase());
putLoadedModule(moduleId, moduleScript, moduleSource.getValidator());
return moduleScript;
}
} finally {
reader.close();
}
}
use of java.io.Reader in project elasticsearch by elastic.
the class MustacheScriptEngineService method compile.
/**
* Compile a template string to (in this case) a Mustache object than can
* later be re-used for execution to fill in missing parameter values.
*
* @param templateSource a string representing the template to compile.
* @return a compiled template object for later execution.
* */
@Override
public Object compile(String templateName, String templateSource, Map<String, String> params) {
final MustacheFactory factory = createMustacheFactory(params);
Reader reader = new FastStringReader(templateSource);
return factory.compile(reader, "query-template");
}
use of java.io.Reader in project elasticsearch by elastic.
the class IcuTokenizerFactoryTests method testIcuCustomizeRuleFile.
public void testIcuCustomizeRuleFile() throws IOException {
TestAnalysis analysis = createTestAnalysis();
// test the tokenizer with single rule file
TokenizerFactory tokenizerFactory = analysis.tokenizer.get("user_rule_tokenizer");
ICUTokenizer tokenizer = (ICUTokenizer) tokenizerFactory.create();
Reader reader = new StringReader("One-two punch. Brang-, not brung-it. This one--not that one--is the right one, -ish.");
tokenizer.setReader(reader);
assertTokenStreamContents(tokenizer, new String[] { "One-two", "punch", "Brang", "not", "brung-it", "This", "one", "not", "that", "one", "is", "the", "right", "one", "ish" });
}
use of java.io.Reader in project elasticsearch by elastic.
the class IcuTokenizerFactoryTests method testSimpleIcuTokenizer.
public void testSimpleIcuTokenizer() throws IOException {
TestAnalysis analysis = createTestAnalysis();
TokenizerFactory tokenizerFactory = analysis.tokenizer.get("icu_tokenizer");
ICUTokenizer tokenizer = (ICUTokenizer) tokenizerFactory.create();
Reader reader = new StringReader("向日葵, one-two");
tokenizer.setReader(reader);
assertTokenStreamContents(tokenizer, new String[] { "向日葵", "one", "two" });
}
use of java.io.Reader in project che by eclipse.
the class JavadocContentAccess2 method getContentsFromInputStream.
private static String getContentsFromInputStream(InputStream in, String encoding) throws CoreException {
final int defaultFileSize = 15 * 1024;
StringBuffer buffer = new StringBuffer(defaultFileSize);
Reader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(in, encoding), defaultFileSize);
char[] readBuffer = new char[2048];
int charCount = reader.read(readBuffer);
while (charCount > 0) {
buffer.append(readBuffer, 0, charCount);
charCount = reader.read(readBuffer);
}
} catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, "JavaPlugin.getPluginId()", e.getMessage(), e));
} finally {
try {
if (reader != null) {
//this will also close the InputStream wrapped in the reader
reader.close();
}
} catch (IOException e) {
//ignore
}
}
return buffer.toString();
}
Aggregations