hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r581564 - in /jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/codecs: TestIdentityDecoder.java TestLengthDelimitedDecoder.java
Date Wed, 03 Oct 2007 11:15:17 GMT
Author: olegk
Date: Wed Oct  3 04:15:15 2007
New Revision: 581564

URL: http://svn.apache.org/viewvc?rev=581564&view=rev
Log:
Removed Java 1.5 dependent code 

Modified:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/codecs/TestIdentityDecoder.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedDecoder.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/codecs/TestIdentityDecoder.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/codecs/TestIdentityDecoder.java?rev=581564&r1=581563&r2=581564&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/codecs/TestIdentityDecoder.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/codecs/TestIdentityDecoder.java
Wed Oct  3 04:15:15 2007
@@ -35,7 +35,6 @@
 import java.io.FileOutputStream;
 import java.io.InputStreamReader;
 import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
 import java.nio.channels.FileChannel;
 import java.nio.channels.ReadableByteChannel;
 
@@ -85,15 +84,25 @@
         return buffer.toString();
     }
     
-    private static String readFromFile(File file, int numChars) throws Exception {
-        FileInputStream fin = new FileInputStream(file);
-        InputStreamReader rdin = new InputStreamReader(fin);
-                
-        CharBuffer cb = CharBuffer.allocate(numChars);
-        rdin.read(cb);
-        
-        fin.close();
-        return cb.flip().toString();
+    private static String readFromFile(final File file, int numChars) throws Exception {
+        FileInputStream filestream = new FileInputStream(file);
+        InputStreamReader reader = new InputStreamReader(filestream);
+        try {
+            StringBuffer buffer = new StringBuffer(numChars);
+            char[] tmp = new char[Math.min(2048, numChars)];
+            int remaining = numChars;
+            while (remaining > 0) {
+                int l = reader.read(tmp);
+                if (l == -1) {
+                    break;
+                }
+                buffer.append(tmp, 0, l);
+                remaining =- l;
+            }
+            return buffer.toString();
+        } finally {
+            reader.close();
+        }
     }
 
     public void testBasicDecoding() throws Exception {

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedDecoder.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedDecoder.java?rev=581564&r1=581563&r2=581564&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedDecoder.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/codecs/TestLengthDelimitedDecoder.java
Wed Oct  3 04:15:15 2007
@@ -35,7 +35,6 @@
 import java.io.FileOutputStream;
 import java.io.InputStreamReader;
 import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
 import java.nio.channels.FileChannel;
 import java.nio.channels.ReadableByteChannel;
 
@@ -85,15 +84,25 @@
         return buffer.toString();
     }
     
-    private static String readFromFile(File file, int numChars) throws Exception {
-        FileInputStream fin = new FileInputStream(file);
-        InputStreamReader rdin = new InputStreamReader(fin);
-                
-        CharBuffer cb = CharBuffer.allocate(numChars);
-        rdin.read(cb);
-        
-        fin.close();
-        return cb.flip().toString();
+    private static String readFromFile(final File file, int numChars) throws Exception {
+        FileInputStream filestream = new FileInputStream(file);
+        InputStreamReader reader = new InputStreamReader(filestream);
+        try {
+            StringBuffer buffer = new StringBuffer(numChars);
+            char[] tmp = new char[Math.min(2048, numChars)];
+            int remaining = numChars;
+            while (remaining > 0) {
+                int l = reader.read(tmp);
+                if (l == -1) {
+                    break;
+                }
+                buffer.append(tmp, 0, l);
+                remaining =- l;
+            }
+            return buffer.toString();
+        } finally {
+            reader.close();
+        }
     }
 
     public void testBasicDecoding() throws Exception {



Mime
View raw message