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