Skip to content

Commit

Permalink
COMPRESS-441 tweaks by Dawid Weiss
Browse files Browse the repository at this point in the history
closes #60
  • Loading branch information
bodewig committed Jan 14, 2018
1 parent 8efea83 commit b2fac80
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Expand Up @@ -139,7 +139,10 @@ InputStream decode(final String archiveName, final InputStream in, final long un
final Coder coder, final byte[] password)
throws IOException {
final Inflater inflater = new Inflater(true);
// Inflater requires an extra dummy byte, see
// Inflater with nowrap=true has this odd contract for a zero padding
// byte following the data stream; this used to be zlib's requirement
// and has been fixed a long time ago, but the contract persists so
// we comply.
// https://docs.oracle.com/javase/7/docs/api/java/util/zip/Inflater.html#Inflater(boolean)
final InflaterInputStream inflaterInputStream = new InflaterInputStream(new SequenceInputStream(in,
new ByteArrayInputStream(ONE_ZERO_BYTE)), inflater);
Expand Down
Expand Up @@ -484,22 +484,24 @@ public InputStream getInputStream(final ZipArchiveEntry ze)
// doesn't get closed if the method is not supported - which
// should never happen because of the checkRequestedFeatures
// call above
final BoundedInputStream bis =
createBoundedInputStream(start, ze.getCompressedSize()); //NOSONAR
final InputStream buf = new BufferedInputStream(bis); //NOSONAR
final InputStream is =
new BufferedInputStream(createBoundedInputStream(start, ze.getCompressedSize())); //NOSONAR
switch (ZipMethod.getMethodByCode(ze.getMethod())) {
case STORED:
return bis;
return is;
case UNSHRINKING:
return new UnshrinkingInputStream(buf);
return new UnshrinkingInputStream(is);
case IMPLODING:
return new ExplodingInputStream(ze.getGeneralPurposeBit().getSlidingDictionarySize(),
ze.getGeneralPurposeBit().getNumberOfShannonFanoTrees(), buf);
ze.getGeneralPurposeBit().getNumberOfShannonFanoTrees(), is);
case DEFLATED:
final Inflater inflater = new Inflater(true);
// Inflater requires an extra dummy byte, see
// Inflater with nowrap=true has this odd contract for a zero padding
// byte following the data stream; this used to be zlib's requirement
// and has been fixed a long time ago, but the contract persists so
// we comply.
// https://docs.oracle.com/javase/7/docs/api/java/util/zip/Inflater.html#Inflater(boolean)
return new InflaterInputStream(new SequenceInputStream(buf, new ByteArrayInputStream(ONE_ZERO_BYTE)),
return new InflaterInputStream(new SequenceInputStream(is, new ByteArrayInputStream(ONE_ZERO_BYTE)),
inflater) {
@Override
public void close() throws IOException {
Expand All @@ -511,9 +513,9 @@ public void close() throws IOException {
}
};
case BZIP2:
return new BZip2CompressorInputStream(buf);
return new BZip2CompressorInputStream(is);
case ENHANCED_DEFLATED:
return new Deflate64CompressorInputStream(buf);
return new Deflate64CompressorInputStream(is);
case AES_ENCRYPTED:
case EXPANDING_LEVEL_1:
case EXPANDING_LEVEL_2:
Expand Down

0 comments on commit b2fac80

Please sign in to comment.