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 * Stephane Lacoin 011 */ 012package org.nuxeo.runtime.model.persistence.fs; 013 014import java.io.IOException; 015import java.io.InputStream; 016import java.net.URL; 017 018import org.nuxeo.common.utils.FileUtils; 019import org.nuxeo.runtime.model.persistence.AbstractContribution; 020 021public class ContributionLocation extends AbstractContribution { 022 023 protected final URL location; 024 025 public ContributionLocation(String name, URL location) { 026 super(name); 027 this.location = location; 028 } 029 030 @Override 031 public InputStream getStream() { 032 try { 033 return location.openStream(); 034 } catch (IOException e) { 035 throw new RuntimeException("Cannot get '".concat(name).concat("' content"), e); 036 } 037 } 038 039 @Override 040 public String getContent() { 041 try { 042 return FileUtils.read(location.openStream()); 043 } catch (IOException e) { 044 throw new RuntimeException("Cannot get '".concat(name).concat("' content"), e); 045 } 046 } 047 048 @Override 049 public URL asURL() { 050 return location; 051 } 052 053}