本文整理汇总了Java中com.google.javascript.jscomp.SourceFile.fromInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java SourceFile.fromInputStream方法的具体用法?Java SourceFile.fromInputStream怎么用?Java SourceFile.fromInputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.jscomp.SourceFile
的用法示例。
在下文中一共展示了SourceFile.fromInputStream方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compressJs
import com.google.javascript.jscomp.SourceFile; //导入方法依赖的package包/类
private void compressJs(String sourceName, InputStream in, OutputStream out) throws IOException
{
CompilerOptions options = new CompilerOptions();
CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
SourceFile input = SourceFile.fromInputStream(sourceName, in, Charset.forName("UTF-8"));
com.google.javascript.jscomp.Compiler compiler = new com.google.javascript.jscomp.Compiler();
compiler.compile(Collections.EMPTY_LIST, Collections.singletonList(input), options);
if (compiler.hasErrors())
{
throw new EvaluatorException(compiler.getErrors()[0].description);
}
String compressed = compiler.toSource();
IOUtils.copy(new StringReader(compressed), out);
}
示例2: map
import com.google.javascript.jscomp.SourceFile; //导入方法依赖的package包/类
@Override
public Resource<String> map(Resource<String> resource) {
try {
CompilerOptions options = new CompilerOptions();
config.getCompilationLevel().setOptionsForCompilationLevel(options);
options.setOutputCharset("UTF-8");
options.setLanguageIn(config.getLanguage());
SourceFile input = SourceFile.fromInputStream("dummy.js",
new ByteArrayInputStream(resource.getContent().getBytes(Charsets.UTF_8)));
List<SourceFile> externs = config.getExterns();
Compiler compiler = new Compiler();
compiler.compile(externs, Lists.newArrayList(input), options);
if (compiler.hasErrors()) {
throw new EvaluatorException(compiler.getErrors()[0].description);
}
return new Resource<String>(resource.getMimeType(), compiler.toSource(), StringHasher.instance);
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
}
示例3: compile
import com.google.javascript.jscomp.SourceFile; //导入方法依赖的package包/类
private String compile(HtmlLibrary library, ClosureOptimizationLevel opt, InputStream js) throws IOException {
CompilationLevel compilationLevel = opt.toCompilationLevel();
if (null == compilationLevel) {
// return original input
return IOUtils.toString(js);
}
SourceFile input = SourceFile.fromInputStream(getLibraryName(library), js);
// TODO externs not supported, should avoid ADVANCED compilation
SourceFile extern = SourceFile.fromCode("TODO", StringUtils.EMPTY);
CompilerOptions options = new CompilerOptions();
compilationLevel.setOptionsForCompilationLevel(options);
// ES5 assumption to allow getters/setters
options.setLanguageIn(CompilerOptions.LanguageMode.ECMASCRIPT5);
Compiler compiler = new Compiler();
compiler.compile(extern, input, options);
return compiler.toSource();
}
示例4: minify
import com.google.javascript.jscomp.SourceFile; //导入方法依赖的package包/类
/**
* Minifies the JS contents from the given merged file into the minified file
*
* <p>
* Minification is performed using the Google Closure compiler, using
* com.google.javascript.jscomp.CompilationLevel#WHITESPACE_ONLY and EcmaScript5 language level
* </p>
*
* @see ThemeFilesProcessor#minify(java.io.File, java.io.File)
* @see com.google.javascript.jscomp.Compiler
*/
@Override
protected void minify(File mergedFile, File minifiedFile) throws IOException {
InputStream in = null;
OutputStream out = null;
OutputStreamWriter writer = null;
InputStreamReader reader = null;
LOG.info("Populating minified JS file: " + minifiedFile.getPath());
try {
out = new FileOutputStream(minifiedFile);
writer = new OutputStreamWriter(out);
in = new FileInputStream(mergedFile);
reader = new InputStreamReader(in);
CompilerOptions options = new CompilerOptions();
CompilationLevel.WHITESPACE_ONLY.setOptionsForCompilationLevel(options);
options.setLanguageIn(CompilerOptions.LanguageMode.ECMASCRIPT6);
options.setExtraAnnotationNames(ignoredAnnotations());
SourceFile input = SourceFile.fromInputStream(mergedFile.getName(), in);
List<SourceFile> externs = Collections.emptyList();
Compiler compiler = new Compiler();
compiler.compile(externs, Arrays.asList(input), options);
writer.append(compiler.toSource());
writer.flush();
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
}
示例5: createInputs
import com.google.javascript.jscomp.SourceFile; //导入方法依赖的package包/类
@Override
protected List<SourceFile> createInputs(
List<FlagEntry<JsSourceType>> files,
List<JsonFileSpec> jsonFiles,
boolean allowStdIn,
List<JsModuleSpec> jsModuleSpecs)
throws IOException {
// Compiler defaults to reading from stdin if no files specified, but we don't support that.
if (files.size() == 1 && "-".equals(files.get(0).getValue())) {
return ImmutableList.of();
}
ImmutableList.Builder<SourceFile> inputs = ImmutableList.builder();
for (FlagEntry<JsSourceType> flagEntry : files) {
checkArgument(
flagEntry.getFlag() != JsSourceType.JS_ZIP,
"Zip file inputs are not supported: %s",
flagEntry.getValue());
checkArgument(!"-".equals(flagEntry.getValue()), "Reading from stdin is not supported");
Path path = inputFileSystem.getPath(flagEntry.getValue());
try (InputStream inputStream = newInputStream(path)) {
SourceFile file = SourceFile.fromInputStream(path.toString(), inputStream, UTF_8);
inputs.add(file);
}
}
return inputs.build();
}