geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickmcgu...@apache.org
Subject svn commit: r593128 - /geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/org/apache/geronimo/mail/handlers/TextHandler.java
Date Thu, 08 Nov 2007 10:56:20 GMT
Author: rickmcguire
Date: Thu Nov  8 02:56:19 2007
New Revision: 593128

URL: http://svn.apache.org/viewvc?rev=593128&view=rev
Log:
GERONIMO-3590 javamail TextHandler fails when content stream is ByteArrayInputStream.


Modified:
    geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/org/apache/geronimo/mail/handlers/TextHandler.java

Modified: geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/org/apache/geronimo/mail/handlers/TextHandler.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/org/apache/geronimo/mail/handlers/TextHandler.java?rev=593128&r1=593127&r2=593128&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/org/apache/geronimo/mail/handlers/TextHandler.java
(original)
+++ geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/org/apache/geronimo/mail/handlers/TextHandler.java
Thu Nov  8 02:56:19 2007
@@ -20,7 +20,9 @@
 package org.apache.geronimo.mail.handlers;
 
 import java.awt.datatransfer.DataFlavor;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
@@ -95,19 +97,24 @@
      * @throws IOException
      */
     public Object getContent(DataSource datasource) throws IOException {
-        InputStreamReader reader;
+        InputStream is = datasource.getInputStream(); 
+        ByteArrayOutputStream os = new ByteArrayOutputStream(); 
+        
+        int count;  
+        byte[] buffer = new byte[1000]; 
+            
         try {
-            String s = getCharSet(datasource.getContentType());
-            reader = new InputStreamReader(datasource.getInputStream(), s);
-        } catch (Exception ex) {
-            throw new UnsupportedEncodingException(ex.toString());
+            while ((count = is.read(buffer, 0, buffer.length)) > 0) {
+                os.write(buffer, 0, count); 
+            }
+        } finally {
+            is.close(); 
         }
-        StringWriter writer = new StringWriter();
-        int ch;
-        while ((ch = reader.read()) != -1) {
-            writer.write(ch);
+        try {   
+            return os.toString(getCharSet(datasource.getContentType())); 
+        } catch (ParseException e) {
+            throw new UnsupportedEncodingException(e.getMessage()); 
         }
-        return writer.getBuffer().toString();
     }
 
     /**



Mime
View raw message