class 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();
            }
        }
    }

}