1 /* 2 * XZEncDemo 3 * 4 * Author: Lasse Collin <lasse.collin@tukaani.org> 5 * 6 * This file has been put into the public domain. 7 * You can do whatever you want with this file. 8 */ 9 10 import java.io.*; 11 import org.tukaani.xz.*; 12 13 /** 14 * Compresses a single file from standard input to standard ouput into 15 * the .xz file format. 16 * <p> 17 * One optional argument is supported: LZMA2 preset level which is an integer 18 * in the range [0, 9]. The default is 6. 19 */ 20 class XZEncDemo { main(String[] args)21 public static void main(String[] args) throws Exception { 22 LZMA2Options options = new LZMA2Options(); 23 24 if (args.length >= 1) 25 options.setPreset(Integer.parseInt(args[0])); 26 27 System.err.println("Encoder memory usage: " 28 + options.getEncoderMemoryUsage() + " KiB"); 29 System.err.println("Decoder memory usage: " 30 + options.getDecoderMemoryUsage() + " KiB"); 31 32 XZOutputStream out = new XZOutputStream(System.out, options); 33 34 byte[] buf = new byte[8192]; 35 int size; 36 while ((size = System.in.read(buf)) != -1) 37 out.write(buf, 0, size); 38 39 out.finish(); 40 } 41 } 42