CompressCLI { public void minifyAndObfuscateFile(File input, File output, boolean isJs) throws EvaluatorException, IOException { final String fileName = input.getCanonicalPath(); InputStreamReader in = new InputStreamReader(new FileInputStream(input), "UTF-8"); OutputStreamWriter out = null; try { if (isJs) { JavaScriptCompressor compressor = new JavaScriptCompressor(in, new ErrorReporter() { public void warning(String message, String sourceName, int line, String lineSource, int lineOffset) { if (line < 0) { System.err.println("\n[WARNING] " + fileName + ':' + message); } else { System.err.println("\n[WARNING] " + fileName + ':' + line + ':' + lineOffset + ':' + message); } } public void error(String message, String sourceName, int line, String lineSource, int lineOffset) { if (line < 0) { System.err.println("\n[ERROR] " + fileName + ':' + message); } else { System.err.println("\n[ERROR] " + fileName + ':' + line + ':' + lineOffset + ':' + message); } } public EvaluatorException runtimeError(String message, String sourceName, int line, String lineSource, int lineOffset) { error(message, sourceName, line, lineSource, lineOffset); return new EvaluatorException(message); } }); in.close(); in = null; out = new OutputStreamWriter(new FileOutputStream(output), "UTF-8"); compressor.compress(out, _lineBreakPos, _obfuscate, _isDebug, _preserveUnecessarySemicolons, _disableMicroOptimizations); } else { CssCompressor compressor = new com.yahoo.platform.yui.compressor.CssCompressor(in); in.close(); in = null; out = new OutputStreamWriter(new FileOutputStream(output), "UTF-8"); compressor.compress(out, _lineBreakPos); } } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } }  static void main(String[] args); void setIsListOnly(boolean isListOnly); void setIsVerbose(boolean isVerbose); void setIsDebug(boolean isDebug); void setLineBreakPos(int breakPos); void setObfuscate(boolean obfuscate); void setDisableMicroOptimizations(boolean disableMicroOptimizations); void setPreserveUnecessarySemicolons(boolean preserveUnecessarySemicolons); void setOutputPath(String outputPath); void setConfigurationFromFile(String configurationPath); void setConfigurationFromStream(InputStream in); void setConfigurationFromString(String in); void setBaseInputPath(String baseInputPath); void setJsURIFragment(String fragment); void setCssURIFragment(String fragment); void execute(); void minifyAndObfuscateFile(File input, File output, boolean isJs);  }
@Test public void testMinifyAndObfuscateCss() throws Exception { File input = new File(getClass().getResource("input.css").getFile()); CompressCLI compressCLI = new CompressCLI(); compressCLI.minifyAndObfuscateFile(input, _outputFile, false); assertTrue(_outputFile.exists()); String actual = IOUtils.toString(new FileInputStream(_outputFile)); String expected = IOUtils.toString(getClass().getResourceAsStream("inputMinified.css")).trim(); TestingUtil.assertEqualsIgnoreWhitespace(expected, actual.trim()); }
@Test public void testMinifyAndObfuscateJs() throws Exception { File input = new File(getClass().getResource("input.js").getFile()); CompressCLI compressCLI = new CompressCLI(); compressCLI.minifyAndObfuscateFile(input, _outputFile, true); assertTrue(_outputFile.exists()); String actual = IOUtils.toString(new FileInputStream(_outputFile)); String expected = IOUtils.toString(getClass().getResourceAsStream("inputMinified.js")).trim(); TestingUtil.assertEqualsIgnoreWhitespace(expected, actual.trim()); }