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.client.jaxrs.util; 013 014import java.io.IOException; 015import java.io.InputStream; 016import java.io.OutputStream; 017 018import javax.activation.DataSource; 019 020import org.nuxeo.ecm.automation.client.model.Blob; 021 022/** 023 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 024 */ 025public class BlobDataSource implements DataSource { 026 027 protected final Blob blob; 028 029 public BlobDataSource(Blob blob) { 030 this.blob = blob; 031 } 032 033 public String getContentType() { 034 return blob.getMimeType(); 035 } 036 037 public InputStream getInputStream() throws IOException { 038 return blob.getStream(); 039 } 040 041 public String getName() { 042 return blob.getFileName(); 043 } 044 045 public OutputStream getOutputStream() throws IOException { 046 throw new UnsupportedOperationException("blob data source is read only"); 047 } 048 049}