以库的形式调用YUI Compressor
import com.yahoo.platform.yui.compressor.CssCompressor;
import org.apache.commons.io.IOUtils;
import java.io.*;
public class YUIProcessor {
public String compressCss(String code) {
Reader in = new InputStreamReader(IOUtils.toInputStream(code));
try (Writer out = new StringWriter()) {
CssCompressor compressor = new CssCompressor(in);
compressor.compress(out, -1);
out.flush();
return out.toString();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
}
追加:
yui compresser 很久没有更新,有很多的不足,已经废弃使用。