当前位置: 首页>>代码示例>>Java>>正文


Java JavaScriptCompressor.compress方法代码示例

本文整理汇总了Java中com.yahoo.platform.yui.compressor.JavaScriptCompressor.compress方法的典型用法代码示例。如果您正苦于以下问题:Java JavaScriptCompressor.compress方法的具体用法?Java JavaScriptCompressor.compress怎么用?Java JavaScriptCompressor.compress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.yahoo.platform.yui.compressor.JavaScriptCompressor的用法示例。


在下文中一共展示了JavaScriptCompressor.compress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: compressJavaScript

import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入方法依赖的package包/类
public void compressJavaScript(Path input, Path output) throws IOException {
    // yui compressor chokes on empty files
    long size = Files.size(input);
    if (size == 0) {
        if (!Files.exists(output)) {
            Files.createFile(output);
        }
        return;
    }

    Options o = new Options();
    try (Reader in = Files.newBufferedReader(input, Charset.forName(o.charset));
         Writer out = Files.newBufferedWriter(output, Charset.forName(o.charset))) {

        JavaScriptCompressor compressor = new JavaScriptCompressor(in, new YuiCompressorErrorReporter());
        compressor.compress(out, o.lineBreakPos, o.munge, o.verbose, o.preserveAllSemiColons, o.disableOptimizations);
    }
}
 
开发者ID:marcobehler,项目名称:saito,代码行数:19,代码来源:YuiWrapper.java

示例2: compressJavaScript

import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入方法依赖的package包/类
public void compressJavaScript(final File inputFile, final File outputFile, final YuiCompressorOptions o) throws IOException {
	Reader in = null;
	Writer out = null;
	try {
		in = new InputStreamReader(new FileInputStream(inputFile), o.charset);

		final JavaScriptCompressor compressor = new JavaScriptCompressor(in, new YuiCompressorErrorReporter());
		in.close();
		in = null;

		out = new OutputStreamWriter(new FileOutputStream(outputFile, true), o.charset);
		compressor.compress(out, o.lineBreakPos, o.munge, o.verbose, o.preserveAllSemiColons, o.disableOptimizations);
	} finally {
		IOUtils.closeQuietly(in);
		IOUtils.closeQuietly(out);
	}
}
 
开发者ID:rii-mango,项目名称:Papaya-Builder,代码行数:18,代码来源:Builder.java

示例3: cleanupJavaScript

import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入方法依赖的package包/类
/**
 * Javascript compression method, based on yuiCompressor
 * @param content uncompressed JavaScript
 * @return A compressed JavaScript 
 */
public static String cleanupJavaScript(String content) {
	int length = content.length();
	int firstlinefeed = content.indexOf("\n");
	if (firstlinefeed==-1 || (length>255 && firstlinefeed>255)){
		//script seems to be already minified=> skip
		return content;
	}
	Reader reader = new StringReader(content);
	Writer writer = new StringWriter();		
	try {
		JavaScriptCompressor jsc = new JavaScriptCompressor(reader,jsReporter);
		jsc.compress(writer, -1, true, false, false, false);
	    //options: (int linebreak, boolean munge, boolean verbose, boolean preserveAllSemiColons, boolean disableOptimizations)
	} catch (Exception e) {
		return content;
	}
	return writer.toString();				
}
 
开发者ID:jburnim,项目名称:GreasySpoon,代码行数:24,代码来源:Compressor.java

示例4: compressJavaScript

import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入方法依赖的package包/类
@Override
public String compressJavaScript(String script) throws Exception {
    StringReader stringReader = new StringReader(script);
    JavaScriptCompressor javaScriptCompressor = new JavaScriptCompressor(stringReader, new YUIErrorReporter());
    StringWriter stringWriter = new StringWriter();
    javaScriptCompressor.compress(stringWriter, linebreak, munge, verbose, preserveAllSemiColons, disableOptimizations);
    String compressedScript = stringWriter.toString();
    return compressedScript;
}
 
开发者ID:devefx,项目名称:validator-web,代码行数:10,代码来源:YUICompressor.java

示例5: compressJavaScript

import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入方法依赖的package包/类
public String compressJavaScript(String script) throws IOException
{
    StringReader stringReader = new StringReader(script);
    JavaScriptCompressor yuiJavaScriptCompressor = new JavaScriptCompressor(stringReader, new YahooJSErrorReporter());
    StringWriter stringWriter = new StringWriter();
    yuiJavaScriptCompressor.compress(stringWriter, (Integer) compressorParameters.get(PARAMETER_LINEBREAK), (Boolean) compressorParameters.get(PARAMETER_MUNGE),
            (Boolean) compressorParameters.get(PARAMETER_VERBOSE), (Boolean) compressorParameters.get(PARAMETER_PRESERVE_ALL_SEMICOLONS),
            (Boolean) compressorParameters.get(PARAMETER_DISABLE_OPTIMIZATIONS));
    String compressedScript = stringWriter.toString();
    return compressedScript;
}
 
开发者ID:directwebremoting,项目名称:dwr,代码行数:12,代码来源:YahooJSCompressor.java

示例6: compressJavaScript

import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入方法依赖的package包/类
public static void compressJavaScript(String inputFilename, String outputFilename, Options o) throws IOException {
    Reader in = null;
    Writer out = null;
    try {
        in = new InputStreamReader(new FileInputStream(inputFilename), o.charset);
        JavaScriptCompressor compressor = new JavaScriptCompressor(in, new YuiCompressorErrorReporter());
        in.close();
        in = null;
        out = new OutputStreamWriter(new FileOutputStream(outputFilename), o.charset);
        compressor.compress(out, o.lineBreakPos, o.munge, o.verbose, o.preserveAllSemiColons, o.disableOptimizations);
    } finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(out);
    }
}
 
开发者ID:AdityaAnand1,项目名称:Website-Compressor,代码行数:16,代码来源:Compressor.java

示例7: compressJs

import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入方法依赖的package包/类
private String compressJs(String content) {
  StringWriter writer = new StringWriter(1024);
  StringReader reader = new StringReader(content);
  try {
    JavaScriptCompressor jsCompressor = createJavaScriptCompressor(reader);
    jsCompressor.compress(writer, _compressorOptions.getLineBreakPosition(), _compressorOptions.isMunge(), _compressorOptions.isWarn(), 
        _compressorOptions.isPreserveAllSemiColons(), !_compressorOptions.isOptimize());
  } catch (IOException ex) {
    s_logger.error("Unexpected IOException", ex);
  }
  return writer.toString();
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:13,代码来源:YUIBundleCompressor.java

示例8: compress

import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入方法依赖的package包/类
@Override
public String compress(String source) {
	
	StringWriter result = new StringWriter();
	try {
		JavaScriptCompressor compressor = new JavaScriptCompressor(new StringReader(source), errorReporter);
		compressor.compress(result, lineBreak, !noMunge, false, preserveAllSemiColons, disableOptimizations);
	} catch (IOException e) {
		result.write(source);
		e.printStackTrace();
	}
	return result.toString();
	
}
 
开发者ID:ad3n,项目名称:htmlcompressor,代码行数:15,代码来源:YuiJavaScriptCompressor.java

示例9: minifyJs

import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入方法依赖的package包/类
private String minifyJs(final String jsSourceCode) throws EvaluatorException,
		IOException {
	JavaScriptCompressor jsc = new JavaScriptCompressor(
			new StringReader(jsSourceCode), this.errorReporter);
	StringWriter sw = new StringWriter();
	jsc.compress(sw, this.jsLinebreakPos, this.jsCompressorMunge,
			this.jsCompressorVerbose, this.jsCompressorPreserveAllSemiColons,
			this.jsCompressordisableOptimizations);
	return sw.toString();

}
 
开发者ID:khun777,项目名称:edsutil,代码行数:12,代码来源:WebResourceProcessor.java

示例10: minify

import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入方法依赖的package包/类
protected void minify(BufferedReader in, BufferedWriter out, String filename, String type) throws IOException {
    if (JS_TYPE.equals(type)) {
        JavaScriptCompressor jsc = new JavaScriptCompressor(in, getLogBasedErrorReporter());
        jsc.compress(out, linebreak, munge, verbose, preserveAllSemiColons, disableOptimizations);
    } else if (CSS_TYPE.equals(type)) {
        CssCompressor cssc = new CssCompressor(in);
        cssc.compress(out, 100);
    }
}
 
开发者ID:takbani,项目名称:blcdemo,代码行数:10,代码来源:ResourceMinificationServiceImpl.java

示例11: processAdminJS

import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入方法依赖的package包/类
private void processAdminJS(final File srcDir) throws Exception {
    if (adminJSs.isEmpty()) {
        return;
    }

    final File adminDir = new File(srcDir + File.separator + "admin");

    final List<File> adminJSList = new ArrayList<File>();
    for (final String adminJS : adminJSs) {
        final File adminJSFile = new File(adminDir.getPath() + File.separator + adminJS);
        adminJSList.add(adminJSFile);
    }

    final File latkeAdminJS = merge(adminJSList);

    final File latkeMinAdminJS =
            new File(getTargetDir() + File.separator + "admin" + File.separator + "latkeAdmin" + getSuffix() + ".js");

    getLogger().info("Minimizing [srcPath=" + latkeAdminJS.getPath() + ", targetPath=" + latkeMinAdminJS.getPath() + "]");

    final Reader reader = new InputStreamReader(
            new FileInputStream(latkeAdminJS), "UTF-8");
    final FileOutputStream writerStream = new FileOutputStream(latkeMinAdminJS);
    final Writer writer = new OutputStreamWriter(writerStream, "UTF-8");

    final JavaScriptCompressor compressor = new JavaScriptCompressor(
            reader, new JavaScriptErrorReporter(getLogger(), latkeAdminJS.getName()));
    compressor.compress(writer, -1, munge, verbose, preserveAllSemiColons, disableOptimizations);

    reader.close();
    writer.close();
}
 
开发者ID:b3log,项目名称:maven-min-plugin,代码行数:33,代码来源:JSProcessor.java

示例12: process

import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入方法依赖的package包/类
@Override
public String process(final String filename, final String source, final Config conf)
    throws Exception {
  ErrorReporter reporter = reporter(log, filename, name());
  JavaScriptCompressor compressor = new JavaScriptCompressor(new StringReader(source), reporter);
  StringWriter out = new StringWriter();
  compressor.compress(out, get("linebreakpos"), get("munge"), get("verbose"),
      get("preserve-semi"), get("disable-optimizations"));
  return out.toString();
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:11,代码来源:YuiJs.java

示例13: compile

import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入方法依赖的package包/类
@Override
public void compile(File in, File out) throws IOException {
    JavaScriptCompressor jsCompressor = new JavaScriptCompressor(new FileReader(in), errorReporter);
    FileWriter outputWriter = new FileWriter(out); //note that the filewriter is opened after the file reader

    jsCompressor.compress(outputWriter, -1, true, false, false, false);

    outputWriter.flush();
    outputWriter.close();
}
 
开发者ID:chrisjohnson1988,项目名称:StaticWeb,代码行数:11,代码来源:JavascriptCompressor.java

示例14: pack

import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入方法依赖的package包/类
public String pack(final InputStream resourceAsStream, final Charset charset, final String path) throws PackException {
	try {
		InputStreamReader isr = new InputStreamReader(resourceAsStream, charset);
		ErrorReporter er = new JavaScriptErrorReporter();
		JavaScriptCompressor jsc = new JavaScriptCompressor(isr, er);
		StringWriter sw = new StringWriter();
		jsc.compress(sw, LINEBREAK_AFTER_CHARACTERS, true, true, true, true);
		sw.flush();
		return sw.toString();
	}
	catch (Exception ex) {
		throw new PackException(ex);
	}
}
 
开发者ID:galan,项目名称:packtag,代码行数:15,代码来源:YuiCompressorPackStrategy.java

示例15: minify

import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入方法依赖的package包/类
@Override
public byte[] minify(String filename, byte[] bytes) {
    if (!getEnabled()) {
        return bytes;
    }
    
    String type = null;
    if (filename.endsWith(".js")) {
        type = "js";
    } else if (filename.endsWith(".css")) {
        type = "css";
    }
    
    if (!"js".equals(type) && !"css".equals(type)) {
        throw new IllegalArgumentException("Can only minify js or css resources");
    }
    
    byte[] minifiedBytes;
    
    BufferedReader in = null;
    BufferedWriter out = null;
    try {
        // Input streams to read the bytes
        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
        InputStreamReader isr = new InputStreamReader(bais, "utf-8");
        in = new BufferedReader(isr);

        // Output streams to save the modified bytes
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        OutputStreamWriter osw = new OutputStreamWriter(baos, "utf-8");
        out = new BufferedWriter(osw);

        if ("js".equals(type)) {
            JavaScriptCompressor jsc = new JavaScriptCompressor(in, getLogBasedErrorReporter());
            jsc.compress(out, linebreak, munge, verbose, preserveAllSemiColons, disableOptimizations);
        } else if ("css".equals(type)) {
            CssCompressor cssc = new CssCompressor(in);
            cssc.compress(out, 100);
        }
        out.flush();
        minifiedBytes = baos.toByteArray();
    } catch (Exception e) { // Catch everything - on a runtime exception, we still want to return the unminified bytes
        LOG.warn("Could not minify resources, returned unminified bytes", e);
        return bytes;
    } finally {
        try {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.close();
            }
        } catch (IOException e2) {
            throw new RuntimeException(e2);
        }
    }
    
    return minifiedBytes;
}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:60,代码来源:ResourceMinificationServiceImpl.java


注:本文中的com.yahoo.platform.yui.compressor.JavaScriptCompressor.compress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。