FileDocCategorySizeDatePackage
multipart_signed.javaAPI DocBouncy Castle Crypto API 1.41 (Java 1.5)7197Wed Oct 01 10:55:30 BST 2008org.bouncycastle.mail.smime.handlers

multipart_signed

public class multipart_signed extends Object implements DataContentHandler

Fields Summary
private static final ActivationDataFlavor
ADF
private static final DataFlavor[]
DFS
Constructors Summary
Methods Summary
public java.lang.ObjectgetContent(javax.activation.DataSource ds)

    
        
          
    
        try
        {
            return new MimeMultipart(ds);
        }
        catch (MessagingException ex)
        {
            return null;
        }
    
public java.lang.ObjectgetTransferData(java.awt.datatransfer.DataFlavor df, javax.activation.DataSource ds)

    
        if (ADF.equals(df))
        {
            return getContent(ds);
        }
        else
        {
            return null;
        }
    
public java.awt.datatransfer.DataFlavor[]getTransferDataFlavors()

        return DFS;
    
private voidoutputBodyPart(java.io.OutputStream out, java.lang.Object bodyPart)

        if (bodyPart instanceof Multipart)
        {
            Multipart mp = (Multipart)bodyPart;
            ContentType contentType = new ContentType(mp.getContentType());
            String boundary = "--" + contentType.getParameter("boundary");

            LineOutputStream lOut = new LineOutputStream(out);

            for (int i = 0; i < mp.getCount(); i++)
            {
                lOut.writeln(boundary);
                outputBodyPart(out, mp.getBodyPart(i));
                lOut.writeln();       // CRLF terminator
            }

            lOut.writeln(boundary + "--");
            return;
        }

        MimeBodyPart    mimePart = (MimeBodyPart)bodyPart;

        if (mimePart.getContent() instanceof Multipart)
        {
            Multipart mp = (Multipart)mimePart.getContent();
            ContentType contentType = new ContentType(mp.getContentType());
            String boundary = "--" + contentType.getParameter("boundary");

            LineOutputStream lOut = new LineOutputStream(out);

            Enumeration headers = mimePart.getAllHeaderLines();
            while (headers.hasMoreElements())
            {
                lOut.writeln((String)headers.nextElement());
            }

            lOut.writeln();      // CRLF separator

            outputPreamble(lOut, mimePart, boundary);

            outputBodyPart(out, mp);
            return;
        }

        mimePart.writeTo(out);
    
static voidoutputPreamble(org.bouncycastle.mail.smime.handlers.multipart_signed$LineOutputStream lOut, javax.mail.internet.MimeBodyPart part, java.lang.String boundary)
internal preamble is generally included in signatures, while this is technically wrong, if we find internal preamble we include it by default.

        InputStream in;

        try
        {
            in = part.getRawInputStream();
        }
        catch (MessagingException e)
        {
            return;            // no underlying content, rely on default generation
        }

        String line;

        while ((line = readLine(in)) != null)
        {
            if (line.equals(boundary))
            {
                break;
            }

            lOut.writeln(line);
        }

        in.close();

        if (line == null)
        {
            throw new MessagingException("no boundary found");
        }
    
private static java.lang.StringreadLine(java.io.InputStream in)

        StringBuffer b = new StringBuffer();

        int ch;
        while ((ch = in.read()) >= 0 && ch != '\n")
        {
            if (ch != '\r")
            {
                b.append((char)ch);
            }
        }

        if (ch < 0)
        {
            return null;
        }

        return b.toString();
    
public voidwriteTo(java.lang.Object obj, java.lang.String _mimeType, java.io.OutputStream os)

        
        if (obj instanceof MimeMultipart)
        {
            try
            {
                outputBodyPart(os, obj);
            }
            catch (MessagingException ex)
            {
                throw new IOException(ex.getMessage());
            }
        }
        else if(obj instanceof byte[])
        {
            os.write((byte[])obj);
        }
        else if (obj instanceof InputStream)
        {
            int         b;
            InputStream in = (InputStream)obj;
            
            if (!(in instanceof BufferedInputStream))
            {
                in = new BufferedInputStream(in);
            }

            while ((b = in.read()) >= 0)
            {
                os.write(b);
            }
        }
        else if (obj instanceof SMIMEStreamingProcessor)
        {
            SMIMEStreamingProcessor processor = (SMIMEStreamingProcessor)obj;

            processor.write(os);
        }
        else
        {
            throw new IOException("unknown object in writeTo " + obj);
        }