directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nik...@apache.org
Subject svn commit: r379192 - /directory/trunks/mina/core/src/main/java/org/apache/mina/filter/StreamWriteFilter.java
Date Mon, 20 Feb 2006 18:29:45 GMT
Author: niklas
Date: Mon Feb 20 10:29:44 2006
New Revision: 379192

URL: http://svn.apache.org/viewcvs?rev=379192&view=rev
Log:
StreamWriteFilter now tries harder to read as much as possible from the stream at once

Modified:
    directory/trunks/mina/core/src/main/java/org/apache/mina/filter/StreamWriteFilter.java

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/filter/StreamWriteFilter.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/filter/StreamWriteFilter.java?rev=379192&r1=379191&r2=379192&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/filter/StreamWriteFilter.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/filter/StreamWriteFilter.java
Mon Feb 20 10:29:44 2006
@@ -154,17 +154,24 @@
         }
     }
 
-    private ByteBuffer getNextByteBuffer( InputStream inputStream ) throws IOException 
+    private ByteBuffer getNextByteBuffer( InputStream is ) throws IOException 
     {
         byte[] bytes = new byte[ writeBufferSize ];
-        int packetLength = inputStream.read( bytes );
-        if( packetLength == -1 )
+        
+        int off = 0;
+        int n = 0;
+        while( off < bytes.length && 
+              ( n = is.read( bytes, off, bytes.length - off ) ) != -1 )
+        {
+            off += n;
+        }
+        
+        if( n == -1 && off == 0 )
         {
             return null;
         }
 
-        ByteBuffer buffer = ByteBuffer.wrap( bytes, 0, packetLength );
-        buffer.acquire(); // prevent from being pooled.
+        ByteBuffer buffer = ByteBuffer.wrap( bytes, 0, off );
 
         return buffer;
     }



Mime
View raw message