james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mwiederk...@apache.org
Subject svn commit: r784087 - in /james/mime4j/trunk/core/src: main/java/org/apache/james/mime4j/ main/java/org/apache/james/mime4j/io/ main/java/org/apache/james/mime4j/parser/ test/java/org/apache/james/mime4j/ test/java/org/apache/james/mime4j/parser/
Date Fri, 12 Jun 2009 11:59:10 GMT
Author: mwiederkehr
Date: Fri Jun 12 11:59:10 2009
New Revision: 784087

URL: http://svn.apache.org/viewvc?rev=784087&view=rev
Log:
removed constructor MimeIOException(String); MaxLineLimitException now extends IOException
instead of MimeIOException; additional javadoc for MimeException and MimeIOException (resolves
MIME4J-137).

Modified:
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/MimeException.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/MimeIOException.java
    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/LineReaderInputStream.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineReaderInputStreamAdaptor.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MaxLineLimitException.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/AbstractEntity.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/MimeIOExceptionTest.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeEntityTest.java

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/MimeException.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/MimeException.java?rev=784087&r1=784086&r2=784087&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/MimeException.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/MimeException.java Fri Jun
12 11:59:10 2009
@@ -19,8 +19,18 @@
 
 package org.apache.james.mime4j;
 
+import org.apache.james.mime4j.parser.ContentHandler;
+
 /**
  * MIME processing exception.
+ * <p>
+ * A <code>MimeException</code> may be thrown by a {@link ContentHandler} to
+ * indicate that it has failed to process a message event and that no further
+ * events should be generated.
+ * <p>
+ * <code>MimeException</code> also gets thrown by the parser to indicate MIME
+ * protocol errors, e.g. if a message boundary is too long or a header field
+ * cannot be parsed.
  */
 public class MimeException extends Exception {
 

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/MimeIOException.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/MimeIOException.java?rev=784087&r1=784086&r2=784087&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/MimeIOException.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/MimeIOException.java Fri
Jun 12 11:59:10 2009
@@ -23,28 +23,36 @@
 
 /**
  * A wrapper class based on {@link IOException} for MIME protocol exceptions.
+ * <p>
+ * This exception is used to signal a <code>MimeException</code> in methods
+ * that only permit <code>IOException</code> to be thrown.
+ * <p>
+ * The cause of a <code>MimeIOException</code> is always a
+ * <code>MimeException</code> therefore.
  */
 public class MimeIOException extends IOException {
 
     private static final long serialVersionUID = 5393613459533735409L;
 
     /**
-     * Creates a new MimeIOException from the specified detail message.
+     * Constructs an IO exception based on {@link MimeException}.
      * 
-     * @param message detail message.
+     * @param cause the cause.
      */
-    public MimeIOException(String message) {
-        this(new MimeException(message));
+    public MimeIOException(MimeException cause) {
+        super(cause == null ? null : cause.getMessage());
+        initCause(cause);
     }
 
     /**
-     * Constructs an IO exception based on {@link MimeException}.
+     * Returns the <code>MimeException</code> that caused this
+     * <code>MimeIOException</code>.
      * 
-     * @param cause the cause.
+     * @return the cause of this <code>MimeIOException</code>.
      */
-    public MimeIOException(MimeException cause) {
-        super(cause == null ? null : cause.getMessage());
-		initCause(cause);
+    @Override
+    public MimeException getCause() {
+        return (MimeException) super.getCause();
     }
 
 }

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=784087&r1=784086&r2=784087&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
Fri Jun 12 11:59:10 2009
@@ -164,9 +164,9 @@
         return false;
     }
 
-    
     @Override
-    public int readLine(final ByteArrayBuffer dst) throws IOException {
+    public int readLine(final ByteArrayBuffer dst)
+            throws MaxLineLimitException, IOException {
         if (dst == null) {
             throw new IllegalArgumentException("Buffer may not be null");
         }

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineReaderInputStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineReaderInputStream.java?rev=784087&r1=784086&r2=784087&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineReaderInputStream.java
(original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineReaderInputStream.java
Fri Jun 12 11:59:10 2009
@@ -41,8 +41,11 @@
      * @return number of bytes copied or <code>-1</code> if the end of 
      * the stream has been reached.
      * 
+     * @throws MaxLineLimitException if the line exceeds a limit on
+     *   the line length imposed by a subclass.
      * @throws IOException in case of an I/O error.
      */
-    public abstract int readLine(final ByteArrayBuffer dst) throws IOException;
-    
+    public abstract int readLine(final ByteArrayBuffer dst)
+            throws MaxLineLimitException, IOException;
+
 }

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineReaderInputStreamAdaptor.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineReaderInputStreamAdaptor.java?rev=784087&r1=784086&r2=784087&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineReaderInputStreamAdaptor.java
(original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineReaderInputStreamAdaptor.java
Fri Jun 12 11:59:10 2009
@@ -71,7 +71,8 @@
     }
     
     @Override
-    public int readLine(final ByteArrayBuffer dst) throws IOException {
+    public int readLine(final ByteArrayBuffer dst)
+            throws MaxLineLimitException, IOException {
         int i;
         if (this.bis != null) {
              i = this.bis.readLine(dst);
@@ -83,7 +84,8 @@
         return i;
     }
 
-    private int doReadLine(final ByteArrayBuffer dst) throws IOException {
+    private int doReadLine(final ByteArrayBuffer dst)
+            throws MaxLineLimitException, IOException {
         int total = 0;
         int ch;
         while ((ch = in.read()) != -1) {

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MaxLineLimitException.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MaxLineLimitException.java?rev=784087&r1=784086&r2=784087&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MaxLineLimitException.java
(original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MaxLineLimitException.java
Fri Jun 12 11:59:10 2009
@@ -19,15 +19,15 @@
 
 package org.apache.james.mime4j.io;
 
-import org.apache.james.mime4j.MimeIOException;
+import java.io.IOException;
 
 /**
- * Signals a I/O error due to a line exceeding the limit on the 
- * maximum line length.
+ * Signals an I/O error due to a line exceeding the limit on the maximum line
+ * length.
  */
-public class MaxLineLimitException extends MimeIOException {
-    
-    private static final long serialVersionUID = 8039001187837730773L;
+public class MaxLineLimitException extends IOException {
+
+    private static final long serialVersionUID = 1855987166990764426L;
 
     public MaxLineLimitException(final String message) {
         super(message);

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/AbstractEntity.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/AbstractEntity.java?rev=784087&r1=784086&r2=784087&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/AbstractEntity.java
(original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/AbstractEntity.java
Fri Jun 12 11:59:10 2009
@@ -130,43 +130,48 @@
         LineReaderInputStream instream = getDataStream();
         ByteArrayBuffer fieldbuf = new ByteArrayBuffer(64);
 
-        for (;;) {
-            // If there's still data stuck in the line buffer
-            // copy it to the field buffer
-            int len = linebuf.length();
-            if (maxLineLen > 0 && fieldbuf.length() + len >= maxLineLen) {
-                throw new MaxLineLimitException("Maximum line length limit exceeded");
-            }
-            if (len > 0) {
-                fieldbuf.append(linebuf.buffer(), 0, len);
-            }
-            linebuf.clear();
-            if (instream.readLine(linebuf) == -1) {
-                monitor(Event.HEADERS_PREMATURE_END);
-                endOfHeader = true;
-                break;
-            }
-            len = linebuf.length();
-            if (len > 0 && linebuf.byteAt(len - 1) == '\n') {
-                len--;
-            }
-            if (len > 0 && linebuf.byteAt(len - 1) == '\r') {
-                len--;
-            }
-            if (len == 0) {
-                // empty line detected 
-                endOfHeader = true;
-                break;
-            }
-            lineCount++;
-            if (lineCount > 1) {
-                int ch = linebuf.byteAt(0);
-                if (ch != CharsetUtil.SP && ch != CharsetUtil.HT) {
-                    // new header detected
+        try {
+            for (;;) {
+                // If there's still data stuck in the line buffer
+                // copy it to the field buffer
+                int len = linebuf.length();
+                if (maxLineLen > 0 && fieldbuf.length() + len >= maxLineLen)
{
+                    throw new MaxLineLimitException("Maximum line length limit exceeded");
+                }
+                if (len > 0) {
+                    fieldbuf.append(linebuf.buffer(), 0, len);
+                }
+                linebuf.clear();
+                if (instream.readLine(linebuf) == -1) {
+                    monitor(Event.HEADERS_PREMATURE_END);
+                    endOfHeader = true;
+                    break;
+                }
+                len = linebuf.length();
+                if (len > 0 && linebuf.byteAt(len - 1) == '\n') {
+                    len--;
+                }
+                if (len > 0 && linebuf.byteAt(len - 1) == '\r') {
+                    len--;
+                }
+                if (len == 0) {
+                    // empty line detected 
+                    endOfHeader = true;
                     break;
                 }
+                lineCount++;
+                if (lineCount > 1) {
+                    int ch = linebuf.byteAt(0);
+                    if (ch != CharsetUtil.SP && ch != CharsetUtil.HT) {
+                        // new header detected
+                        break;
+                    }
+                }
             }
         }
+        catch (MaxLineLimitException e) {
+            throw new MimeException(e);
+        }
 
         return fieldbuf;
     }

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/MimeIOExceptionTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/MimeIOExceptionTest.java?rev=784087&r1=784086&r2=784087&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/MimeIOExceptionTest.java
(original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/MimeIOExceptionTest.java
Fri Jun 12 11:59:10 2009
@@ -23,14 +23,6 @@
 
 public class MimeIOExceptionTest extends TestCase {
 
-    public void testMimeIOExceptionString() {
-        MimeIOException e =  new MimeIOException("message");
-        assertEquals("message", e.getMessage());
-        assertNotNull(e.getCause());
-        assertTrue(e.getCause() instanceof MimeException);
-        assertEquals("message", e.getCause().getMessage());
-    }
-
     public void testMimeIOExceptionMimeException() {
         MimeException cause = new MimeException("cause");
         MimeIOException e = new MimeIOException(cause);

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeEntityTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeEntityTest.java?rev=784087&r1=784086&r2=784087&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeEntityTest.java
(original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeEntityTest.java
Fri Jun 12 11:59:10 2009
@@ -23,6 +23,7 @@
 import java.io.IOException;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.io.BufferedLineReaderInputStream;
 import org.apache.james.mime4j.io.MaxHeaderLimitException;
 import org.apache.james.mime4j.io.MaxLineLimitException;
@@ -366,8 +367,9 @@
         assertEquals(EntityStates.T_FIELD, entity.getState());
         try {
             entity.advance();
-            fail("MaxLineLimitException should have been thrown");
-        } catch (MaxLineLimitException expected) {
+            fail("MimeException caused by MaxLineLimitException should have been thrown");
+        } catch (MimeException expected) {
+            assertTrue(expected.getCause() instanceof MaxLineLimitException);
         }
     }
     
@@ -420,8 +422,9 @@
         assertEquals(EntityStates.T_FIELD, entity.getState());
         try {
             entity.advance();
-            fail("MaxLineLimitException should have been thrown");
-        } catch (MaxLineLimitException expected) {
+            fail("MimeException caused by MaxLineLimitException should have been thrown");
+        } catch (MimeException expected) {
+            assertTrue(expected.getCause() instanceof MaxLineLimitException);
         }
     }
 



Mime
View raw message