1 16 17 package org.springframework.core.io.support; 18 19 import java.io.IOException ; 20 import java.io.InputStreamReader ; 21 import java.io.Reader ; 22 23 import org.springframework.core.io.Resource; 24 import org.springframework.util.Assert; 25 26 36 public class EncodedResource { 37 38 private final Resource resource; 39 40 private final String encoding; 41 42 43 48 public EncodedResource(Resource resource) { 49 this(resource, null); 50 } 51 52 58 public EncodedResource(Resource resource, String encoding) { 59 Assert.notNull(resource, "Resource must not be null"); 60 this.resource = resource; 61 this.encoding = encoding; 62 } 63 64 65 68 public Resource getResource() { 69 return resource; 70 } 71 72 76 public String getEncoding() { 77 return encoding; 78 } 79 80 85 public Reader getReader() throws IOException { 86 if (this.encoding != null) { 87 return new InputStreamReader (this.resource.getInputStream(), this.encoding); 88 } 89 else { 90 return new InputStreamReader (this.resource.getInputStream()); 91 } 92 } 93 94 } 95 | Popular Tags |