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.soap.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 * @author <a href="mailto:gnodet@logicblaze.com"> Guillaume Nodet</a>
028 * @since 3.0
029 */
030 public class StreamDataSource implements DataSource {
031
032 private InputStream in;
033 private String contentType;
034 private String name;
035
036 public StreamDataSource(InputStream in) {
037 this(in, null, null);
038 }
039
040 public StreamDataSource(InputStream in, String contentType) {
041 this(in, contentType, null);
042 }
043
044 public StreamDataSource(InputStream in, String contentType, String name) {
045 this.in = in;
046 this.contentType = contentType;
047 this.name = name;
048 }
049
050 public InputStream getInputStream() throws IOException {
051 if (in == null) throw new IOException("no data");
052 return in;
053 }
054
055 public OutputStream getOutputStream() throws IOException {
056 throw new IOException("getOutputStream() not supported");
057 }
058
059 public String getContentType() {
060 return contentType;
061 }
062
063 public String getName() {
064 return name;
065 }
066
067 public void setName(String name) {
068 this.name = name;
069 }
070
071 public void setContentType(String contentType) {
072 this.contentType = contentType;
073 }
074
075 }