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

see #15229 - move compression methods from Utils to Compression

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.