Changeset 12772 in josm for trunk/src


Ignore:
Timestamp:
2017-09-07T21:24:42+02:00 (7 years ago)
Author:
bastiK
Message:

see #15229 - move compression methods from Utils to Compression

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/Compression.java

    r10223 r12772  
    99import java.io.OutputStream;
    1010import java.nio.charset.StandardCharsets;
     11import java.util.zip.GZIPInputStream;
    1112import java.util.zip.GZIPOutputStream;
     13import java.util.zip.ZipEntry;
     14import java.util.zip.ZipInputStream;
    1215import java.util.zip.ZipOutputStream;
    1316
     17import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
    1418import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
     19import org.openstreetmap.josm.tools.Logging;
    1520import org.openstreetmap.josm.tools.Utils;
    1621
     
    7984        switch (this) {
    8085            case BZIP2:
    81                 return Utils.getBZip2InputStream(in);
     86                return getBZip2InputStream(in);
    8287            case GZIP:
    83                 return Utils.getGZipInputStream(in);
     88                return getGZipInputStream(in);
    8489            case ZIP:
    85                 return Utils.getZipInputStream(in);
     90                return getZipInputStream(in);
    8691            case NONE:
    8792            default:
    8893                return in;
    8994        }
     95    }
     96
     97    /**
     98     * Returns a Bzip2 input stream wrapping given input stream.
     99     * @param in The raw input stream
     100     * @return a Bzip2 input stream wrapping given input stream, or {@code null} if {@code in} is {@code null}
     101     * @throws IOException if the given input stream does not contain valid BZ2 header
     102     * @since 12772 (moved from {@link Utils}, there since 7867)
     103     */
     104    public static BZip2CompressorInputStream getBZip2InputStream(InputStream in) throws IOException {
     105        if (in == null) {
     106            return null;
     107        }
     108        return new BZip2CompressorInputStream(in, /* see #9537 */ true);
     109    }
     110
     111    /**
     112     * Returns a Gzip input stream wrapping given input stream.
     113     * @param in The raw input stream
     114     * @return a Gzip input stream wrapping given input stream, or {@code null} if {@code in} is {@code null}
     115     * @throws IOException if an I/O error has occurred
     116     * @since 12772 (moved from {@link Utils}, there since 7119)
     117     */
     118    public static GZIPInputStream getGZipInputStream(InputStream in) throws IOException {
     119        if (in == null) {
     120            return null;
     121        }
     122        return new GZIPInputStream(in);
     123    }
     124
     125    /**
     126     * Returns a Zip input stream wrapping given input stream.
     127     * @param in The raw input stream
     128     * @return a Zip input stream wrapping given input stream, or {@code null} if {@code in} is {@code null}
     129     * @throws IOException if an I/O error has occurred
     130     * @since 12772 (moved from {@link Utils}, there since 7119)
     131     */
     132    public static ZipInputStream getZipInputStream(InputStream in) throws IOException {
     133        if (in == null) {
     134            return null;
     135        }
     136        ZipInputStream zis = new ZipInputStream(in, StandardCharsets.UTF_8);
     137        // Positions the stream at the beginning of first entry
     138        ZipEntry ze = zis.getNextEntry();
     139        if (ze != null && Logging.isDebugEnabled()) {
     140            Logging.debug("Zip entry: {0}", ze.getName());
     141        }
     142        return zis;
    90143    }
    91144
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r12703 r12772  
    5858import java.util.stream.Stream;
    5959import java.util.zip.GZIPInputStream;
    60 import java.util.zip.ZipEntry;
    6160import java.util.zip.ZipFile;
    6261import java.util.zip.ZipInputStream;
     
    7170import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
    7271import org.openstreetmap.josm.Main;
     72import org.openstreetmap.josm.io.Compression;
    7373import org.w3c.dom.Document;
    7474import org.xml.sax.InputSource;
     
    727727     * @throws IOException if the given input stream does not contain valid BZ2 header
    728728     * @since 7867
    729      */
     729     * @deprecated use {@link Compression#getBZip2InputStream(java.io.InputStream)}
     730     */
     731    @Deprecated
    730732    public static BZip2CompressorInputStream getBZip2InputStream(InputStream in) throws IOException {
    731         if (in == null) {
    732             return null;
    733         }
    734         return new BZip2CompressorInputStream(in, /* see #9537 */ true);
     733        return Compression.getBZip2InputStream(in);
    735734    }
    736735
     
    741740     * @throws IOException if an I/O error has occurred
    742741     * @since 7119
    743      */
     742     * @deprecated use {@link Compression#getGZipInputStream(java.io.InputStream)}
     743     */
     744    @Deprecated
    744745    public static GZIPInputStream getGZipInputStream(InputStream in) throws IOException {
    745         if (in == null) {
    746             return null;
    747         }
    748         return new GZIPInputStream(in);
     746        return Compression.getGZipInputStream(in);
    749747    }
    750748
     
    755753     * @throws IOException if an I/O error has occurred
    756754     * @since 7119
    757      */
     755     * @deprecated use {@link Compression#getZipInputStream(java.io.InputStream)}
     756     */
     757    @Deprecated
    758758    public static ZipInputStream getZipInputStream(InputStream in) throws IOException {
    759         if (in == null) {
    760             return null;
    761         }
    762         ZipInputStream zis = new ZipInputStream(in, StandardCharsets.UTF_8);
    763         // Positions the stream at the beginning of first entry
    764         ZipEntry ze = zis.getNextEntry();
    765         if (ze != null && Logging.isDebugEnabled()) {
    766             Logging.debug("Zip entry: {0}", ze.getName());
    767         }
    768         return zis;
     759        return Compression.getZipInputStream(in);
    769760    }
    770761
Note: See TracChangeset for help on using the changeset viewer.