htmlcompressor介绍

荣波
2023-12-01

官网 : http://code.google.com/p/htmlcompressor/

例程 :

package net.dncsoft.htmlcompressor;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Date;

import com.googlecode.htmlcompressor.compressor.HtmlCompressor;

public class MainHtmlCompressor {

	public static void main(String[] args) throws Exception {
		MainHtmlCompressor main = new MainHtmlCompressor();
		main.cssCompress();
	}

	private void cssCompress() throws Exception {
		StringBuffer cssBuf = new StringBuffer();
		readFileToBuffer("c:/html.css", cssBuf);
		HtmlCompressor compressor = new HtmlCompressor();
		compressor.setCompressCss(true);

		long beforeTimestamp = new Date().getTime();
		String compressedCss = compressor.compress(cssBuf.toString());
		long afterTimestamp = new Date().getTime();

		System.out.println(afterTimestamp - beforeTimestamp);
		System.out.println(compressedCss);
	}

	private void readFileToBuffer(String fileName, StringBuffer sb) {
		try {
			FileReader in = new FileReader(fileName);
			BufferedReader br = new BufferedReader(in);
			String line;

			while ((line = br.readLine()) != null) {
				sb.append(line);
			}

			br.close();
			in.close();
		} catch (IOException e) {
			System.out.println(e);
		}
	}
}

 

相关的JAR

  htmlcompressor-1.3.1.jar

  yuicompressor-2.4.6.jar

  jargs-1.0.jar

  rhino-1.6R7.jar

 

 类似资料: