001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.servicemix.jbi.util;
018
019 import java.io.IOException;
020 import java.io.InputStream;
021 import java.io.OutputStream;
022
023 import javax.activation.DataSource;
024
025 /**
026 * Stream DataSource for Mail and message attachments .
027 *
028 * @author <a href="mailto:gnodet@logicblaze.com"> Guillaume Nodet</a>
029 * @since 3.0
030 */
031 public class StreamDataSource implements DataSource {
032
033 private InputStream in;
034
035 private String contentType;
036
037 private String name;
038
039 public StreamDataSource(InputStream in) {
040 this(in, null, null);
041 }
042
043 public StreamDataSource(InputStream in, String contentType) {
044 this(in, contentType, null);
045 }
046
047 public StreamDataSource(InputStream in, String contentType, String name) {
048 this.in = in;
049 this.contentType = contentType;
050 this.name = name;
051 }
052
053 public InputStream getInputStream() throws IOException {
054 if (in == null) {
055 throw new IOException("no data");
056 }
057 return in;
058 }
059
060 public OutputStream getOutputStream() throws IOException {
061 throw new IOException("getOutputStream() not supported");
062 }
063
064 public String getContentType() {
065 return contentType;
066 }
067
068 public String getName() {
069 return name;
070 }
071
072 public void setName(String name) {
073 this.name = name;
074 }
075
076 public void setContentType(String contentType) {
077 this.contentType = contentType;
078 }
079
080 }