You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mime4j-dev@james.apache.org by ol...@apache.org on 2011/06/21 17:25:54 UTC

svn commit: r1138047 - in /james/mime4j/trunk/core/src: main/java/org/apache/james/mime4j/io/ test/java/org/apache/james/mime4j/io/

Author: olegk
Date: Tue Jun 21 15:25:54 2011
New Revision: 1138047

URL: http://svn.apache.org/viewvc?rev=1138047&view=rev
Log:
Fixed broken #charAt method; renamed to #byteAt

Modified:
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/BufferedLineReaderInputStream.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamBufferTest.java

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/BufferedLineReaderInputStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/BufferedLineReaderInputStream.java?rev=1138047&r1=1138046&r2=1138047&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/BufferedLineReaderInputStream.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/BufferedLineReaderInputStream.java Tue Jun 21 15:25:54 2011
@@ -305,11 +305,11 @@ public class BufferedLineReaderInputStre
         return indexOf(b, this.bufpos, bufferLen());
     }
     
-    public byte charAt(int pos) {
+    public int byteAt(int pos) {
         if (pos < this.bufpos || pos > this.buflen) {
             throw new IndexOutOfBoundsException("looking for "+pos+" in "+bufpos+"/"+buflen);
         }
-        return this.buffer[pos];
+        return this.buffer[pos] & 0xff;
     }
     
     protected byte[] buf() {

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.java?rev=1138047&r1=1138046&r2=1138047&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.java Tue Jun 21 15:25:54 2011
@@ -231,7 +231,7 @@ public class MimeBoundaryInputStream ext
         int i = buffer.indexOf(boundary);
         // NOTE this currently check only for LF. It doesn't check for canonical CRLF
         // and neither for isolated CR. This will require updates according to MIME4J-60
-        while (i > buffer.pos() && buffer.charAt(i-1) != '\n') {
+        while (i > buffer.pos() && buffer.byteAt(i-1) != '\n') {
             // skip the "fake" boundary (it does not contain LF or CR so we cannot have
             // another boundary starting before this is complete.
             i = i + boundary.length;
@@ -265,13 +265,13 @@ public class MimeBoundaryInputStream ext
         int len = limit - buffer.pos();
         if (len >= 0 && initialLength == -1) initialLength = len;
         if (len > 0) {
-            if (buffer.charAt(limit - 1) == '\n') {
+            if (buffer.byteAt(limit - 1) == '\n') {
                 boundaryLen++;
                 limit--;
             }
         }
         if (len > 1) {
-            if (buffer.charAt(limit - 1) == '\r') {
+            if (buffer.byteAt(limit - 1) == '\r') {
                 boundaryLen++;
                 limit--;
             }
@@ -285,8 +285,8 @@ public class MimeBoundaryInputStream ext
             boolean checkForLastPart = true;
             for (;;) {
                 if (buffer.length() > 1) {
-                    int ch1 = buffer.charAt(buffer.pos());
-                    int ch2 = buffer.charAt(buffer.pos() + 1);
+                    int ch1 = buffer.byteAt(buffer.pos());
+                    int ch2 = buffer.byteAt(buffer.pos() + 1);
                     
                     if (checkForLastPart) if (ch1 == '-' && ch2 == '-') {
                         this.lastPart = true;

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamBufferTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamBufferTest.java?rev=1138047&r1=1138046&r2=1138047&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamBufferTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamBufferTest.java Tue Jun 21 15:25:54 2011
@@ -39,12 +39,12 @@ public class BufferedLineReaderInputStre
         assertEquals('l', inbuffer.read());
         
         try {
-            inbuffer.charAt(1);
+            inbuffer.byteAt(1);
             fail("IndexOutOfBoundsException should have been thrown");
         } catch (IndexOutOfBoundsException expected) {
         }
         try {
-            inbuffer.charAt(20);
+            inbuffer.byteAt(20);
             fail("IndexOutOfBoundsException should have been thrown");
         } catch (IndexOutOfBoundsException expected) {
         }