001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bstefanescu 018 */ 019package org.nuxeo.ecm.automation.jaxrs.io; 020 021import java.io.IOException; 022import java.io.InputStream; 023import java.io.OutputStream; 024 025import javax.activation.DataSource; 026 027/** 028 * @author <a href="mailto:[email protected]">Bogdan Stefanescu</a> 029 */ 030public class InputStreamDataSource implements DataSource { 031 032 protected final InputStream in; 033 034 protected final String ctype; 035 036 protected final String name; 037 038 public InputStreamDataSource(InputStream in, String ctype) { 039 this(in, ctype, "MultipartRequest"); 040 } 041 042 public InputStreamDataSource(InputStream in, String ctype, String name) { 043 this.in = in; 044 this.name = name; 045 this.ctype = ctype; 046 } 047 048 public OutputStream getOutputStream() throws IOException { 049 throw new UnsupportedOperationException("data source is not writeable"); 050 } 051 052 public String getName() { 053 return name; 054 } 055 056 public InputStream getInputStream() throws IOException { 057 return in; 058 } 059 060 public String getContentType() { 061 return ctype; 062 } 063}