1 4 package com.tc.config.schema.setup.sources; 5 6 import com.tc.config.schema.setup.ConfigurationSetupException; 7 import com.tc.util.Assert; 8 9 import java.io.File ; 10 import java.io.InputStream ; 11 12 15 public class ResourceConfigurationSource implements ConfigurationSource { 16 17 private final String path; 18 private final Class relativeTo; 19 20 public ResourceConfigurationSource(String path, Class relativeTo) { 21 Assert.assertNotBlank(path); 22 Assert.assertNotNull(relativeTo); 23 24 this.path = path; 25 this.relativeTo = relativeTo; 26 } 27 28 public InputStream getInputStream(long maxTimeoutMillis) throws ConfigurationSetupException { 29 InputStream out = this.relativeTo.getResourceAsStream(this.path); 30 if (out == null) throw new ConfigurationSetupException("Resource '" + this.path + "', relative to class " 31 + this.relativeTo.getName() + ", does not exist"); 32 return out; 33 } 34 35 public File directoryLoadedFrom() { 36 return null; 37 } 38 39 public boolean isTrusted() { 40 return false; 41 } 42 43 public String toString() { 44 return "Java resource at '" + this.path + "', relative to class " + this.relativeTo.getName(); 45 } 46 47 } 48 | Popular Tags |