aboutsummaryrefslogtreecommitdiff
path: root/src/XZDecDemo.java
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2011-03-30 13:59:11 +0300
committerLasse Collin <lasse.collin@tukaani.org>2011-03-30 13:59:11 +0300
commit36d0dfc560046f8fefd8b7e962ae0e01dc03a90c (patch)
tree8e7b36cfd8bf7ff760c709a5c0663cc6adccfd6f /src/XZDecDemo.java
downloadxz-java-36d0dfc560046f8fefd8b7e962ae0e01dc03a90c.tar.gz
Initial commit.
This supports only decompression in streamed mode using LZMA2 and Delta filters. The integrity checks None, CRC32, CRC64, and SHA-256 are supported.
Diffstat (limited to 'src/XZDecDemo.java')
-rw-r--r--src/XZDecDemo.java62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/XZDecDemo.java b/src/XZDecDemo.java
new file mode 100644
index 0000000..25b83f7
--- /dev/null
+++ b/src/XZDecDemo.java
@@ -0,0 +1,62 @@
+/*
+ * XZDecDemo
+ *
+ * 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 .xz files to standard output. If no arguments are given,
+ * reads from standard input.
+ */
+class XZDecDemo {
+ public static void main(String[] args) {
+ byte[] buf = new byte[8192];
+ String name = null;
+
+ try {
+ if (args.length == 0) {
+ name = "standard input";
+ InputStream in = new XZInputStream(System.in);
+
+ while (in.read(buf) != -1)
+ System.out.write(buf);
+
+ } else {
+ // Read from files given on the command line.
+ for (int i = 0; i < args.length; ++i) {
+ name = args[i];
+
+ // Since XZInputStream does some buffering internally
+ // anyway, BufferedInputStream doesn't seem to be
+ // needed here to improve performance.
+ InputStream in = new FileInputStream(name);
+ // in = new BufferedInputStream(in);
+ in = new XZInputStream(in);
+
+ while (in.read(buf) != -1)
+ System.out.write(buf);
+ }
+ }
+ } catch (FileNotFoundException e) {
+ System.err.println("XZDecDemo: Cannot open " + name + ": "
+ + e.getMessage());
+ System.exit(1);
+
+ } catch (EOFException e) {
+ System.err.println("XZDecDemo: Unexpected end of input on "
+ + name);
+ System.exit(1);
+
+ } catch (IOException e) {
+ System.err.println("XZDecDemo: Error decompressing from "
+ + name + ": " + e.getMessage());
+ System.exit(1);
+ }
+ }
+}