Ignore:
Timestamp:
2015-01-11T21:50:45+01:00 (10 years ago)
Author:
donvip
Message:

[josm_opendata] update to GeoFLA 2.0, fix regression in 7z handling

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  
    3333
    3434    private final IInArchive archive = new Handler();
    35 
     35   
    3636    public SevenZipReader(InputStream in, AbstractDataSetHandler handler, boolean promptUser) throws IOException {
    3737        super(handler, handler != null ? handler.getArchiveHandler() : null, promptUser);
     
    4141            Utils.copyStream(in, out);
    4242        }
    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();
    5152            }
     53            throw new IOException(message);
    5254        }
    5355    }
    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) 
    5658            throws IOException, XMLStreamException, FactoryConfigurationError, JAXBException {
    5759        return new SevenZipReader(in, handler, promptUser).parseDoc(instance);
    5860    }
    5961
    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) 
    6163            throws IOException, XMLStreamException, FactoryConfigurationError, JAXBException {
    6264        return new SevenZipReader(in, handler, promptUser).parseDocs(instance);
     
    6870    }
    6971
    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 {
    7174        archive.Extract(null, -1, IInArchive.NExtract_NAskMode_kExtract, new ExtractCallback(archive, temp, candidates));
     75        archive.close();
    7276    }
    73 
     77   
    7478    private class ExtractCallback extends ArchiveExtractCallback {
    7579        private final List<File> candidates;
    76 
     80       
    7781        public ExtractCallback(IInArchive archive, File tempDir, List<File> candidates) {
    7882            Init(archive);
     
    8185        }
    8286
    83         @Override
     87        @Override 
    8488        public int GetStream(int index, OutputStream[] outStream, int askExtractMode) throws IOException {
    8589            int res = super.GetStream(index, outStream, askExtractMode);
Note: See TracChangeset for help on using the changeset viewer.