geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject svn commit: r154541 - in geronimo/trunk/specs/javamail/src: java/javax/mail/internet/MimeBodyPart.java java/javax/mail/internet/MimeMultipart.java test/javax/mail/internet/MimeMessageTest.java test/javax/mail/internet/MimeMultipartTest.java
Date Sun, 20 Feb 2005 18:01:50 GMT
Author: jboynes
Date: Sun Feb 20 10:01:49 2005
New Revision: 154541

URL: http://svn.apache.org/viewcvs?view=rev&rev=154541
Log:
make writeTo go directly to the stream to avoid String conversion

Added:
    geronimo/trunk/specs/javamail/src/test/javax/mail/internet/MimeMultipartTest.java
Modified:
    geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeBodyPart.java
    geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeMultipart.java
    geronimo/trunk/specs/javamail/src/test/javax/mail/internet/MimeMessageTest.java

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeBodyPart.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeBodyPart.java?view=diff&r1=154540&r2=154541
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeBodyPart.java (original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeBodyPart.java Sun Feb 20
10:01:49 2005
@@ -208,7 +208,7 @@
         headers.writeTo(out, null);
         out.write(13);
         out.write(10);
-        out.write(content);
+        getDataHandler().writeTo(out);
     }
 
     public String[] getHeader(String name) throws MessagingException {

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeMultipart.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeMultipart.java?view=diff&r1=154540&r2=154541
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeMultipart.java (original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeMultipart.java Sun Feb
20 10:01:49 2005
@@ -113,23 +113,24 @@
     }
 
     private static byte[] dash = { '-', '-' };
+    private static byte[] crlf = { 13, 10 };
 
     public void writeTo(OutputStream out) throws IOException, MessagingException {
         parse();
         String boundary = type.getParameter("boundary");
         byte[] bytes = boundary.getBytes();
-        PrintStream pos = new PrintStream(out, false);
         for (int i = 0; i < parts.size(); i++) {
             BodyPart bodyPart = (BodyPart) parts.get(i);
-            pos.print(dash);
-            pos.println(bytes);
-            bodyPart.writeTo(pos);
-            pos.println();
+            out.write(dash);
+            out.write(bytes);
+            out.write(crlf);
+            bodyPart.writeTo(out);
+            out.write(crlf);
         }
-        pos.print(dash);
-        pos.print(bytes);
-        pos.println(dash);
-        pos.flush();
+        out.write(dash);
+        out.write(bytes);
+        out.write(crlf);
+        out.flush();
     }
 
     protected void parse() throws MessagingException {

Modified: geronimo/trunk/specs/javamail/src/test/javax/mail/internet/MimeMessageTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/test/javax/mail/internet/MimeMessageTest.java?view=diff&r1=154540&r2=154541
==============================================================================
--- geronimo/trunk/specs/javamail/src/test/javax/mail/internet/MimeMessageTest.java (original)
+++ geronimo/trunk/specs/javamail/src/test/javax/mail/internet/MimeMessageTest.java Sun Feb
20 10:01:49 2005
@@ -17,16 +17,12 @@
 
 package javax.mail.internet;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-
-import javax.mail.Message;
+import java.util.Properties;
 import javax.mail.MessagingException;
-import javax.mail.Part;
+import javax.mail.Session;
+import javax.activation.CommandMap;
+import javax.activation.MailcapCommandMap;
 
 import junit.framework.TestCase;
 
@@ -34,87 +30,31 @@
  * @version $Rev$ $Date$
  */
 public class MimeMessageTest extends TestCase {
-    public void testNothing() {
+    private CommandMap defaultMap;
+    private Session session;
+
+    public void testWriteTo() throws MessagingException, IOException {
+/*
+        MimeMessage msg = new MimeMessage(session);
+        msg.setSender(new InternetAddress("foo"));
+        MimeMultipart mp = new MimeMultipart();
+        MimeBodyPart part1 = new MimeBodyPart();
+        part1.setContent("Hello World", "text/plain");
+        mp.addBodyPart(part1);
+        msg.setContent(mp);
+        msg.writeTo(System.out);
+*/
     }
-    /*
-    private static final String EOL = "\r\n";
-    private static final String users =
-        "Geronimo Users <geronimo-user@apache.org>";
-    private static final String developers =
-        "Geronimo Developers <geronimo-dev@apache.org>";
-    private static final String announce =
-        "Geronimo Team <geronimo-announce@apache.org>";
 
-    public void testMimeMessage() throws MessagingException {
-        StringBuffer buffer = new StringBuffer();
-        buffer.append("To: " + users);
-        buffer.append(EOL);
-        buffer.append("To: " + developers);
-        buffer.append(EOL);
-        buffer.append("Subject: New   ");
-        buffer.append(EOL);
-        buffer.append("   release");
-        buffer.append(EOL);
-        buffer.append("From: " + announce);
-        buffer.append(EOL);
-        buffer.append("Bcc: " + announce);
-        buffer.append(EOL);
-        buffer.append(EOL);
-        buffer.append("Hello World");
-        byte[] data = buffer.toString().getBytes();
-        InputStream in = new ByteArrayInputStream(data);
-        MimeMessage message = new MimeMessage(null, in);
-        List to =
-            Arrays.asList(message.getRecipients(Message.RecipientType.TO));
-        assertEquals(2, to.size());
-        assertTrue(to.contains(new InternetAddress(users)));
-        assertTrue(to.contains(new InternetAddress(developers)));
-        List cc =
-            Arrays.asList(message.getRecipients(Message.RecipientType.CC));
-        assertEquals(0, cc.size());
-        List bcc =
-            Arrays.asList(message.getRecipients(Message.RecipientType.BCC));
-        assertEquals(1, bcc.size());
-        assertTrue(bcc.contains(new InternetAddress(announce)));
-        List all = Arrays.asList(message.getAllRecipients());
-        assertEquals(3, all.size());
-        assertTrue(all.contains(new InternetAddress(announce)));
-        assertTrue(all.contains(new InternetAddress(users)));
-        assertTrue(all.contains(new InternetAddress(developers)));
+    protected void setUp() throws Exception {
+        defaultMap = CommandMap.getDefaultCommandMap();
+        MailcapCommandMap myMap = new MailcapCommandMap();
+        myMap.addMailcap("text/plain;;    x-java-content-handler=" + MimeMultipartTest.DummyTextHandler.class.getName());
+        CommandMap.setDefaultCommandMap(myMap);
+        session = Session.getDefaultInstance(new Properties());
     }
-    public void testSetters() throws MessagingException, IOException {
-        MimeMessage message = new MimeMessage(null, 1);
-        message.setContent("Hello world", "text/plain");
-        message.setContentID("Test message @ test.com");
-        //message.setContentLanguage(new String[] { "en" });
-        message.setContentMD5("md5hash");
-        message.setDescription("A test message");
-        message.setDisposition(Part.INLINE);
-        message.setFileName("file.txt");
-        message.setFrom(new InternetAddress(users));
-        message.setRecipient(
-            Message.RecipientType.TO,
-            new InternetAddress(developers));
-        message.setSubject("What is the first program you write?");
-        Date sent = new Date();
-        message.setSentDate(sent);
-        assertEquals("Hello world", message.getContent());
-        assertEquals("Test message @ test.com", message.getContentID());
-        assertEquals("md5hash", message.getContentMD5());
-        assertEquals("A test message", message.getDescription());
-        assertEquals("inline", message.getDisposition());
-        assertEquals("file.txt", message.getFileName());
-        //        assertEquals("en",message.getContentLanguage()[0]);
-        assertEquals(
-            "inline;filename=file.txt",
-            message.getHeader("Content-Disposition", null));
-        assertEquals(new InternetAddress(users), message.getFrom()[0]);
-        assertEquals(
-            new InternetAddress(developers),
-            message.getRecipients(Message.RecipientType.TO)[0]);
-            // Cannot use 'equals' testing becaues new Date() contains millisecond accuracy,

-            // whereas the one from the MessageContext has been encoded to a string and parsed
-        assertEquals(sent.toString(),message.getSentDate().toString());
+
+    protected void tearDown() throws Exception {
+        CommandMap.setDefaultCommandMap(defaultMap);
     }
-    */
 }

Added: geronimo/trunk/specs/javamail/src/test/javax/mail/internet/MimeMultipartTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/test/javax/mail/internet/MimeMultipartTest.java?view=auto&rev=154541
==============================================================================
--- geronimo/trunk/specs/javamail/src/test/javax/mail/internet/MimeMultipartTest.java (added)
+++ geronimo/trunk/specs/javamail/src/test/javax/mail/internet/MimeMultipartTest.java Sun
Feb 20 10:01:49 2005
@@ -0,0 +1,101 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+//
+// This source code implements specifications defined by the Java
+// Community Process. In order to remain compliant with the specification
+// DO NOT add / change / or delete method signatures!
+//
+package javax.mail.internet;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import javax.mail.MessagingException;
+import javax.activation.CommandMap;
+import javax.activation.DataHandler;
+import javax.activation.MailcapCommandMap;
+import javax.activation.DataContentHandler;
+import javax.activation.DataSource;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MimeMultipartTest extends TestCase {
+    private CommandMap defaultMap;
+
+    public void testWriteTo() throws MessagingException, IOException {
+        MimeMultipart mp = new MimeMultipart();
+        MimeBodyPart part1 = new MimeBodyPart();
+        part1.setContent("Hello World", "text/plain");
+        mp.addBodyPart(part1);
+        MimeBodyPart part2 = new MimeBodyPart();
+        part2.setContent("Hello Again", "text/plain");
+        mp.addBodyPart(part2);
+        mp.writeTo(System.out);
+    }
+
+    protected void setUp() throws Exception {
+        defaultMap = CommandMap.getDefaultCommandMap();
+        MailcapCommandMap myMap = new MailcapCommandMap();
+        myMap.addMailcap("text/plain;;    x-java-content-handler=" + DummyTextHandler.class.getName());
+        CommandMap.setDefaultCommandMap(myMap);
+    }
+
+    protected void tearDown() throws Exception {
+        CommandMap.setDefaultCommandMap(defaultMap);
+    }
+
+    public static class DummyTextHandler implements DataContentHandler {
+        public DataFlavor[] getTransferDataFlavors() {
+            return new DataFlavor[0];  //To change body of implemented methods use File |
Settings | File Templates.
+        }
+
+        public Object getTransferData(DataFlavor df, DataSource ds) throws UnsupportedFlavorException,
IOException {
+            return null;  //To change body of implemented methods use File | Settings | File
Templates.
+        }
+
+        public Object getContent(DataSource ds) throws IOException {
+            return null;  //To change body of implemented methods use File | Settings | File
Templates.
+        }
+
+        public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException
{
+            os.write(((String)obj).getBytes());
+        }
+    }
+
+    public static class DummyMultipartHandler implements DataContentHandler {
+        public DataFlavor[] getTransferDataFlavors() {
+            return new DataFlavor[0];  //To change body of implemented methods use File |
Settings | File Templates.
+        }
+
+        public Object getTransferData(DataFlavor df, DataSource ds) throws UnsupportedFlavorException,
IOException {
+            return null;  //To change body of implemented methods use File | Settings | File
Templates.
+        }
+
+        public Object getContent(DataSource ds) throws IOException {
+            return null;  //To change body of implemented methods use File | Settings | File
Templates.
+        }
+
+        public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException
{
+            os.write(((String)obj).getBytes());
+        }
+    }
+}



Mime
View raw message