001/*
002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     bstefanescu
011 */
012package org.nuxeo.ecm.automation.jaxrs.io;
013
014import java.io.IOException;
015import java.io.InputStream;
016import java.io.OutputStream;
017
018import javax.activation.DataSource;
019
020/**
021 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
022 */
023public class InputStreamDataSource implements DataSource {
024
025    protected final InputStream in;
026
027    protected final String ctype;
028
029    protected final String name;
030
031    public InputStreamDataSource(InputStream in, String ctype) {
032        this(in, ctype, "MultipartRequest");
033    }
034
035    public InputStreamDataSource(InputStream in, String ctype, String name) {
036        this.in = in;
037        this.name = name;
038        this.ctype = ctype;
039    }
040
041    public OutputStream getOutputStream() throws IOException {
042        throw new UnsupportedOperationException("data source is not writeable");
043    }
044
045    public String getName() {
046        return name;
047    }
048
049    public InputStream getInputStream() throws IOException {
050        return in;
051    }
052
053    public String getContentType() {
054        return ctype;
055    }
056}