1 package com.ozacc.mail.impl;
\r
4 * @(#)ByteArrayDataSource.java 1.4 01/05/23
\r
6 * Copyright 1998-2000 Sun Microsystems, Inc. All Rights Reserved.
\r
8 * Redistribution and use in source and binary forms, with or without
\r
9 * modification, are permitted provided that the following conditions
\r
12 * - Redistributions of source code must retain the above copyright
\r
13 * notice, this list of conditions and the following disclaimer.
\r
15 * - Redistribution in binary form must reproduce the above copyright
\r
16 * notice, this list of conditions and the following disclaimer in the
\r
17 * documentation and/or other materials provided with the distribution.
\r
19 * Neither the name of Sun Microsystems, Inc. or the names of contributors
\r
20 * may be used to endorse or promote products derived from this software
\r
21 * without specific prior written permission.
\r
23 * This software is provided "AS IS," without a warranty of any kind. ALL
\r
24 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
\r
25 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
\r
26 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND
\r
27 * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES OR LIABILITIES
\r
28 * SUFFERED BY LICENSEE AS A RESULT OF OR RELATING TO USE, MODIFICATION
\r
29 * OR DISTRIBUTION OF THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
\r
30 * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
\r
31 * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
\r
32 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
\r
33 * ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS
\r
34 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
\r
36 * You acknowledge that Software is not designed, licensed or intended
\r
37 * for use in the design, construction, operation or maintenance of any
\r
41 import java.io.ByteArrayInputStream;
\r
42 import java.io.ByteArrayOutputStream;
\r
43 import java.io.IOException;
\r
44 import java.io.InputStream;
\r
45 import java.io.OutputStream;
\r
46 import java.io.UnsupportedEncodingException;
\r
48 import javax.activation.DataSource;
\r
51 * InputStream、byte array、StringからDataSourceインスタンスを生成するクラス。<br>
\r
54 * <strong>注:</strong> このクラスはpublicですが、ozacc-mail library外からは使用しないでください。
\r
59 * @author Bill Shannon
\r
60 * @author Max Spivak
\r
62 public class ByteArrayDataSource implements DataSource {
\r
64 private byte[] data; // data
\r
66 private String type; // content-type
\r
68 /* Create a DataSource from an input stream */
\r
69 public ByteArrayDataSource(InputStream is, String type) {
\r
72 ByteArrayOutputStream os = new ByteArrayOutputStream();
\r
75 while ((ch = is.read()) != -1)
\r
76 // XXX - must be made more efficient by
\r
77 // doing buffered reads, rather than one byte reads
\r
79 data = os.toByteArray();
\r
81 } catch (IOException ioex) {}
\r
84 /* Create a DataSource from a byte array */
\r
85 public ByteArrayDataSource(byte[] data, String type) {
\r
90 /* Create a DataSource from a String */
\r
91 public ByteArrayDataSource(String data, String type) {
\r
93 // Assumption that the string contains only ASCII
\r
94 // characters! Otherwise just pass a charset into this
\r
95 // constructor and use it in getBytes()
\r
96 this.data = data.getBytes("iso-8859-1");
\r
97 } catch (UnsupportedEncodingException uex) {}
\r
102 * Return an InputStream for the data.
\r
103 * Note - a new stream must be returned each time.
\r
105 public InputStream getInputStream() throws IOException {
\r
107 throw new IOException("no data");
\r
108 return new ByteArrayInputStream(data);
\r
111 public OutputStream getOutputStream() throws IOException {
\r
112 throw new IOException("cannot do this");
\r
115 public String getContentType() {
\r
119 public String getName() {
\r