1 36 package org.columba.ristretto.composer.mimepartrenderers; 37 38 import java.io.ByteArrayInputStream ; 39 import java.io.InputStream ; 40 import java.util.Vector ; 41 42 import org.columba.ristretto.composer.MimePartRenderer; 43 import org.columba.ristretto.composer.MimeTreeRenderer; 44 import org.columba.ristretto.io.SequenceInputStream; 45 import org.columba.ristretto.message.MimeHeader; 46 import org.columba.ristretto.message.MimePart; 47 import org.columba.ristretto.message.StreamableMimePart; 48 49 56 public class MultipartRenderer extends MimePartRenderer { 57 58 61 public String getRegisterString() { 62 return "multipart"; 63 } 64 65 68 public InputStream render(MimePart part) throws Exception { 69 Vector streams = new Vector (part.countChilds() * 2 + 3); 70 71 MimeHeader header = part.getHeader(); 72 73 String boundary = createUniqueBoundary().toString(); 75 header.putContentParameter("boundary", boundary ); 76 byte[] startBoundary = ( "\r\n--" + boundary + "\r\n" ).getBytes(); 77 byte[] endBoundary = ( "\r\n--" + boundary + "--\r\n" ).getBytes(); 78 79 streams.add( header.getHeader().getInputStream() ); 81 if( part instanceof StreamableMimePart) 82 streams.add( ((StreamableMimePart)part).getInputStream() ); 83 84 for( int i=0; i<part.countChilds(); i++ ) { 86 streams.add(new ByteArrayInputStream ( startBoundary )); 87 streams.add(MimeTreeRenderer.getInstance().renderMimePart(part.getChild(i))); 88 } 89 90 streams.add( new ByteArrayInputStream ( endBoundary ) ); 92 93 return new SequenceInputStream( streams ); 94 } 95 96 97 98 } 99 | Popular Tags |