Changeset 12772 in josm for trunk/src/org/openstreetmap/josm/io
- Timestamp:
- 2017-09-07T21:24:42+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/Compression.java
r10223 r12772 9 9 import java.io.OutputStream; 10 10 import java.nio.charset.StandardCharsets; 11 import java.util.zip.GZIPInputStream; 11 12 import java.util.zip.GZIPOutputStream; 13 import java.util.zip.ZipEntry; 14 import java.util.zip.ZipInputStream; 12 15 import java.util.zip.ZipOutputStream; 13 16 17 import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; 14 18 import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; 19 import org.openstreetmap.josm.tools.Logging; 15 20 import org.openstreetmap.josm.tools.Utils; 16 21 … … 79 84 switch (this) { 80 85 case BZIP2: 81 return Utils.getBZip2InputStream(in);86 return getBZip2InputStream(in); 82 87 case GZIP: 83 return Utils.getGZipInputStream(in);88 return getGZipInputStream(in); 84 89 case ZIP: 85 return Utils.getZipInputStream(in);90 return getZipInputStream(in); 86 91 case NONE: 87 92 default: 88 93 return in; 89 94 } 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; 90 143 } 91 144
Note:
See TracChangeset
for help on using the changeset viewer.