cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1127196 - in /cxf/trunk: common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java rt/core/src/main/java/org/apache/cxf/attachment/DelegatingInputStream.java
Date Tue, 24 May 2011 18:24:04 GMT
Author: dkulp
Date: Tue May 24 18:24:04 2011
New Revision: 1127196

URL: http://svn.apache.org/viewvc?rev=1127196&view=rev
Log:
[CXF-3504] Use a faster method to consume the stream

Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/DelegatingInputStream.java

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java?rev=1127196&r1=1127195&r2=1127196&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java Tue May 24 18:24:04
2011
@@ -235,6 +235,30 @@ public final class IOUtils {
         in.close();
         return bout.createInputStream();
     }
+    
+    public static void consume(InputStream in) throws IOException {
+        int i = in.available();
+        if (i == 0) {
+            //if i is 0, then we MAY have already hit the end of the stream
+            //so try a read and return rather than allocate a buffer and such 
+            int i2 = in.read();
+            if (i2 == -1) {
+                return;
+            }
+            //reading the byte may have caused a buffer to fill
+            i = in.available();
+        }
+        if (i < DEFAULT_BUFFER_SIZE) {
+            i = DEFAULT_BUFFER_SIZE;
+        }
+        if (i > 65536) {
+            i = 65536;
+        }
+        byte bytes[] = new byte[i];
+        while (in.read(bytes) != -1) {
+            //nothing - just discarding
+        }
+    }
 
     public static byte[] readBytesFromStream(InputStream in) throws IOException {
         int i = in.available();

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/DelegatingInputStream.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/DelegatingInputStream.java?rev=1127196&r1=1127195&r2=1127196&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/DelegatingInputStream.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/DelegatingInputStream.java Tue
May 24 18:24:04 2011
@@ -23,6 +23,8 @@ package org.apache.cxf.attachment;
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.cxf.helpers.IOUtils;
+
 public class DelegatingInputStream extends InputStream {
     private InputStream is;
     private AttachmentDeserializer deserializer;
@@ -42,10 +44,7 @@ public class DelegatingInputStream exten
 
     @Override
     public void close() throws IOException {
-        int x = is.read();
-        while (x != -1) {
-            x = is.read();
-        }
+        IOUtils.consume(is);
         is.close();
         if (!isClosed && deserializer != null) {
             deserializer.markClosed(this);



Mime
View raw message