Changeset 30908 in osm for applications/editors/josm/plugins/opendata/src/org
- Timestamp:
- 2015-01-11T21:50:45+01:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/SevenZipReader.java
r30738 r30908 33 33 34 34 private final IInArchive archive = new Handler(); 35 35 36 36 public SevenZipReader(InputStream in, AbstractDataSetHandler handler, boolean promptUser) throws IOException { 37 37 super(handler, handler != null ? handler.getArchiveHandler() : null, promptUser); … … 41 41 Utils.copyStream(in, out); 42 42 } 43 try (IInStream random = new MyRandomAccessFile(tmpFile.getPath(), "r")) { 44 if (archive.Open(random) != 0) { 45 String message = "Unable to open 7z archive: "+tmpFile.getPath(); 46 Main.warn(message); 47 if (!tmpFile.delete()) { 48 tmpFile.deleteOnExit(); 49 } 50 throw new IOException(message); 43 // random must be kept open for later extracting 44 @SuppressWarnings("resource") 45 IInStream random = new MyRandomAccessFile(tmpFile.getPath(), "r"); 46 if (archive.Open(random) != 0) { 47 String message = "Unable to open 7z archive: "+tmpFile.getPath(); 48 Main.warn(message); 49 random.close(); 50 if (!tmpFile.delete()) { 51 tmpFile.deleteOnExit(); 51 52 } 53 throw new IOException(message); 52 54 } 53 55 } 54 55 public static DataSet parseDataSet(InputStream in, AbstractDataSetHandler handler, ProgressMonitor instance, boolean promptUser) 56 57 public static DataSet parseDataSet(InputStream in, AbstractDataSetHandler handler, ProgressMonitor instance, boolean promptUser) 56 58 throws IOException, XMLStreamException, FactoryConfigurationError, JAXBException { 57 59 return new SevenZipReader(in, handler, promptUser).parseDoc(instance); 58 60 } 59 61 60 public static Map<File, DataSet> parseDataSets(InputStream in, AbstractDataSetHandler handler, ProgressMonitor instance, boolean promptUser) 62 public static Map<File, DataSet> parseDataSets(InputStream in, AbstractDataSetHandler handler, ProgressMonitor instance, boolean promptUser) 61 63 throws IOException, XMLStreamException, FactoryConfigurationError, JAXBException { 62 64 return new SevenZipReader(in, handler, promptUser).parseDocs(instance); … … 68 70 } 69 71 70 @Override protected void extractArchive(File temp, List<File> candidates) throws IOException, FileNotFoundException { 72 @Override 73 protected void extractArchive(File temp, List<File> candidates) throws IOException, FileNotFoundException { 71 74 archive.Extract(null, -1, IInArchive.NExtract_NAskMode_kExtract, new ExtractCallback(archive, temp, candidates)); 75 archive.close(); 72 76 } 73 77 74 78 private class ExtractCallback extends ArchiveExtractCallback { 75 79 private final List<File> candidates; 76 80 77 81 public ExtractCallback(IInArchive archive, File tempDir, List<File> candidates) { 78 82 Init(archive); … … 81 85 } 82 86 83 @Override 87 @Override 84 88 public int GetStream(int index, OutputStream[] outStream, int askExtractMode) throws IOException { 85 89 int res = super.GetStream(index, outStream, askExtractMode);
Note:
See TracChangeset
for help on using the changeset viewer.