cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6579] Finalizing it with the code prepared by Phillip Klinefelter
Date Thu, 10 Sep 2015 09:32:08 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 3ad862c9d -> 91278f9fd


[CXF-6579] Finalizing it with the code prepared by Phillip Klinefelter


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/91278f9f
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/91278f9f
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/91278f9f

Branch: refs/heads/master
Commit: 91278f9fdcc4fd1d5037d30cb0ba93cea10104b3
Parents: 3ad862c
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Thu Sep 10 10:31:49 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu Sep 10 10:31:49 2015 +0100

----------------------------------------------------------------------
 .../cxf/common/util/CompressionUtils.java       | 45 +++++++-------------
 1 file changed, 16 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/91278f9f/core/src/main/java/org/apache/cxf/common/util/CompressionUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/common/util/CompressionUtils.java b/core/src/main/java/org/apache/cxf/common/util/CompressionUtils.java
index a67a789..6fbf2a4 100644
--- a/core/src/main/java/org/apache/cxf/common/util/CompressionUtils.java
+++ b/core/src/main/java/org/apache/cxf/common/util/CompressionUtils.java
@@ -19,8 +19,8 @@
 package org.apache.cxf.common.util;
 
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
-import java.io.SequenceInputStream;
 import java.util.zip.DataFormatException;
 import java.util.zip.Deflater;
 import java.util.zip.Inflater;
@@ -35,39 +35,26 @@ public final class CompressionUtils {
     }
     public static InputStream inflate(byte[] deflatedToken, boolean nowrap) 
         throws DataFormatException {
-        Inflater inflater = new Inflater(nowrap);
+        Inflater inflater = new Inflater(true);
         inflater.setInput(deflatedToken);
-        
-        byte[] input = new byte[deflatedToken.length * 2];
-        int inflatedLen = 0;
-        int inputLen = 0;
-        byte[] inflatedToken = input;
+
+        byte[] buffer = new byte[deflatedToken.length];
+        int inflateLen;
+        ByteArrayOutputStream inflatedToken = new ByteArrayOutputStream();
         while (!inflater.finished()) {
-            inputLen = inflater.inflate(input);
-            if (!inflater.finished()) {
-                
-                if (inputLen == 0) {
-                    if (inflater.needsInput()) {
-                        throw new DataFormatException("Inflater can not inflate all the token
bytes");
-                    } else {
-                        break;
-                    }
-                }
-                byte[] lastInflatedToken = inflatedToken;
-                inflatedToken = new byte[input.length + inflatedLen];
-                if (lastInflatedToken != input) {
-                    System.arraycopy(lastInflatedToken, 0, inflatedToken, 0, inflatedLen);
+            inflateLen = inflater.inflate(buffer, 0, deflatedToken.length);
+            if (inflateLen == 0 && !inflater.finished()) {
+                if (inflater.needsInput()) {
+                    throw new DataFormatException("Inflater can not inflate all the token
bytes");
+                } else {
+                    break;
                 }
-                System.arraycopy(input, 0, inflatedToken, inflatedLen, inputLen);
-                inflatedLen += inputLen;
             }
+            
+            inflatedToken.write(buffer, 0, inflateLen);
         }
-        InputStream is = new ByteArrayInputStream(input, 0, inputLen);
-        if (inflatedToken != input) {
-            is = new SequenceInputStream(new ByteArrayInputStream(inflatedToken, 0, inflatedLen),
-                                         is);
-        }
-        return is;
+
+        return new ByteArrayInputStream(inflatedToken.toByteArray());
     }
     
     public static byte[] deflate(byte[] tokenBytes) {


Mime
View raw message