Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
  * file except in compliance with the License. You may obtain a copy of the License at
  * Unless required by applicable law or agreed to in writing, software distributed under
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
  * OF ANY KIND, either express or implied. See the License for the specific language
  * governing permissions and limitations under the License.
package com.ning.compress.lzf;
Simple command-line utility that can be used for testing LZF compression, or as rudimentary command-line tool. Arguments are the same as used by the "standard" lzf command line tool

Tatu Saloranta (
public class LZF
    public final static String SUFFIX = ".lzf";
    protected void process(String[] argsthrows IOException
        if (args.length == 2) {
            String oper = args[0];
            boolean compress = "-c".equals(oper);
            boolean toSystemOutput = !compress && "-o".equals(oper);
            if (compress || toSystemOutput || "-d".equals(oper)) {
                String filename = args[1];
                File src = new File(filename);
                if (!src.exists()) {
                    ..println("File '"+filename+"' does not exist.");
                if (!compress && !filename.endsWith()) {
                    ..println("File '"+filename+"' does end with expected suffix ('"++"', won't decompress.");
                if (compress) {
                    int inputLength = 0;
                    File resultFile = new File(filename+);
                    InputStream in = new FileInputStream(src);
                    OutputStream out = new LZFFileOutputStream(resultFile);
                    byte[] buffer = new byte[8192];
                    int bytesRead;
                    while ((bytesRead =, 0, buffer.length)) != -1) { 
                        inputLength += bytesRead;
                        out.write(buffer, 0, bytesRead); 
                    ..printf("Compressed '%s' into '%s' (%d->%d bytes)\n",
                            src.getPath(), resultFile.getPath(),
                } else {
                    OutputStream out;
                    LZFFileInputStream in = new LZFFileInputStream(src);
                    File resultFile = null;
                    if (toSystemOutput) {
                        out = .;
                    } else {
                        resultFile = new File(filename.substring(0, filename.length() - .length()));
                        out = new FileOutputStream(resultFile);
                    int uncompLen = in.readAndWrite(out);
                    if (resultFile != null) {
                        ..printf("Uncompressed '%s' into '%s' (%d->%d bytes)\n",
                                src.getPath(), resultFile.getPath(),
                                src.length(), uncompLen);
        ..println("Usage: java "+getClass().getName()+" -c/-d/-o source-file");
        ..println(" -d parameter: decompress to file");
        ..println(" -c parameter: compress to file");
        ..println(" -o parameter: decompress to stdout");
    public static void main(String[] argsthrows IOException {
        new LZF().process(args);
New to GrepCode? Check out our FAQ X