Changeset 5317 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2012-07-10T13:29:55+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OpenLocationAction.java
r4996 r5317 23 23 import org.openstreetmap.josm.Main; 24 24 import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask; 25 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmBzip2Task; 25 26 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmChangeTask; 26 27 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; … … 55 56 addDownloadTaskClass(DownloadOsmChangeTask.class); 56 57 addDownloadTaskClass(DownloadOsmUrlTask.class); 58 addDownloadTaskClass(DownloadOsmBzip2Task.class); 57 59 } 58 60 -
trunk/src/org/openstreetmap/josm/io/OsmBzip2Importer.java
r3083 r5317 8 8 import java.io.FileInputStream; 9 9 import java.io.IOException; 10 import java.io.InputStream; 10 11 11 12 import org.apache.tools.bzip2.CBZip2InputStream; … … 22 23 @Override 23 24 public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException { 24 BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); 25 importData(getBZip2InputStream(new FileInputStream(file)), file); 26 } 27 28 public static CBZip2InputStream getBZip2InputStream(InputStream in) throws IOException { 29 if (in == null) { 30 return null; 31 } 32 BufferedInputStream bis = new BufferedInputStream(in); 25 33 int b = bis.read(); 26 34 if (b != 'B') … … 29 37 if (b != 'Z') 30 38 throw new IOException(tr("Invalid bz2 file.")); 31 CBZip2InputStream in = new CBZip2InputStream(bis); 32 importData(in, file); 39 return new CBZip2InputStream(bis); 33 40 } 34 41 } -
trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java
r4530 r5317 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.IOException; 6 7 import java.io.InputStream; 7 8 9 import org.apache.tools.bzip2.CBZip2InputStream; 8 10 import org.openstreetmap.josm.data.gpx.GpxData; 9 11 import org.openstreetmap.josm.data.osm.DataSet; 10 12 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 13 import org.xml.sax.SAXException; 11 14 12 15 public class OsmServerLocationReader extends OsmServerReader { 13 16 14 String url;17 protected final String url; 15 18 16 19 public OsmServerLocationReader(String url) { … … 18 21 } 19 22 20 /**21 * Method to download OSM files from somewhere22 */23 @Override24 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 25 InputStream in = null;23 protected abstract class Parser<T> { 24 public InputStream in = null; 25 public abstract T parse() throws OsmTransferException, IllegalDataException, IOException, SAXException; 26 } 27 28 protected final <T> T doParse(Parser<T> parser, final ProgressMonitor progressMonitor) throws OsmTransferException { 26 29 progressMonitor.beginTask(tr("Contacting Server...", 10)); 27 30 try { 28 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false)); 29 if (in == null) 30 return null; 31 progressMonitor.subTask(tr("Downloading OSM data...")); 32 return OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, false)); 31 return parser.parse(); 33 32 } catch(OsmTransferException e) { 34 33 throw e; … … 41 40 try { 42 41 activeConnection = null; 43 if (in != null) { 44 in.close(); 42 if (parser.in != null) { 43 parser.in.close(); 44 parser.in = null; 45 45 } 46 46 } catch(Exception e) {/* ignore it */} 47 47 } 48 } 49 50 /** 51 * Method to download OSM files from somewhere 52 */ 53 @Override 54 public DataSet parseOsm(final ProgressMonitor progressMonitor) throws OsmTransferException { 55 return doParse(new Parser<DataSet>() { 56 @Override 57 public DataSet parse() throws OsmTransferException, IllegalDataException { 58 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false)); 59 if (in == null) 60 return null; 61 progressMonitor.subTask(tr("Downloading OSM data...")); 62 return OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, false)); 63 } 64 }, progressMonitor); 65 } 66 67 /** 68 * Method to download BZip2-compressed OSM files from somewhere 69 */ 70 @Override 71 public DataSet parseOsmBzip2(final ProgressMonitor progressMonitor) throws OsmTransferException { 72 return doParse(new Parser<DataSet>() { 73 @Override 74 public DataSet parse() throws OsmTransferException, IllegalDataException, IOException { 75 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false)); 76 if (in == null) 77 return null; 78 CBZip2InputStream bzin = OsmBzip2Importer.getBZip2InputStream(in); 79 progressMonitor.subTask(tr("Downloading OSM data...")); 80 return OsmReader.parseDataSet(bzin, progressMonitor.createSubTaskMonitor(1, false)); 81 } 82 }, progressMonitor); 48 83 } 49 84 … … 52 87 */ 53 88 @Override 54 public DataSet parseOsmChange( ProgressMonitor progressMonitor)89 public DataSet parseOsmChange(final ProgressMonitor progressMonitor) 55 90 throws OsmTransferException { 56 InputStream in = null; 57 progressMonitor.beginTask(tr("Contacting Server...", 10)); 58 try { 59 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false)); 60 if (in == null) 61 return null; 62 progressMonitor.subTask(tr("Downloading OSM data...")); 63 return OsmChangeReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, false)); 64 } catch(OsmTransferException e) { 65 throw e; 66 } catch (Exception e) { 67 if (cancel) 68 return null; 69 throw new OsmTransferException(e); 70 } finally { 71 progressMonitor.finishTask(); 72 try { 73 activeConnection = null; 74 if (in != null) { 75 in.close(); 76 } 77 } catch(Exception e) {/* ignore it */} 78 } 91 return doParse(new Parser<DataSet>() { 92 @Override 93 public DataSet parse() throws OsmTransferException, IllegalDataException { 94 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false)); 95 if (in == null) 96 return null; 97 progressMonitor.subTask(tr("Downloading OSM data...")); 98 return OsmChangeReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, false)); 99 } 100 }, progressMonitor); 79 101 } 80 102 81 103 @Override 82 public GpxData parseRawGps(ProgressMonitor progressMonitor) throws OsmTransferException { 83 InputStream in = null; 84 progressMonitor.beginTask(tr("Contacting Server...", 10)); 85 try { 86 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(1, true)); 87 if (in == null) 88 return null; 89 progressMonitor.subTask(tr("Downloading OSM data...")); 90 GpxReader reader = new GpxReader(in); 91 reader.parse(false); 92 GpxData result = reader.data; 93 result.fromServer = true; 94 return result; 95 } catch(OsmTransferException e) { 96 throw e; 97 } catch (Exception e) { 98 if (cancel) 99 return null; 100 throw new OsmTransferException(e); 101 } finally { 102 progressMonitor.finishTask(); 103 try { 104 activeConnection = null; 105 if (in != null) { 106 in.close(); 107 } 108 } catch(Exception e) {/* ignore it */} 109 } 104 public GpxData parseRawGps(final ProgressMonitor progressMonitor) throws OsmTransferException { 105 return doParse(new Parser<GpxData>() { 106 @Override 107 public GpxData parse() throws OsmTransferException, IllegalDataException, IOException, SAXException { 108 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(1, true)); 109 if (in == null) 110 return null; 111 progressMonitor.subTask(tr("Downloading OSM data...")); 112 GpxReader reader = new GpxReader(in); 113 reader.parse(false); 114 GpxData result = reader.data; 115 result.fromServer = true; 116 return result; 117 } 118 }, progressMonitor); 110 119 } 111 120 } -
trunk/src/org/openstreetmap/josm/io/OsmServerReader.java
r5097 r5317 144 144 } 145 145 146 public abstract DataSet parseOsm( ProgressMonitor progressMonitor) throws OsmTransferException;146 public abstract DataSet parseOsm(final ProgressMonitor progressMonitor) throws OsmTransferException; 147 147 148 public DataSet parseOsmChange( ProgressMonitor progressMonitor) throws OsmTransferException {148 public DataSet parseOsmChange(final ProgressMonitor progressMonitor) throws OsmTransferException { 149 149 return null; 150 150 } 151 151 152 public GpxData parseRawGps(ProgressMonitor progressMonitor) throws OsmTransferException { 152 public GpxData parseRawGps(final ProgressMonitor progressMonitor) throws OsmTransferException { 153 return null; 154 } 155 156 public DataSet parseOsmBzip2(final ProgressMonitor progressMonitor) throws OsmTransferException { 153 157 return null; 154 158 }
Note:
See TracChangeset
for help on using the changeset viewer.