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.runtime.model.persistence.fs; 013 014import java.io.ByteArrayInputStream; 015import java.io.File; 016import java.io.InputStream; 017import java.net.MalformedURLException; 018import java.net.URL; 019 020import org.nuxeo.runtime.model.persistence.AbstractContribution; 021 022/** 023 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 024 */ 025public class ContributionFile extends AbstractContribution { 026 027 protected final File file; 028 029 public ContributionFile(String name, File file) { 030 super(name); 031 this.file = file; 032 } 033 034 @Override 035 public URL asURL() { 036 try { 037 return file.toURI().toURL(); 038 } catch (MalformedURLException e) { 039 return null; 040 } 041 } 042 043 @Override 044 public String getContent() { 045 return FileSystemStorage.safeRead(file); 046 } 047 048 @Override 049 public InputStream getStream() { 050 return new ByteArrayInputStream(getContent().getBytes()); 051 } 052 053}