001/* 002 * (C) Copyright 2014 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 * Thomas Roger 018 */ 019 020package org.nuxeo.ecm.core.api.impl.blob; 021 022import java.io.File; 023import java.io.IOException; 024import java.io.InputStream; 025import java.io.OutputStream; 026import java.io.Serializable; 027 028import org.nuxeo.ecm.core.api.Blob; 029import org.nuxeo.ecm.core.api.CloseableFile; 030 031/** 032 * Wraps an existing {@link Blob} to allow setting a different filename. 033 * 034 * @since 5.9.2 035 */ 036public class BlobWrapper implements Blob, Serializable { 037 038 private static final long serialVersionUID = 1L; 039 040 protected final Blob blob; 041 042 protected String filename; 043 044 public BlobWrapper(Blob blob) { 045 this.blob = blob; 046 filename = blob.getFilename(); 047 } 048 049 @Override 050 public String getFilename() { 051 return filename; 052 } 053 054 @Override 055 public void setFilename(String filename) { 056 this.filename = filename; 057 } 058 059 // the rest of the implementation just delegates to the blob 060 061 @Override 062 public String getMimeType() { 063 return blob.getMimeType(); 064 } 065 066 @Override 067 public String getEncoding() { 068 return blob.getEncoding(); 069 } 070 071 @Override 072 public String getDigestAlgorithm() { 073 return blob.getDigestAlgorithm(); 074 } 075 076 @Override 077 public String getDigest() { 078 return blob.getDigest(); 079 } 080 081 @Override 082 public void setMimeType(String mimeType) { 083 blob.setMimeType(mimeType); 084 } 085 086 @Override 087 public void setEncoding(String encoding) { 088 blob.setEncoding(encoding); 089 } 090 091 @Override 092 public void setDigest(String digest) { 093 blob.setDigest(digest); 094 } 095 096 @Override 097 public InputStream getStream() throws IOException { 098 return blob.getStream(); 099 } 100 101 @Override 102 public long getLength() { 103 return blob.getLength(); 104 } 105 106 @Override 107 public byte[] getByteArray() throws IOException { 108 return blob.getByteArray(); 109 } 110 111 @Override 112 public String getString() throws IOException { 113 return blob.getString(); 114 } 115 116 @Override 117 public void transferTo(OutputStream out) throws IOException { 118 blob.transferTo(out); 119 } 120 121 @Override 122 public void transferTo(File file) throws IOException { 123 blob.transferTo(file); 124 } 125 126 @Override 127 public File getFile() { 128 return blob.getFile(); 129 } 130 131 @Override 132 public CloseableFile getCloseableFile() throws IOException { 133 return blob.getCloseableFile(); 134 } 135 136 @Override 137 public CloseableFile getCloseableFile(String ext) throws IOException { 138 return blob.getCloseableFile(ext); 139 } 140 141}