commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject commons-compress git commit: Refactor code into a reusable output stream.
Date Fri, 09 Dec 2016 02:55:12 GMT
Repository: commons-compress
Updated Branches:
  refs/heads/master 99eb4cb21 -> 77579145e


Refactor code into a reusable output stream.

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

Branch: refs/heads/master
Commit: 77579145e7f4050dd5f7677f4a427d33cafd450f
Parents: 99eb4cb
Author: Gary Gregory <ggregory@apache.org>
Authored: Thu Dec 8 18:55:10 2016 -0800
Committer: Gary Gregory <ggregory@apache.org>
Committed: Thu Dec 8 18:55:10 2016 -0800

----------------------------------------------------------------------
 .../compress/archivers/sevenz/Coders.java       |  9 +----
 .../compress/archivers/sevenz/LZMADecoder.java  | 10 ++---
 .../utils/FlushShieldFilterOutputStream.java    | 40 ++++++++++++++++++++
 3 files changed, 45 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/77579145/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java
index 8c7f1d2..ac0c319 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java
@@ -18,7 +18,6 @@
 package org.apache.commons.compress.archivers.sevenz;
 
 import java.io.FilterInputStream;
-import java.io.FilterOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -32,6 +31,7 @@ import java.util.zip.InflaterInputStream;
 
 import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
 import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
+import org.apache.commons.compress.utils.FlushShieldFilterOutputStream;
 import org.tukaani.xz.ARMOptions;
 import org.tukaani.xz.ARMThumbOptions;
 import org.tukaani.xz.FilterOptions;
@@ -118,12 +118,7 @@ class Coders {
         }
         @Override
         OutputStream encode(final OutputStream out, final Object options) {
-            final FinishableOutputStream fo = opts.getOutputStream(new FinishableWrapperOutputStream(out));
-            return new FilterOutputStream(fo) {
-                @Override
-                public void flush() {
-                }
-            };
+            return new FlushShieldFilterOutputStream(opts.getOutputStream(new FinishableWrapperOutputStream(out)));
         }
     }
     

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/77579145/src/main/java/org/apache/commons/compress/archivers/sevenz/LZMADecoder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/LZMADecoder.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/LZMADecoder.java
index 78e1fc8..5357a07 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/LZMADecoder.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/LZMADecoder.java
@@ -17,11 +17,11 @@
  */
 package org.apache.commons.compress.archivers.sevenz;
 
-import java.io.FilterOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
+import org.apache.commons.compress.utils.FlushShieldFilterOutputStream;
 import org.tukaani.xz.LZMA2Options;
 import org.tukaani.xz.LZMAInputStream;
 import org.tukaani.xz.LZMAOutputStream;
@@ -46,12 +46,8 @@ class LZMADecoder extends CoderBase {
     @Override
     OutputStream encode(final OutputStream out, final Object opts)
         throws IOException {
-        return new FilterOutputStream(new LZMAOutputStream(out, getOptions(opts), false))
{
-            @Override
-            public void flush() {
-                // NOOP as LZMAOutputStream throws an exception in flush
-            }
-        };
+        // NOOP as LZMAOutputStream throws an exception in flush
+        return new FlushShieldFilterOutputStream(new LZMAOutputStream(out, getOptions(opts),
false));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/77579145/src/main/java/org/apache/commons/compress/utils/FlushShieldFilterOutputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/utils/FlushShieldFilterOutputStream.java
b/src/main/java/org/apache/commons/compress/utils/FlushShieldFilterOutputStream.java
new file mode 100644
index 0000000..d087780
--- /dev/null
+++ b/src/main/java/org/apache/commons/compress/utils/FlushShieldFilterOutputStream.java
@@ -0,0 +1,40 @@
+/*
+ * 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.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * Re-implements {@link flush()} to do nothing.
+ */
+public class FlushShieldFilterOutputStream extends FilterOutputStream {
+
+    public FlushShieldFilterOutputStream(OutputStream out) {
+        super(out);
+    }
+
+    @Override
+    public void flush() throws IOException {
+        // NO IMPLEMENTATION.
+    }
+
+}


Mime
View raw message