- Timestamp:
- 2017-09-07T21:24:42+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 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 -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r12703 r12772 58 58 import java.util.stream.Stream; 59 59 import java.util.zip.GZIPInputStream; 60 import java.util.zip.ZipEntry;61 60 import java.util.zip.ZipFile; 62 61 import java.util.zip.ZipInputStream; … … 71 70 import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; 72 71 import org.openstreetmap.josm.Main; 72 import org.openstreetmap.josm.io.Compression; 73 73 import org.w3c.dom.Document; 74 74 import org.xml.sax.InputSource; … … 727 727 * @throws IOException if the given input stream does not contain valid BZ2 header 728 728 * @since 7867 729 */ 729 * @deprecated use {@link Compression#getBZip2InputStream(java.io.InputStream)} 730 */ 731 @Deprecated 730 732 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); 735 734 } 736 735 … … 741 740 * @throws IOException if an I/O error has occurred 742 741 * @since 7119 743 */ 742 * @deprecated use {@link Compression#getGZipInputStream(java.io.InputStream)} 743 */ 744 @Deprecated 744 745 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); 749 747 } 750 748 … … 755 753 * @throws IOException if an I/O error has occurred 756 754 * @since 7119 757 */ 755 * @deprecated use {@link Compression#getZipInputStream(java.io.InputStream)} 756 */ 757 @Deprecated 758 758 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); 769 760 } 770 761
Note:
See TracChangeset
for help on using the changeset viewer.