Changeset 16816 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2020-08-02T15:30:15+02:00 (4 years ago)
Author:
simon04
Message:

RenderingCLI: support compressed .osm files

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingCLI.java

    r16815 r16816  
    99import java.io.FileNotFoundException;
    1010import java.io.IOException;
    11 import java.nio.file.Files;
     11import java.io.InputStream;
    1212import java.nio.file.NoSuchFileException;
    1313import java.nio.file.Paths;
     
    3636import org.openstreetmap.josm.data.projection.Projections;
    3737import org.openstreetmap.josm.gui.mappaint.RenderingHelper.StyleData;
     38import org.openstreetmap.josm.io.Compression;
    3839import org.openstreetmap.josm.io.IllegalDataException;
    3940import org.openstreetmap.josm.io.OsmReader;
     
    572573            throw new IllegalArgumentException(tr("Missing argument - input data file ({0})", "--input|-i"));
    573574        }
    574         try {
    575             return OsmReader.parseDataSet(Files.newInputStream(Paths.get(argInput)), null);
     575        try (InputStream inputStream = Compression.getUncompressedFileInputStream(Paths.get(argInput))) {
     576            return OsmReader.parseDataSet(inputStream, null);
    576577        } catch (IllegalDataException e) {
    577578            throw new IllegalDataException(tr("In .osm data file ''{0}'' - ", argInput) + e.getMessage(), e);
  • trunk/src/org/openstreetmap/josm/io/Compression.java

    r15588 r16816  
    99import java.nio.file.Files;
    1010import java.nio.file.InvalidPathException;
     11import java.nio.file.Path;
    1112import java.util.zip.GZIPInputStream;
    1213import java.util.zip.GZIPOutputStream;
     
    177178    public static InputStream getUncompressedFileInputStream(File file) throws IOException {
    178179        try {
    179             InputStream in = Files.newInputStream(file.toPath()); // NOPMD
    180             try {
    181                 return byExtension(file.getName()).getUncompressedInputStream(in);
    182             } catch (IOException e) {
    183                 Utils.close(in);
    184                 throw e;
    185             }
     180            return getUncompressedFileInputStream(file.toPath());  // NOPMD
    186181        } catch (InvalidPathException e) {
    187182            throw new IOException(e);
     183        }
     184    }
     185
     186    /**
     187     * Returns an un-compressing {@link InputStream} for the {@link Path} {@code path}.
     188     * @param path path
     189     * @return un-compressing input stream
     190     * @throws IOException if any I/O error occurs
     191     * @since 16816
     192     */
     193    public static InputStream getUncompressedFileInputStream(Path path) throws IOException {
     194        InputStream in = Files.newInputStream(path); // NOPMD
     195        try {
     196            return byExtension(path.getFileName().toString()).getUncompressedInputStream(in);
     197        } catch (IOException e) {
     198            Utils.close(in);
     199            throw e;
    188200        }
    189201    }
     
    221233     */
    222234    public static OutputStream getCompressedFileOutputStream(File file) throws IOException {
    223         OutputStream out = Files.newOutputStream(file.toPath()); // NOPMD
     235        return getCompressedFileOutputStream(file.toPath()); // NOPMD
     236    }
     237
     238    /**
     239     * Returns a compressing {@link OutputStream} for the {@link Path} {@code path}.
     240     * @param path path
     241     * @return compressing output stream
     242     *
     243     * @throws IOException if any I/O error occurs
     244     * @throws InvalidPathException if a Path object cannot be constructed from the abstract path
     245     * @since 16816
     246     */
     247    public static OutputStream getCompressedFileOutputStream(Path path) throws IOException {
     248        OutputStream out = Files.newOutputStream(path); // NOPMD
    224249        try {
    225             return byExtension(file.getName()).getCompressedOutputStream(out);
     250            return byExtension(path.getFileName().toString()).getCompressedOutputStream(out);
    226251        } catch (IOException e) {
    227252            Utils.close(out);
Note: See TracChangeset for help on using the changeset viewer.