001package com.hfg.util.mime;
002
003import java.io.IOException;
004import java.io.OutputStream;
005import java.util.List;
006
007
008//------------------------------------------------------------------------------
009/**
010 Generator for multipart MIME (Multipurpose Internet Mail Extensions).
011 <p>
012 See <a href='http://www.ietf.org/rfc/rfc2045.txt'>[RFC2045]</a>
013 </p>
014 @author J. Alex Taylor, hairyfatguy.com
015 */
016//------------------------------------------------------------------------------
017// com.hfg XML/HTML Coding Library
018//
019// This library is free software; you can redistribute it and/or
020// modify it under the terms of the GNU Lesser General Public
021// License as published by the Free Software Foundation; either
022// version 2.1 of the License, or (at your option) any later version.
023//
024// This library is distributed in the hope that it will be useful,
025// but WITHOUT ANY WARRANTY; without even the implied warranty of
026// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
027// Lesser General Public License for more details.
028//
029// You should have received a copy of the GNU Lesser General Public
030// License along with this library; if not, write to the Free Software
031// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
032//
033// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
034// jataylor@hairyfatguy.com
035//------------------------------------------------------------------------------
036
037public class MultipartMimeGenerator
038{
039   //##########################################################################
040   // PRIVATE FIELDS
041   //##########################################################################
042
043   private String  mBoundary = "974767299852498929531610575";
044
045
046   private static final String CRLF = "\r\n";
047
048
049   //##########################################################################
050   // PUBLIC METHODS
051   //##########################################################################
052
053   //--------------------------------------------------------------------------
054   public MultipartMimeGenerator setBoundary(String inValue)
055   {
056      mBoundary = inValue;
057      return this;
058   }
059
060   //--------------------------------------------------------------------------
061   public String getBoundary()
062   {
063      return mBoundary;
064   }
065
066   //--------------------------------------------------------------------------
067   public void generate(List<MimeEntity> inEntities, OutputStream inStream)
068         throws IOException
069   {
070      for (MimeEntity entity : inEntities)
071      {
072         inStream.write("--".getBytes());
073         inStream.write(getBoundary().getBytes());
074         inStream.write(CRLF.getBytes());
075         entity.write(inStream);
076      }
077      inStream.write("--".getBytes());
078      inStream.write(getBoundary().getBytes());
079      inStream.write("--".getBytes());
080      inStream.write(CRLF.getBytes());
081      inStream.write(CRLF.getBytes());
082   }
083
084}