本文整理汇总了Java中com.yahoo.platform.yui.compressor.CssCompressor.compress方法的典型用法代码示例。如果您正苦于以下问题:Java CssCompressor.compress方法的具体用法?Java CssCompressor.compress怎么用?Java CssCompressor.compress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.yahoo.platform.yui.compressor.CssCompressor
的用法示例。
在下文中一共展示了CssCompressor.compress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compressCSS
import com.yahoo.platform.yui.compressor.CssCompressor; //导入方法依赖的package包/类
public void compressCSS(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))) {
CssCompressor compressor = new CssCompressor(in);
compressor.compress(out, o.lineBreakPos);
}
}
示例2: compressCss
import com.yahoo.platform.yui.compressor.CssCompressor; //导入方法依赖的package包/类
private void compressCss(File source, File dest) throws IOException {
Reader in = null;
Writer out = null;
try {
in = new BufferedReader(new FileReader(source));
CssCompressor compressor = new CssCompressor(in);
log("Compressing: " + source.getName());
out = new BufferedWriter(new FileWriter(dest));
compressor.compress(out, linebreak);
} finally {
if (in != null) in.close();
if (out != null) out.close();
}
}
示例3: compressCSS
import com.yahoo.platform.yui.compressor.CssCompressor; //导入方法依赖的package包/类
public void compressCSS(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 CssCompressor compressor = new CssCompressor(in);
in.close();
in = null;
out = new OutputStreamWriter(new FileOutputStream(outputFile, true), o.charset);
compressor.compress(out, o.lineBreakPos);
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
}
}
示例4: compressCss
import com.yahoo.platform.yui.compressor.CssCompressor; //导入方法依赖的package包/类
private void compressCss(Reader reader, OutputStream out) throws IOException
{
CssCompressor compressor = new CssCompressor(reader);
StringWriter writer = new StringWriter();
compressor.compress(writer, -1);
String compressed = writer.toString();
IOUtils.copy(new StringReader(compressed), out);
}
示例5: write
import com.yahoo.platform.yui.compressor.CssCompressor; //导入方法依赖的package包/类
public void write(Writer writer, boolean minify) throws IOException {
if (minify) {
InputStreamReader reader = new InputStreamReader(
new ByteArrayInputStream(printState().getBytes("UTF-8")));
CssCompressor compressor = new CssCompressor(reader);
compressor.compress(writer, -1);
} else {
writer.write(printState());
}
}
示例6: compressCSS
import com.yahoo.platform.yui.compressor.CssCompressor; //导入方法依赖的package包/类
public static void compressCSS(String inputFilename, String outputFilename, Options o) throws IOException {
Reader in = null;
Writer out = null;
try {
in = new InputStreamReader(new FileInputStream(inputFilename), o.charset);
CssCompressor compressor = new CssCompressor(in);
in.close();
in = null;
out = new OutputStreamWriter(new FileOutputStream(outputFilename), o.charset);
compressor.compress(out, o.lineBreakPos);
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
}
}
示例7: compressCss
import com.yahoo.platform.yui.compressor.CssCompressor; //导入方法依赖的package包/类
private String compressCss(String content) {
StringWriter stringWriter = new StringWriter(1024);
try {
CssCompressor compressor = new CssCompressor(new StringReader(content));
compressor.compress(stringWriter, _compressorOptions.getLineBreakPosition());
} catch (IOException ex) {
s_logger.error("Unexpected IOException", ex);
}
return stringWriter.toString();
}
示例8: minify
import com.yahoo.platform.yui.compressor.CssCompressor; //导入方法依赖的package包/类
/**
* Minifies the CSS contents from the given merged file into the minified file
*
* <p>
* Minification is performed using the YUI Compressor compiler with no line break
* </p>
*
* @see ThemeFilesProcessor#minify(java.io.File, java.io.File)
* @see com.yahoo.platform.yui.compressor.CssCompressor
*/
@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 CSS file: " + minifiedFile.getPath());
try {
out = new FileOutputStream(minifiedFile);
writer = new OutputStreamWriter(out);
in = new FileInputStream(mergedFile);
reader = new InputStreamReader(in);
CssCompressor compressor = new CssCompressor(reader);
compressor.compress(writer, this.linebreak);
writer.flush();
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
}
示例9: minify
import com.yahoo.platform.yui.compressor.CssCompressor; //导入方法依赖的package包/类
/**
* Minifies a CSS file. Create missing parent directories if needed.
*
* @param mergedFile input file resulting from the merged step
* @param minifiedFile output file resulting from the minify step
* @throws IOException when the minify step fails
*/
@Override
protected void minify(File mergedFile, File minifiedFile) throws IOException {
minifiedFile.getParentFile().mkdirs();
try (InputStream in = new FileInputStream(mergedFile);
OutputStream out = new FileOutputStream(minifiedFile);
InputStreamReader reader = new InputStreamReader(in, charset);
OutputStreamWriter writer = new OutputStreamWriter(out, charset)) {
log.info("Creating the minified file [" + ((verbose) ? minifiedFile.getPath() : minifiedFile.getName())
+ "].");
switch (engine) {
case YUI:
log.debug("Using YUI Compressor engine.");
CssCompressor compressor = new CssCompressor(reader);
compressor.compress(writer, yuiConfig.getLineBreak());
break;
default:
log.warn("CSS engine not supported.");
break;
}
} catch (IOException e) {
log.error("Failed to compress the CSS file [" + ((verbose) ? mergedFile.getPath() : mergedFile.getName())
+ "].", e);
throw e;
}
logCompressionGains(mergedFile, minifiedFile);
}
示例10: compress
import com.yahoo.platform.yui.compressor.CssCompressor; //导入方法依赖的package包/类
@Override
public String compress(String source) {
StringWriter result = new StringWriter();
try {
CssCompressor compressor = new CssCompressor(new StringReader(source));
compressor.compress(result, lineBreak);
} catch (IOException e) {
result.write(source);
e.printStackTrace();
}
return result.toString();
}
示例11: minify
import com.yahoo.platform.yui.compressor.CssCompressor; //导入方法依赖的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);
}
}
示例12: process
import com.yahoo.platform.yui.compressor.CssCompressor; //导入方法依赖的package包/类
public String process(File[] srcFiles) throws ProcessException {
StringWriter writer = new StringWriter();
try {
for (File srcFile : srcFiles) {
CssCompressor compressor = new CssCompressor(new InputStreamReader(new FileInputStream(srcFile)));
compressor.compress(writer, -1);
}
} catch (IOException e) {
throw new ProcessException("Failed to process CSS files.", e);
}
return writer.toString();
}
示例13: minimiseCSS
import com.yahoo.platform.yui.compressor.CssCompressor; //导入方法依赖的package包/类
private String minimiseCSS( String cssContents ) throws cfmRunTimeException {
StringReader stringReader = new StringReader( cssContents );
try{
CssCompressor compressor = new CssCompressor( stringReader );
StringWriter out = new StringWriter();
compressor.compress(out, -1);
return out.toString();
}catch(Exception e){
throw newRunTimeException( "CSS Minimizer: failed: " + e.getMessage() );
}
}
示例14: map
import com.yahoo.platform.yui.compressor.CssCompressor; //导入方法依赖的package包/类
@Override
public Resource<String> map(Resource<String> resource) {
StringWriter sw = new StringWriter();
try {
CssCompressor cssCompressor = new CssCompressor(new StringReader(resource.getContent()));
cssCompressor.compress(sw, -1);
} catch (Exception e) {
throw new IllegalStateException(e);
}
return new Resource<String>(resource.getMimeType(), sw.toString(), StringHasher.instance);
}
示例15: process
import com.yahoo.platform.yui.compressor.CssCompressor; //导入方法依赖的package包/类
@Override
public String process(final String filename, final String source, final Config conf)
throws Exception {
CssCompressor compressor = new CssCompressor(new StringReader(source));
int linebreakpos = get("linebreakpos");
StringWriter out = new StringWriter();
compressor.compress(out, linebreakpos);
return out.toString();
}