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;
013
014import java.io.IOException;
015import java.io.InputStream;
016import java.net.URL;
017
018/**
019 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
020 */
021public class URLStreamRef implements StreamRef {
022
023    protected final URL url;
024
025    protected final String name;
026
027    public URLStreamRef(URL url) {
028        this(url, url.toString());
029    }
030
031    public URLStreamRef(URL url, String name) {
032        this.url = url;
033        this.name = name;
034    }
035
036    @Override
037    public String getId() {
038        return url.toString();
039    }
040
041    @Override
042    public InputStream getStream() throws IOException {
043        return url.openStream();
044    }
045
046    @Override
047    public URL asURL() {
048        return url;
049    }
050
051}