ResourceLocator.java |
1 package resource; 2 3 import java.net.URL; 4 5 /** 6 * Helper class to load resources placed in the package directory of this class. 7 * 8 * @author JChem Base team, ChemAxon Ltd. 9 */ 10public final class ResourceLocator { 11 12 private static final String DEFAULT_INPUT_FILE = "nci1000.smiles"; 13 14 /** 15 * Gets the path of the given resource. 16 * 17 * @param resourceFileName the name of the requested resource file (more precisely, a file 18 * path that is relative to the package directory of this class). 19 * @return the full path of the requested resource file 20 * @throws IllegalArgumentException if the resource is not found 21 */ 22 public static String getPath(String resourceFileName) throws IllegalArgumentException { 23 URL resource = ResourceLocator.class.getResource(resourceFileName); 24 if (resource == null) { 25 throw new IllegalArgumentException("Resource not found: " + resourceFileName); 26 } 27 return resource.getPath(); 28 } 29 30 /** 31 * Gets the path of the default molecule input file (nci1000.smiles). 32 * 33 * @return the full path of the default input file 34 */ 35 public static String getDefaultInputPath() { 36 return getPath(DEFAULT_INPUT_FILE); 37 } 38 39} 40