Add LZMADecDemo demo program.
diff --git a/build.xml b/build.xml
index cd3358f..f22e6d6 100644
--- a/build.xml
+++ b/build.xml
@@ -105,6 +105,14 @@
<attribute name="Class-Path" value="xz.jar"/>
</manifest>
</jar>
+
+ <jar destfile="${jar_dir}/LZMADecDemo.jar" basedir="${classes_dir}"
+ includes="LZMADecDemo.class">
+ <manifest>
+ <attribute name="Main-Class" value="LZMADecDemo"/>
+ <attribute name="Class-Path" value="xz.jar"/>
+ </manifest>
+ </jar>
</target>
<!-- It's an ugly quick hack. Maybe some day there will be a cleaner
diff --git a/fileset-src.txt b/fileset-src.txt
index fad687e..c7181fb 100644
--- a/fileset-src.txt
+++ b/fileset-src.txt
@@ -1,3 +1,4 @@
+src/LZMADecDemo.java
src/XZDecDemo.java
src/XZEncDemo.java
src/XZSeekDecDemo.java
diff --git a/src/LZMADecDemo.java b/src/LZMADecDemo.java
new file mode 100644
index 0000000..1098725
--- /dev/null
+++ b/src/LZMADecDemo.java
@@ -0,0 +1,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);
+ }
+ }
+}