1 package org.ozoneDB.tools.OPP.srcgen.streamfactory; 9 10 import org.ozoneDB.tools.OPP.OPPHelper; 11 12 import java.io.InputStream ; 13 import java.io.IOException ; 14 15 19 public class ResourceInputStreamFactory implements InputStreamFactory { 20 private String root; 21 private String extension; 22 23 24 public ResourceInputStreamFactory(String extension) { 25 this("/", extension); 26 } 27 28 public ResourceInputStreamFactory(String root, String extension) { 29 this.root = root; 30 this.extension = extension; 31 if (!root.endsWith("/")) 32 root += "/"; 33 } 34 35 public InputStream newInstance(String className) throws IOException { 36 String name = root + OPPHelper.classFileBasename(className, '/') + "." + extension; 37 InputStream is = getClass().getResourceAsStream(name); 38 39 if (is == null) { 40 throw new IOException ("Resource \"" + name + "\" was not found!"); 41 } 42 return is; 43 } 44 } 45 | Popular Tags |