-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLZMADecDemo.java
More file actions
80 lines (69 loc) · 2.73 KB
/
LZMADecDemo.java
File metadata and controls
80 lines (69 loc) · 2.73 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* LZMADecDemo
*
* 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.*;
/**
* Decompresses .lzma files to standard output. If no arguments are given,
* reads from standard input.
*
* NOTE: For most purposes, .lzma is a legacy format and usually you should
* use .xz instead.
*/
class LZMADecDemo {
public static void main(String[] args) {
byte[] buf = new byte[8192];
String name = null;
try {
if (args.length == 0) {
name = "standard input";
// No need to use BufferedInputStream with System.in which
// seems to be fast with one-byte reads.
InputStream in = new LZMAInputStream(System.in);
int size;
while ((size = in.read(buf)) != -1)
System.out.write(buf, 0, size);
} else {
// Read from files given on the command line.
for (int i = 0; i < args.length; ++i) {
name = args[i];
InputStream in = new FileInputStream(name);
try {
// In contrast to other classes in org.tukaani.xz,
// LZMAInputStream doesn't do buffering internally
// and reads one byte at a time. BufferedInputStream
// gives a huge performance improvement here but even
// then it's slower than the other input streams from
// org.tukaani.xz.
in = new BufferedInputStream(in);
in = new LZMAInputStream(in);
int size;
while ((size = in.read(buf)) != -1)
System.out.write(buf, 0, size);
} finally {
// Close FileInputStream (directly or indirectly
// via LZMAInputStream, it doesn't matter).
in.close();
}
}
}
} catch (FileNotFoundException e) {
System.err.println("LZMADecDemo: Cannot open " + name + ": "
+ e.getMessage());
System.exit(1);
} catch (EOFException e) {
System.err.println("LZMADecDemo: Unexpected end of input on "
+ name);
System.exit(1);
} catch (IOException e) {
System.err.println("LZMADecDemo: Error decompressing from "
+ name + ": " + e.getMessage());
System.exit(1);
}
}
}