List of usage examples for java.lang ClassLoader getSystemResource
public static URL getSystemResource(String name)
From source file:org.n52.oss.IT.OpenSearchIT.java
private static void insertSensor(String path) throws XmlException, IOException, OwsExceptionReport, HttpException { File sensor = new File(ClassLoader.getSystemResource(path).getFile()); SensorMLDocument sensorMLDoc = SensorMLDocument.Factory.parse(sensor); InsertSensorInfoRequestDocument req = InsertSensorInfoRequestDocument.Factory.newInstance(); req.addNewInsertSensorInfoRequest().addNewInfoToBeInserted() .setSensorDescription(sensorMLDoc.getSensorML().getMemberArray(0).getProcess()); XmlObject res = client.xSendPostRequest(req); InsertSensorInfoResponseDocument resp = InsertSensorInfoResponseDocument.Factory.parse(res.getDomNode()); log.debug("Inserted sensor: {}", resp.xmlText()); // assertThat("inserted sensor successfully", // resp.getInsertSensorInfoResponse().getNumberOfInsertedSensors(), // is(not(0))); }
From source file:com.sonatype.security.ldap.AbstractMockLdapConnectorTest.java
public void setUp() throws Exception { super.setUp(); String filename = "ldap.xml"; String resourcePath = this.getClass().getName().replace('.', '/'); resourcePath += "-" + filename; if (ClassLoader.getSystemResource(resourcePath) == null) { resourcePath = "defaults/" + filename; }//from w w w. j av a2s . com getConfHomeDir().mkdirs(); Map<String, String> interpolationMap = new HashMap<String, String>(); interpolationMap.put("default-ldap-port", "12345"); try (InterpolationFilterReader reader = new InterpolationFilterReader( new InputStreamReader(ClassLoader.getSystemResourceAsStream(resourcePath)), interpolationMap); OutputStream out = new FileOutputStream(new File(getConfHomeDir(), "ldap.xml"));) { IOUtils.copy(reader, out); } this.ldapManager = (EnterpriseLdapManager) this.lookup(LdapManager.class); this.resetLdapConnectors(); }
From source file:com.dougchimento.at.AtManagerSimpleTest.java
@BeforeClass public void setUp() throws Exception { FileSystemManager manager = VFS.getManager(); atManager = At.getManager(new AtTestConfig("atTest.properties")); FileObject fakeAtResource = manager .resolveFile(new File(ClassLoader.getSystemResource("fakeAt.sh").getFile()).toURI().toString()); FileObject atListOutResource = manager.resolveFile( new File(ClassLoader.getSystemResource("atListOutput.txt").getFile()).toURI().toString()); FileObject atListRemovedOutResource = manager.resolveFile( new File(ClassLoader.getSystemResource("atListRemovedOutput.txt").getFile()).toURI().toString()); FileObject atListAddedOutResource = manager.resolveFile( new File(ClassLoader.getSystemResource("atListAddedOutput.txt").getFile()).toURI().toString()); fakeAt = manager.resolveFile("file://tmp/.at/fakeAt.sh"); atListOut = manager.resolveFile("file://tmp/.at/atListOutput.txt"); atListRemovedOut = manager.resolveFile("file://tmp/.at/atListRemovedOutput.txt"); atListAddedOut = manager.resolveFile("file://tmp/.at/atListAddedOutput.txt"); //Copy from jar resources to /tmp so we can fake at commands //TODO Clean up //TODO Permission on this file may not allow deleting tmpDir = new File("/tmp/.at"); if (tmpDir.exists()) { tmpDir.delete();/*from ww w . j av a 2 s .com*/ } tmpDir = new File("/tmp/.at/"); tmpDir.mkdir(); atListOut.copyFrom(atListOutResource, new AllFileSelector()); atListRemovedOut.copyFrom(atListRemovedOutResource, new AllFileSelector()); atListAddedOut.copyFrom(atListAddedOutResource, new AllFileSelector()); fakeAt.copyFrom(fakeAtResource, new AllFileSelector()); atConfig = new AtTestConfig("atTest.properties"); atManager = At.getManager(atConfig); }
From source file:com.depas.utils.FileUtils.java
private static String getConfigDirectoryPath(Class<?> c, String rootDirectory) { // get url to iwc/idc directory on classpath try {//from w ww. ja v a 2s . com URL url = ClassLoader.getSystemResource(rootDirectory); if (url == null) { // try this classpath, for running in eclipse url = c.getClassLoader().getResource(rootDirectory); } if (url != null) { String path = url.getPath(); if (!path.endsWith("\\") && !path.endsWith("/")) { path += "/"; } return URLDecoder.decode(path, "UTF-8"); } else { return null; } } catch (Exception ex) { logger.warn("Error obtaining file path to '" + rootDirectory + "' config directory: " + ex); return null; } }
From source file:edu.snu.dolphin.bsp.examples.ml.algorithms.graph.PageRankTest.java
/** * Run PageRank test.//w ww .j a va 2 s . c om */ @Test public void testPageRank() throws Exception { final String[] args = { "-convThr", "0.01", "-maxIter", "10", "-dampingFactor", "0.85", "-local", "true", "-split", "1", "-input", ClassLoader.getSystemResource("data").getPath() + "/pagerank", "-output", OUTPUT_PATH, "-maxNumEvalLocal", "2" }; DolphinLauncher.run(Configurations.merge( DolphinConfiguration.getConfiguration(args, PageRankParameters.getCommandLine()), Tang.Factory.getTang().newConfigurationBuilder().bindNamedParameter(JobIdentifier.class, "PageRank") .bindImplementation(UserJobInfo.class, PageRankJobInfo.class) .bindImplementation(UserParameters.class, PageRankParameters.class).build())); final File expected = new File(ClassLoader.getSystemResource("result").getPath() + "/pagerank"); final File actual = new File(OUTPUT_PATH + "/rank/CtrlTask-0"); Assert.assertTrue(FileUtils.contentEquals(expected, actual)); }
From source file:org.n52.sir.IT.solr.AutoCompleteServletIT.java
public void insertSensor() throws OwsExceptionReport, XmlException, IOException { File sensor_status = new File(ClassLoader.getSystemResource("Requests/testsensor.xml").getFile()); SensorMLDocument doc = SensorMLDocument.Factory.parse(sensor_status); SOLRInsertSensorInfoDAO dao = new SOLRInsertSensorInfoDAO(); this.insertedSensorId = dao.insertSensor(SensorMLDecoder.decode(doc)); log.debug("inserted test sensor: {}", this.insertedSensorId); }
From source file:org.n52.oss.IT.AutoCompleteServletIT.java
public void insertSensor() throws OwsExceptionReport, XmlException, IOException { File sensor_status = new File(ClassLoader.getSystemResource("Requests/testsensor.xml").getFile()); SensorMLDocument doc = SensorMLDocument.Factory.parse(sensor_status); // FIXME use mocked up up database backend SOLRInsertSensorInfoDAO dao = new SOLRInsertSensorInfoDAO( new SolrConnection("http://localhost:8983/solr", 1000)); SensorMLDecoder d = new SensorMLDecoder(); this.insertedSensorId = dao.insertSensor(d.decode(doc)); log.debug("inserted test sensor: {}", this.insertedSensorId); }
From source file:edu.snu.dolphin.bsp.examples.ml.algorithms.regression.LinearRegTest.java
/** * Run LinearReg test./*from w ww . j a v a2 s .co m*/ */ @Test public void testLinearReg() throws Exception { final String[] args = { "-dim", "3", "-maxIter", "20", "-stepSize", "0.001", "-lambda", "0.1", "-local", "true", "-split", "4", "-input", ClassLoader.getSystemResource("data").getPath() + "/regression", "-output", OUTPUT_PATH, "-maxNumEvalLocal", "5" }; DolphinLauncher.run(Configurations.merge( DolphinConfiguration.getConfiguration(args, LinearRegParameters.getCommandLine()), Tang.Factory.getTang().newConfigurationBuilder() .bindNamedParameter(JobIdentifier.class, "Linear Regression") .bindImplementation(UserJobInfo.class, LinearRegJobInfo.class) .bindImplementation(UserParameters.class, LinearRegParameters.class).build())); final File expectedModel = new File(ClassLoader.getSystemResource("result").getPath() + "/linearreg_model"); final File actualModel = new File(OUTPUT_PATH + "/model/CtrlTask-0"); Assert.assertTrue(FileUtils.contentEquals(expectedModel, actualModel)); final File expectedAccuracy = new File( ClassLoader.getSystemResource("result").getPath() + "/linearreg_loss"); final File actualAccuracy = new File(OUTPUT_PATH + "/loss/CtrlTask-0"); Assert.assertTrue(FileUtils.contentEquals(expectedAccuracy, actualAccuracy)); }
From source file:com.baidu.rigel.biplatform.parser.util.PropertiesUtil.java
/** * loadPropertiesFromCurrent//w ww . j a v a2 s . co m * @param resource * @return * @throws IOException */ public static Properties loadPropertiesFromPath(String resource) throws IOException { String location = resource; if (StringUtils.isBlank(location)) { location = "conf/default.properties"; } Properties properties = new Properties(); ClassLoader classLoaderToUse = Thread.currentThread().getContextClassLoader(); URL url = classLoaderToUse != null ? classLoaderToUse.getResource(location) : ClassLoader.getSystemResource(location); URLConnection con = url.openConnection(); InputStream is = con.getInputStream(); try { if (location != null && location.endsWith(".xml")) { properties.loadFromXML(is); } else { properties.load(is); } } finally { IOUtils.close(con); IOUtils.closeQuietly(is); } return properties; }
From source file:org.apache.hadoop.gateway.svcregfunc.impl.ServiceRegistryFunctionsTest.java
private static URL getTestResource(String name) { name = ServiceRegistryFunctionsTest.class.getName().replaceAll("\\.", "/") + "/" + name; URL url = ClassLoader.getSystemResource(name); return url;/*from ww w .j a va 2s. c om*/ }