001/* 002 * Copyright 2002-2018 the original author or authors. 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 * https://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 017package org.springframework.web.reactive.resource; 018 019import java.io.IOException; 020 021import org.springframework.core.io.ByteArrayResource; 022import org.springframework.core.io.Resource; 023import org.springframework.lang.Nullable; 024 025/** 026 * An extension of {@link ByteArrayResource} that a {@link ResourceTransformer} 027 * can use to represent an original resource preserving all other information 028 * except the content. 029 * 030 * @author Rossen Stoyanchev 031 * @since 5.0 032 */ 033public class TransformedResource extends ByteArrayResource { 034 035 @Nullable 036 private final String filename; 037 038 private final long lastModified; 039 040 041 public TransformedResource(Resource original, byte[] transformedContent) { 042 super(transformedContent); 043 this.filename = original.getFilename(); 044 try { 045 this.lastModified = original.lastModified(); 046 } 047 catch (IOException ex) { 048 // should never happen 049 throw new IllegalArgumentException(ex); 050 } 051 } 052 053 054 @Override 055 @Nullable 056 public String getFilename() { 057 return this.filename; 058 } 059 060 @Override 061 public long lastModified() { 062 return this.lastModified; 063 } 064 065}