You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by se...@apache.org on 2001/06/28 05:41:57 UTC

cvs commit: jakarta-james/proposals/noparse-mimemessage/java/org/apache/james/core MimeMessageWrapper.java

serge       01/06/27 20:41:56

  Modified:    proposals/noparse-mimemessage/java/org/apache/james/core
                        MimeMessageWrapper.java
  Log:
  Implemented the writeTo methods so they no longer parse and instantiate the MimeMessage.
  
  Revision  Changes    Path
  1.2       +44 -12    jakarta-james/proposals/noparse-mimemessage/java/org/apache/james/core/MimeMessageWrapper.java
  
  Index: MimeMessageWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/proposals/noparse-mimemessage/java/org/apache/james/core/MimeMessageWrapper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MimeMessageWrapper.java	2001/06/27 04:34:22	1.1
  +++ MimeMessageWrapper.java	2001/06/28 03:41:54	1.2
  @@ -21,11 +21,6 @@
        */
       boolean modified = false;
   
  -/*
  -    public MimeMessageWrapper(InputStream in) {
  -        this(new MimeMessageInputStreamSource(in));
  -    }
  -*/
       public MimeMessageWrapper(MimeMessageSource source) {
           super(javax.mail.Session.getDefaultInstance(System.getProperties(), null));
           this.source = source;
  @@ -44,6 +39,8 @@
               //Another thread has already loaded this message
               return;
           }
  +        System.err.println("parsing " + this);
  +        new Throwable().printStackTrace();
           try {
               InputStream in = source.getInputStream();
               message = new MimeMessage(session, in);
  @@ -62,20 +59,55 @@
       }
   
       /**
  -     * Methods that should be rewritten for optimization purposes
  +     * Rewritten for optimization purposes
        */
       public void writeTo(OutputStream os) throws IOException, MessagingException {
  -        if (message == null) {
  -            loadMessage();
  +        if (message == null || !modified) {
  +            //We do not want to instantiate the message... just read from source
  +            //  and write to this outputstream
  +            byte[] block = new byte[1024];
  +            int read = 0;
  +            InputStream in = source.getInputStream();
  +            while ((read = in.read(block)) > 0) {
  +                os.write(block, 0, read);
  +            }
  +            in.close();
  +        } else {
  +            message.writeTo(os);
           }
  -        message.writeTo(os);
       }
   
  +    /**
  +     * Could be rewritten for optimization purposes at some point
  +     */
       public void writeTo(OutputStream os, String[] ignoreList) throws IOException, MessagingException {
  -        if (message == null) {
  -            loadMessage();
  +        if (message == null || !modified) {
  +            //We do not want to instantiate the message... just read from source
  +            //  and write to this outputstream
  +
  +            //First handle the headers
  +            InputStream in = source.getInputStream();
  +            InternetHeaders headers = new InternetHeaders(in);
  +            PrintStream pos = new PrintStream(os);
  +            for (Enumeration e = headers.getNonMatchingHeaderLines(ignoreList); e.hasMoreElements(); ) {
  +                String header = (String)e.nextElement();
  +                pos.print(header);
  +                pos.print("\r\n");
  +                //System.err.println(header);
  +            }
  +            pos.print("\r\n");
  +            //System.err.println();
  +            pos.flush();
  +            byte[] block = new byte[1024];
  +            int read = 0;
  +            while ((read = in.read(block)) > 0) {
  +                os.write(block, 0, read);
  +                //System.err.write(block, 0, read);
  +            }
  +            in.close();
  +        } else {
  +            message.writeTo(os, ignoreList);
           }
  -        message.writeTo(os, ignoreList);
       }
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org