cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1127200 - in /cxf/branches/2.3.x-fixes: ./ 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:28:41 GMT
Author: dkulp
Date: Tue May 24 18:28:41 2011
New Revision: 1127200

URL: http://svn.apache.org/viewvc?rev=1127200&view=rev
Log:
Merged revisions 1127196 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1127196 | dkulp | 2011-05-24 14:24:04 -0400 (Tue, 24 May 2011) | 1 line
  
  [CXF-3504] Use a faster method to consume the stream
........

Modified:
    cxf/branches/2.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
    cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/DelegatingInputStream.java

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java?rev=1127200&r1=1127199&r2=1127200&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
(original)
+++ cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
Tue May 24 18:28:41 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/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/DelegatingInputStream.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/DelegatingInputStream.java?rev=1127200&r1=1127199&r2=1127200&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/DelegatingInputStream.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/DelegatingInputStream.java
Tue May 24 18:28:41 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