本文整理汇总了Java中com.yahoo.platform.yui.compressor.CssCompressor类的典型用法代码示例。如果您正苦于以下问题:Java CssCompressor类的具体用法?Java CssCompressor怎么用?Java CssCompressor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CssCompressor类属于com.yahoo.platform.yui.compressor包,在下文中一共展示了CssCompressor类的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: minifyCSS
import com.yahoo.platform.yui.compressor.CssCompressor; //导入依赖的package包/类
/**
* Minifies CSS by utilising YUI {@link CssCompressor}.
*
* @param bytes - an array of bytes to minify
* @param linebreakpos - split long line after a specific column
* @return minified content as array of bytes
* @throws IOException
*/
static final byte[] minifyCSS(final byte[] bytes, int linebreakpos) throws IOException {
Reader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(bytes)));
StringWriter writer = new StringWriter();
try {
new CssCompressor(reader).compress(writer, linebreakpos);
} catch (IndexOutOfBoundsException e) {
// handle YUI bug when file is empty or contains comments only
return new byte[] {};
}
finally {
if (reader != null) {
reader.close();
}
if (writer != null) {
writer.close();
}
}
return writer.toString().getBytes("UTF-8");
}
示例3: 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();
}
}
示例4: 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);
}
}
示例5: runSafe
import com.yahoo.platform.yui.compressor.CssCompressor; //导入依赖的package包/类
@Override
protected void runSafe() throws Exception {
try (Reader reader = new BufferedReader(new InputStreamReader(
srcFile.getContents(), inCharset));
Writer writer = new OutputStreamWriter(out, outCharset)) {
try {
new CssCompressor(reader).compress(writer, -1);
} finally {
writer.close();
}
}
}
示例6: 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);
}
示例7: 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());
}
}
示例8: 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);
}
}
示例9: 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();
}
示例10: 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();
}
}
}
示例11: 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);
}
示例12: 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();
}
示例13: 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);
}
}
示例14: 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();
}
示例15: 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() );
}
}