001/* 002 * Copyright (c) 2006-2015 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 * Bogdan Stefanescu 011 * Florent Guillaume 012 */ 013package org.nuxeo.ecm.core.api.impl.blob; 014 015import java.io.IOException; 016import java.io.InputStream; 017import java.io.Serializable; 018import java.net.URL; 019 020/** 021 * Blob backed by a URL. Its length is -1. Note that the encoding is not detected even for an HTTP URL. 022 */ 023public class URLBlob extends AbstractBlob implements Serializable { 024 025 private static final long serialVersionUID = 1L; 026 027 protected final URL url; 028 029 public URLBlob(URL url) { 030 this(url, null, null); 031 } 032 033 public URLBlob(URL url, String mimeType) { 034 this(url, mimeType, null); 035 } 036 037 public URLBlob(URL url, String mimeType, String encoding) { 038 if (url == null) { 039 throw new NullPointerException("null url"); 040 } 041 this.url = url; 042 this.mimeType = mimeType; 043 this.encoding = encoding; 044 } 045 046 /** 047 * @deprecated since 7.2, use a separate {@link #setFilename} call 048 */ 049 @Deprecated 050 public URLBlob(URL url, String mimeType, String encoding, String filename) { 051 this(url, mimeType, encoding); 052 this.filename = filename; 053 } 054 055 @Override 056 public InputStream getStream() throws IOException { 057 return url.openStream(); 058 } 059 060}