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