1 10 11 package org.mule.extras.spring.config; 12 13 import java.io.ByteArrayInputStream ; 14 import java.io.IOException ; 15 import java.io.InputStream ; 16 import java.io.UnsupportedEncodingException ; 17 18 import org.springframework.core.io.AbstractResource; 19 20 30 public class CachedResource extends AbstractResource 31 { 32 33 private static final String DEFAULT_DESCRIPTION = "cached in-memory resource"; 34 35 private final byte[] buffer; 36 private final String description; 37 38 public CachedResource(byte[] source) 39 { 40 this(source, null); 41 } 42 43 public CachedResource(String source, String encoding) throws UnsupportedEncodingException 44 { 45 this(source.trim().getBytes(encoding), DEFAULT_DESCRIPTION); 46 } 47 48 public CachedResource(byte[] source, String description) 49 { 50 this.buffer = source; 51 this.description = description; 52 } 53 54 public String getDescription() 55 { 56 return (description == null) ? "" : description; 57 } 58 59 public InputStream getInputStream() throws IOException 60 { 61 return new ByteArrayInputStream (buffer); 65 } 66 } 67 | Popular Tags |