| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.apache.tools.bzip2;
|
|---|
| 3 |
|
|---|
| 4 | import java.io.Closeable;
|
|---|
| 5 | import java.io.FileInputStream;
|
|---|
| 6 | import java.io.FileNotFoundException;
|
|---|
| 7 | import java.io.FileOutputStream;
|
|---|
| 8 | import java.io.IOException;
|
|---|
| 9 |
|
|---|
| 10 | public class Bzip2Test
|
|---|
| 11 | {
|
|---|
| 12 | public static void main(String[] args) throws FileNotFoundException, IOException
|
|---|
| 13 | {
|
|---|
| 14 | FileOutputStream fos = null;
|
|---|
| 15 | CBZip2InputStream inputStream = null;
|
|---|
| 16 | try {
|
|---|
| 17 | FileInputStream fis = new FileInputStream("d:/tmp/josm-test/luxembourg-20140903_121227.osm.bz2");
|
|---|
| 18 | fis.read();
|
|---|
| 19 | fis.read();
|
|---|
| 20 | inputStream = new CBZip2InputStream(fis);
|
|---|
| 21 | fos = new FileOutputStream("d:/tmp/josm-test/luxembourg-20140903_121227.osm.test");
|
|---|
| 22 | byte[] b = new byte[1024];
|
|---|
| 23 | int length;
|
|---|
| 24 | while ((length = inputStream.read(b, 0, b.length)) != -1) {
|
|---|
| 25 | fos.write(b, 0, length);
|
|---|
| 26 | }
|
|---|
| 27 | }
|
|---|
| 28 | finally {
|
|---|
| 29 | close(fos);
|
|---|
| 30 | close(inputStream);
|
|---|
| 31 | }
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | private static void close(Closeable inputStream) {
|
|---|
| 35 | if(inputStream != null)
|
|---|
| 36 | try {
|
|---|
| 37 | inputStream.close();
|
|---|
| 38 | } catch (IOException e) {
|
|---|
| 39 | // ignore
|
|---|
| 40 | }
|
|---|
| 41 | }
|
|---|
| 42 | }
|
|---|