01: package org.bouncycastle.mail.smime.handlers;
02:
03: import java.awt.datatransfer.DataFlavor;
04: import java.io.IOException;
05: import java.io.InputStream;
06: import java.io.OutputStream;
07:
08: import javax.activation.ActivationDataFlavor;
09: import javax.activation.DataContentHandler;
10: import javax.activation.DataSource;
11: import javax.mail.MessagingException;
12: import javax.mail.internet.MimeBodyPart;
13:
14: public class x_pkcs7_signature implements DataContentHandler {
15:
16: /*
17: *
18: * VARIABLES
19: *
20: */
21:
22: private static final ActivationDataFlavor ADF;
23: private static final DataFlavor[] ADFs;
24:
25: static {
26: ADF = new ActivationDataFlavor(MimeBodyPart.class,
27: "application/x-pkcs7-signature", "Signature");
28: ADFs = new DataFlavor[] { ADF };
29: }
30:
31: public Object getContent(DataSource _ds) throws IOException {
32: return _ds.getInputStream();
33: }
34:
35: public Object getTransferData(DataFlavor _df, DataSource _ds)
36: throws IOException {
37: if (ADF.equals(_df)) {
38: return getContent(_ds);
39: } else {
40: return null;
41: }
42: }
43:
44: public DataFlavor[] getTransferDataFlavors() {
45: return ADFs;
46: }
47:
48: public void writeTo(Object _obj, String _mimeType, OutputStream _os)
49: throws IOException {
50: if (_obj instanceof MimeBodyPart) {
51: try {
52: ((MimeBodyPart) _obj).writeTo(_os);
53: } catch (MessagingException ex) {
54: throw new IOException(ex.getMessage());
55: }
56: } else if (_obj instanceof byte[]) {
57: _os.write((byte[]) _obj);
58: } else if (_obj instanceof InputStream) {
59: int b;
60: InputStream in = (InputStream) _obj;
61:
62: while ((b = in.read()) >= 0) {
63: _os.write(b);
64: }
65: } else {
66: throw new IOException("unknown object in writeTo " + _obj);
67: }
68: }
69: }
|