Ticket #10448: Bzip2Test.java

File Bzip2Test.java, 1.2 KB (added by Hojoe, 11 years ago)

uncompress luxembourg-20140903_121227.osm.bz2

Line 
1// License: GPL. For details, see LICENSE file.
2package org.apache.tools.bzip2;
3
4import java.io.Closeable;
5import java.io.FileInputStream;
6import java.io.FileNotFoundException;
7import java.io.FileOutputStream;
8import java.io.IOException;
9
10public 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}