commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [5/5] commons-compress git commit: move System.in logic back to bzip2 stream class
Date Sat, 04 Feb 2017 19:21:21 GMT
move System.in logic back to bzip2 stream class


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/c1a6e38e
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/c1a6e38e
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/c1a6e38e

Branch: refs/heads/PR13
Commit: c1a6e38e4401e7c693ccc14f8cb175e057d01a10
Parents: 2adac25
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Sat Feb 4 19:48:00 2017 +0100
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Sat Feb 4 19:48:00 2017 +0100

----------------------------------------------------------------------
 .../bzip2/BZip2CompressorInputStream.java       |  4 +-
 .../commons/compress/utils/BitInputStream.java  |  4 +-
 .../utils/CloseShieldFilterInputStream.java     | 41 ++++++++++++++++++++
 3 files changed, 45 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/c1a6e38e/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
b/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
index a6e2d10..bce1d3d 100644
--- a/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
+++ b/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
@@ -31,6 +31,7 @@ import java.util.Arrays;
 
 import org.apache.commons.compress.compressors.CompressorInputStream;
 import org.apache.commons.compress.utils.BitInputStream;
+import org.apache.commons.compress.utils.CloseShieldFilterInputStream;
 
 /**
  * An input stream that decompresses from the BZip2 format to be read as any other stream.
@@ -126,7 +127,8 @@ public class BZip2CompressorInputStream extends CompressorInputStream
implements
      *             if {@code in == null}, the stream content is malformed, or an I/O error
occurs.
      */
     public BZip2CompressorInputStream(final InputStream in, final boolean decompressConcatenated)
throws IOException {
-        this.bin = new BitInputStream(in, ByteOrder.BIG_ENDIAN);
+        this.bin = new BitInputStream(in == System.in ? new CloseShieldFilterInputStream(in)
: in,
+            ByteOrder.BIG_ENDIAN);
         this.decompressConcatenated = decompressConcatenated;
 
         init(true);

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/c1a6e38e/src/main/java/org/apache/commons/compress/utils/BitInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/utils/BitInputStream.java b/src/main/java/org/apache/commons/compress/utils/BitInputStream.java
index 387e804..e53a381 100644
--- a/src/main/java/org/apache/commons/compress/utils/BitInputStream.java
+++ b/src/main/java/org/apache/commons/compress/utils/BitInputStream.java
@@ -56,9 +56,7 @@ public class BitInputStream implements Closeable {
 
     @Override
     public void close() throws IOException {
-        if (in != System.in) {
-            in.close();
-        }
+        in.close();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/c1a6e38e/src/main/java/org/apache/commons/compress/utils/CloseShieldFilterInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/utils/CloseShieldFilterInputStream.java
b/src/main/java/org/apache/commons/compress/utils/CloseShieldFilterInputStream.java
new file mode 100644
index 0000000..a0ec8ff
--- /dev/null
+++ b/src/main/java/org/apache/commons/compress/utils/CloseShieldFilterInputStream.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.commons.compress.utils;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Re-implements {@link FilterInputStream#close()} to do nothing.
+ * @since 1.14
+ */
+public class CloseShieldFilterInputStream extends FilterInputStream {
+
+    public CloseShieldFilterInputStream(InputStream in) {
+        super(in);
+    }
+
+    @Override
+    public void close() throws IOException {
+        // NO IMPLEMENTATION.
+    }
+
+}


Mime
View raw message