01: /*
02: * Copyright (C) 2001, 2002 Robert MacGrogan
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: *
19: * $Archive: SourceJammer$
20: * $FileName: SendBytesDataSource.java$
21: * $FileID: 4311$
22: *
23: * Last change:
24: * $AuthorName: Rob MacGrogan$
25: * $Date: 4/23/03 5:24 PM$
26: * $Comment: Replaced GPL header with LGPL header.$
27: */
28:
29: package org.sourcejammer.util;
30:
31: import java.io.ByteArrayInputStream;
32: import java.io.IOException;
33: import java.io.InputStream;
34: import java.io.OutputStream;
35:
36: import javax.activation.DataSource;
37:
38: /**
39: * Title: $FileName: SendBytesDataSource.java$
40: * @author $AuthorName: Rob MacGrogan$
41: * @version $VerNum: 2$
42: * $KeyWordsOff: $<br><br>
43: *
44: *
45: * DataSource for SendBytes object. Should turn into a SOAP attachment.
46: */
47: public class SendBytesDataSource implements DataSource {
48:
49: private static final String CONTENT_TYPE = "application/octet-stream";
50:
51: private byte[] by = null;
52:
53: public SendBytesDataSource() {
54: }
55:
56: public void setBytes(byte[] by) {
57: this .by = by;
58: }
59:
60: public byte[] getBytes() {
61: return by;
62: }
63:
64: /**
65: * @see javax.activation.DataSource#getContentType()
66: */
67: public String getContentType() {
68: return CONTENT_TYPE;
69: }
70:
71: /**
72: * @see javax.activation.DataSource#getInputStream()
73: */
74: public InputStream getInputStream() throws IOException {
75: InputStream stmIn = new ByteArrayInputStream(this .by);
76: return stmIn;
77: }
78:
79: /**
80: * @see javax.activation.DataSource#getName()
81: */
82: public String getName() {
83: return "BYTES";
84: }
85:
86: /**
87: * @see javax.activation.DataSource#getOutputStream()
88: */
89: public OutputStream getOutputStream() throws IOException {
90: return new SendBytesOutputStream(this);
91: }
92:
93: }
|