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

PKCS7ContentHandler

public class PKCS7ContentHandler extends Object implements DataContentHandler

Fields Summary
private final ActivationDataFlavor
_adf
private final DataFlavor[]
_dfs
Constructors Summary
PKCS7ContentHandler(ActivationDataFlavor adf, DataFlavor[] dfs)

        _adf = adf;
        _dfs = dfs;
    
Methods Summary
public java.lang.ObjectgetContent(javax.activation.DataSource ds)

        return ds.getInputStream();
    
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;
    
public voidwriteTo(java.lang.Object obj, java.lang.String mimeType, java.io.OutputStream os)

        if (obj instanceof MimeBodyPart) 
        {
            try 
            {
                ((MimeBodyPart)obj).writeTo(os);
            }
            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
        {
            // TODO it would be even nicer if we could attach the object to the exception
            //     as well since in deeply nested messages, it is not always clear which
            //     part caused the problem. Thus I guess we would have to subclass the
            //     IOException

            throw new IOException("unknown object in writeTo " + obj);
        }