Hi Daniele,

Thanx for checking in the Email class. This is the patch for the
ByteArrayDataSource that I sent with an explanation of the changes.

Could you (or any other commiters) check it in please.

/Colin


> Here is a patch for the ByteArraydatasource with an explanation why I
> changed data[] to a ByteArrayOutputStream
>
> <snip>
> I was trying to accomplish two things here:
>
> 1.
> In the original file data[] was used for holding the data.There was a
> getOuputStream method returning a dummy outputstream (because it probably
> couldn't get linked up to the data[]) whereas it should have returned a
> stream to which you can write (to). Furthermore after parsing the
> InputStream the Ouptutstream used  was being converted to a byte[]. By
> replacing data[] with an outputstream these issues were solved/simplified.
>
> 2.
> In order to reuse code (I like writing things only once :-) ) I made a
> private method which can be used whether you access the class via a byte[]
> OR an InputStream.
> </snip>
>
> /Colin





> "Colin Chalmers" <[EMAIL PROTECTED]> writes:
>
> > A couple of small changes
> >
> > 1. Corrected the " Disposition-Notification-To: [EMAIL PROTECTED]" example
> > identified yesterday.
> > 2. There was a global session that was not being used.
> > 3. Changed the setting of debug info for the correct session and not the
> > global which was therafter redundant.
>
> Hi Colin.  Patch checked in, thanks.
>
> > Could someone check this in for me please. Also was there any reason why
the
> > patch for ByteArrayDataSource that I sent yesterday could not be checked
in?
>
> I misplaced this one, someone else will have to get it.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
Index: 
./jakarta-turbine/src/adapter/org/apache/turbine/util/mail/ByteArrayDataSource.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-turbine/src/adapter/org/apache/turbine/util/mail/ByteArrayDataSource.java,v
retrieving revision 1.2
diff -r1.2 ByteArrayDataSource.java
74a75
>  * @author <a href="mailto:[EMAIL PROTECTED]";>Colin Chalmers</a> 
77c78
<  * @version $Id: ByteArrayDataSource.java,v 1.2 2001/07/25 01:05:29 jvanzyl Exp $
---
>  * @version $Id: ByteArrayDataSource.java,v 1.2 2001/07/23 00:39:39 jvanzyl Exp $
82,84c83,85
<     /** Data. */
<     private byte[] data;
< 
---
>     /** Stream containg the Data */
>       private ByteArrayOutputStream baos = null;
>       
86c87
<     private String type;
---
>     private String type = "application/octet-stream";
88c89,95
<     private ByteArrayOutputStream baos;
---
>     /**
>      * Default constructor
>      *
>      */
>     public ByteArrayDataSource()
>     {
>     }
94a102
>      * @exception IOException.         
96,97c104,105
<     public ByteArrayDataSource(byte[] data,
<                                String type)
---
>     public ByteArrayDataSource(byte[] data, String type)
>               throws IOException
99,100c107,131
<         this.data = data;
<         this.type = type;
---
>               ByteArrayInputStream Bis = null;
>               
>               try
>               {
>                       Bis = new ByteArrayInputStream(data);
>                       this.ByteArrayDataSource(Bis, type);                    
>               }
>         catch (IOException ioex)
>         {
>           throw ioex;
>         }
>               finally
>               {
>                       try
>                       {
>                               if (Bis != null)
>                               {
>                                       Bis.close();
>                               }
>                       }
>                   catch (IOException ignored)
>                   {
>             // Ignore
>               }
>               }
107a139,152
>      * @exception IOException.         
>      */
>     public ByteArrayDataSource(InputStream aIs, String type)
>               throws IOException
>     {
>               this.ByteArrayDataSource(aIs, type);
>     }
>       
>    /**
>      * Create a datasource from an input stream.
>      *
>      * @param is An InputStream.
>      * @param type A String.
>      * @exception IOException.         
109,110c154,155
<     public ByteArrayDataSource(InputStream is,
<                                String type)
---
>     private void ByteArrayDataSource(InputStream aIs, String type)
>               throws IOException
112a158,161
>               
>         BufferedInputStream Bis = null;
>         BufferedOutputStream osWriter = null;
>               
115,125c164,178
<             int ch;
< 
<             ByteArrayOutputStream os = new ByteArrayOutputStream();
<             BufferedInputStream isReader = new BufferedInputStream( is );
<             BufferedOutputStream osWriter = new BufferedOutputStream( os );
< 
<             while ((ch = isReader.read()) != -1)
<             {
<                 osWriter.write(ch);
<             }
<             data = os.toByteArray();
---
>                       int length = 0;
>                       byte[] buffer = new byte[512];
>                       
>                       Bis = new BufferedInputStream( aIs );
>               baos = new ByteArrayOutputStream();                             
>             osWriter = new BufferedOutputStream( baos );
> 
>                       //Write the InputData to OutputStream                          
> 
>                       while ((length = Bis.read(buffer)) != -1)               
>                       {
>                               osWriter.write(buffer, 0 , length);
>                       }                       
>                       osWriter.flush();
>                       osWriter.close();
>                       
129c182
<             // Do something!
---
>           throw ioex;
130a184,205
>               finally
>               {
>                       try
>                       {
>                               if (Bis != null)
>                               {
>                                       Bis.close();
>                               }
>                               if (baos != null)
>                               {
>                                       baos.close();
>                               }                               
>                               if (osWriter != null)
>                               {
>                                       osWriter.close();
>                               }                               
>                       }
>                   catch (IOException ignored)
>                   {
>             // Ignore
>               }
>               }
132c207
< 
---
>               
137a213
>      * @exception IOException.         
139,140c215,216
<     public ByteArrayDataSource(String data,
<                                String type)
---
>     public ByteArrayDataSource(String data, String type)
>               throws IOException
142a219
>               
144a222,223
>               baos = new ByteArrayOutputStream();     
>                                       
148c227,229
<             this.data = data.getBytes("iso-8859-1");
---
>             baos.write(data.getBytes("iso-8859-1"));
>                       baos.flush();
>                       baos.close();
153a235,252
>               catch (IOException ignored)
>               {
>             // Ignore
>               }       
>               finally
>               {
>                       try
>                       {
>                               if (baos != null)
>                               {
>                                       baos.close();
>                               }                               
>                       }
>                   catch (IOException ignored)
>                   {
>             // Ignore
>               }
>               }                       
170c269
<         }            
---
>         }  
182c281
<         if (data == null)
---
>         if (baos == null)
186c285
<         return new ByteArrayInputStream(data);
---
>         return new ByteArrayInputStream(baos.toByteArray());
197a297
>       
199,207c299,309
<     /**
<      * Get the output stream.
<      *
<      * @return An OutputStream.
<      * @exception IOException.
<      */
<     public OutputStream getOutputStream()
<         throws IOException
<     {
---
> 
> 
>       /**
>        * Get the OutputStream to write to
>        *
>        * @return  An OutputStream
>        * @exception   IOException  
>        */
>       public OutputStream getOutputStream()
>         throws IOException    
>       {
210c312
<     }
---
>       }

The command completed successfully.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to