001/* 002 * (C) Copyright 2006-2015 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Bogdan Stefanescu 018 * Florent Guillaume 019 */ 020package org.nuxeo.ecm.core.api.impl.blob; 021 022import java.io.IOException; 023import java.io.InputStream; 024import java.io.Serializable; 025import java.net.URL; 026 027/** 028 * Blob backed by a URL. Its length is -1. Note that the encoding is not detected even for an HTTP URL. 029 */ 030public class URLBlob extends AbstractBlob implements Serializable { 031 032 private static final long serialVersionUID = 1L; 033 034 protected final URL url; 035 036 public URLBlob(URL url) { 037 this(url, null, null); 038 } 039 040 public URLBlob(URL url, String mimeType) { 041 this(url, mimeType, null); 042 } 043 044 public URLBlob(URL url, String mimeType, String encoding) { 045 if (url == null) { 046 throw new NullPointerException("null url"); 047 } 048 this.url = url; 049 this.mimeType = mimeType; 050 this.encoding = encoding; 051 } 052 053 /** 054 * @deprecated since 7.2, use a separate {@link #setFilename} call 055 */ 056 @Deprecated 057 public URLBlob(URL url, String mimeType, String encoding, String filename) { 058 this(url, mimeType, encoding); 059 this.filename = filename; 060 } 061 062 @Override 063 public InputStream getStream() throws IOException { 064 return url.openStream(); 065 } 066 067}