source: josm/trunk/src/org/openstreetmap/josm/io/OsmBzip2Importer.java@ 1750

Last change on this file since 1750 was 1653, checked in by stoecker, 15 years ago

add support for compressed OSM files (bzip2, gzip)

File size: 1.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.BufferedInputStream;
7import java.io.File;
8import java.io.FileInputStream;
9import java.io.IOException;
10
11import org.apache.tools.bzip2.CBZip2InputStream;
12import org.openstreetmap.josm.actions.ExtensionFileFilter;
13import org.xml.sax.SAXException;
14
15public class OsmBzip2Importer extends OsmImporter {
16
17 public OsmBzip2Importer() {
18 super(new ExtensionFileFilter("osm.bz2, osm.bz", "osm.bz2", tr("OSM Server Files bzip2 compressed")
19 + " (*.osm.bz2 *.osm.bz)"));
20 }
21
22 @Override
23 public void importData(File file) throws IOException {
24 BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
25 int b = bis.read();
26 if (b != 'B') {
27 throw new IOException(tr("Invalid bz2 file."));
28 }
29 b = bis.read();
30 if (b != 'Z') {
31 throw new IOException(tr("Invalid bz2 file."));
32 }
33 CBZip2InputStream in = new CBZip2InputStream(bis);
34
35 try {
36 importData(in, file);
37 } catch (SAXException e) {
38 e.printStackTrace();
39 throw new IOException(tr("Could not read \"{0}\"", file.getName()));
40 }
41 }
42}
Note: See TracBrowser for help on using the repository browser.