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.core.mail; 013 014import java.io.IOException; 015import java.io.InputStream; 016import java.io.OutputStream; 017 018import javax.activation.DataSource; 019 020import org.nuxeo.ecm.core.api.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 @Override 034 public String getContentType() { 035 return blob.getMimeType(); 036 } 037 038 @Override 039 public InputStream getInputStream() throws IOException { 040 return blob.getStream(); 041 } 042 043 @Override 044 public String getName() { 045 return blob.getFilename(); 046 } 047 048 @Override 049 public OutputStream getOutputStream() throws IOException { 050 throw new UnsupportedOperationException("blob data source is read only"); 051 } 052 053}