commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1304066 - in /commons/proper/io/trunk/src: changes/changes.xml main/java/org/apache/commons/io/IOUtils.java test/java/org/apache/commons/io/IOUtilsTestCase.java
Date Thu, 22 Mar 2012 21:13:01 GMT
Author: sebb
Date: Thu Mar 22 21:13:00 2012
New Revision: 1304066

URL: http://svn.apache.org/viewvc?rev=1304066&view=rev
Log:
IO-311 IOUtils.read(InputStream/Reader) ignores the offset parameter

Modified:
    commons/proper/io/trunk/src/changes/changes.xml
    commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/IOUtilsTestCase.java

Modified: commons/proper/io/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/changes/changes.xml?rev=1304066&r1=1304065&r2=1304066&view=diff
==============================================================================
--- commons/proper/io/trunk/src/changes/changes.xml (original)
+++ commons/proper/io/trunk/src/changes/changes.xml Thu Mar 22 21:13:00 2012
@@ -40,6 +40,9 @@ The <action> type attribute can be add,u
 
   <body>
     <release version="2.2" date="TBA" description="">
+      <action issue="IO-311" dev="sebb" type="fix" due-to="Robert Muir">
+        IOUtils.read(InputStream/Reader) ignores the offset parameter
+      </action>        
       <action issue="IO-312" dev="sebb" type="fix">
         CharSequenceInputStream(CharSequence s, Charset charset, int bufferSize) ignores
bufferSize
       </action>        

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java?rev=1304066&r1=1304065&r2=1304066&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java (original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java Thu Mar 22 21:13:00
2012
@@ -1977,7 +1977,7 @@ public class IOUtils {
         int remaining = length;
         while (remaining > 0) {
             int location = length - remaining;
-            int count = input.read(buffer, location, remaining);
+            int count = input.read(buffer, offset + location, remaining);
             if (EOF == count) { // EOF
                 break;
             }
@@ -2023,7 +2023,7 @@ public class IOUtils {
         int remaining = length;
         while (remaining > 0) {
             int location = length - remaining;
-            int count = input.read(buffer, location, remaining);
+            int count = input.read(buffer, offset + location, remaining);
             if (EOF == count) { // EOF
                 break;
             }

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/IOUtilsTestCase.java?rev=1304066&r1=1304065&r2=1304066&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/IOUtilsTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/IOUtilsTestCase.java Thu Mar
22 21:13:00 2012
@@ -30,6 +30,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
+import java.io.StringReader;
 import java.net.URI;
 import java.net.URL;
 import java.nio.channels.Selector;
@@ -732,6 +733,23 @@ public class IOUtilsTestCase extends Fil
         }
         IOUtils.closeQuietly(input);
     }
+    
+    public void testReadReaderWithOffset() throws Exception {
+        Reader reader = new StringReader("abcd1234");
+        char[] buffer = "wx00000000".toCharArray();
+        IOUtils.readFully(reader, buffer, 2, 8);
+        assertEquals("wxabcd1234", new String(buffer));
+        IOUtils.closeQuietly(reader);
+    }
+    
+    public void testReadStreamWithOffset() throws Exception {
+        byte[] bytes = "abcd1234".getBytes("UTF-8");
+        ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
+        byte[] buffer = "wx00000000".getBytes("UTF-8");
+        IOUtils.readFully(stream, buffer, 2, 8);
+        assertEquals("wxabcd1234", new String(buffer, 0, buffer.length, "UTF-8"));
+        IOUtils.closeQuietly(stream);
+    }
 
     // Tests from IO-305
     



Mime
View raw message