List of usage examples for java.lang ClassLoader getResource
public URL getResource(String name)
From source file:org.apache.hadoop.distributedloadsimulator.sls.appmaster.InitializeAppMaster.java
private String getRunTimeClassPath() { LOG.info("Trying to generate classpath for app master from current thread's classpath"); String envClassPath = ""; String cp = System.getProperty("java.class.path"); if (cp != null) { envClassPath += cp.trim() + File.pathSeparator; }/* w w w.j a v a2 s. com*/ ClassLoader thisClassLoader = Thread.currentThread().getContextClassLoader(); URL url = thisClassLoader.getResource("yarn-site.xml"); envClassPath += new File(url.getFile()).getParent(); return envClassPath; }
From source file:com.github.dozermapper.core.util.ResourceLoader.java
public URL getResource(String resource) { resource = resource.trim();/* w ww. ja v a 2s . c o m*/ URL result = Thread.currentThread().getContextClassLoader().getResource(resource); // Could not find resource. Try with the classloader that loaded this class. if (result == null) { ClassLoader classLoader = ResourceLoader.class.getClassLoader(); if (classLoader != null) { result = classLoader.getResource(resource); } } // Last ditch attempt searching classpath if (result == null) { result = ClassLoader.getSystemResource(resource); } // one more time if (result == null && StringUtils.contains(resource, ":")) { try { result = new URL(resource); } catch (MalformedURLException e) { MappingUtils.throwMappingException(e); } } return result; }
From source file:com.microsoft.applicationinsights.agent.internal.config.XmlAgentConfigurationBuilderTest.java
private AgentConfiguration testConfiguration(String testFileName) throws IOException { File folder = null;/* w ww. j a va 2 s .c o m*/ try { folder = createFolder(); ClassLoader classLoader = getClass().getClassLoader(); URL testFileUrl = classLoader.getResource(testFileName); File sourceFile = new File(testFileUrl.toURI()); File destinationFile = new File(folder, TEMP_CONF_FILE); FileUtils.copyFile(sourceFile, destinationFile); return new XmlAgentConfigurationBuilder().parseConfigurationFile(folder.toString()); } catch (java.net.URISyntaxException e) { return null; } finally { cleanFolder(folder); } }
From source file:io.hops.tensorflow.TestYarnTF.java
@Test(timeout = 90000) public void testAddFiles() throws Exception { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); String mainPath = classLoader.getResource("foo.py").getPath(); String extraDepPy = classLoader.getResource("bar.py").getPath(); String extraDepZip = classLoader.getResource("baz.zip").getPath(); String[] args = { "--" + PYTHON, "/bin/python", "--" + AM_JAR, APPMASTER_JAR, "--" + MEMORY, "256", "--" + VCORES, "1", "--" + FILES, extraDepPy + "," + extraDepZip, "--" + MAIN, mainPath, "--" + PROTOCOL, "grpc+verbs" }; LOG.info("Initializing yarntf Client"); final Client client = new Client(new Configuration(yarnCluster.getConfig())); boolean initSuccess = client.init(args); Assert.assertTrue(initSuccess);/* www. j a va2s.c om*/ LOG.info("Running yarntf Client"); final ApplicationId appId = client.submitApplication(); boolean result = client.monitorApplication(appId); LOG.info("Client run completed. Result=" + result); Assert.assertEquals(2, TestUtils.verifyContainerLog(yarnCluster, 2, null, true, "hello, from baz")); Assert.assertEquals(2, TestUtils.verifyContainerLog(yarnCluster, 2, null, true, "YARNTF_PROTOCOL=grpc+verbs")); Thread.sleep(5000); TestUtils.dumpAllAggregatedContainersLogs(yarnCluster, appId); }
From source file:com.boundary.sdk.event.esper.QueryListTest.java
private void load() throws Exception { ClassLoader classLoader = this.getClass().getClassLoader(); URL url = classLoader.getResource(QUERY_LIST_FILE); File file = new File(url.toURI()); ObjectMapper mapper = new ObjectMapper(); try {//from www .ja va2s . co m this.queryList = mapper.readValue(file, QueryList.class); } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.smartystreets.spring.SmartyStreetsAPIDataTransformTest.java
@Test public void canTransformAddressResponse() throws IOException { ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource("address_response.json").getFile()); ObjectMapper om = new ObjectMapper(); AddressResponse addressResponse = om.readValue(file, AddressResponse[].class)[0]; assertEquals(0, addressResponse.getInputIndex()); assertEquals(0, addressResponse.getCandidateIndex()); assertEquals("13936 Flay Ave N", addressResponse.getDeliveryLine1()); assertEquals("Hugo MN 55038-6401", addressResponse.getLastLine()); assertEquals("550386401369", addressResponse.getDeliveryPointBarcode()); Components components = addressResponse.getComponents(); assertEquals("13936", components.getPrimaryNumber()); assertEquals("Flay", components.getStreetName()); assertEquals("N", components.getStreetPostdirection()); assertEquals("Ave", components.getStreetSuffix()); assertEquals("Hugo", components.getCityName()); assertEquals("MN", components.getStateAbbreviation()); assertEquals("55038", components.getZipcode()); assertEquals("6401", components.getPlus4Code()); assertEquals("36", components.getDeliveryPoint()); assertEquals("9", components.getDeliveryPointCheckDigit()); Metadata metadata = addressResponse.getMetadata(); assertEquals(RecordType.S, metadata.getRecordType()); assertEquals(ZipType.Standard, metadata.getZipType()); assertEquals("27163", metadata.getCountyFips()); assertEquals("Washington", metadata.getCountyName()); assertEquals("R009", metadata.getCarrierRoute()); assertEquals("06", metadata.getCongressionalDistrict()); assertEquals(ResidentialDeliveryIndicator.Residential, metadata.getRdi()); assertEquals("0238", metadata.getElotSequence()); assertEquals(ElotSortType.A, metadata.getElotSort()); assertEquals(BigDecimal.valueOf(45.15118D), metadata.getLocation().getLatitude()); assertEquals(BigDecimal.valueOf(-92.99295D), metadata.getLocation().getLongitude()); assertEquals("Zip9", metadata.getLocation().getPrecision()); assertEquals("Central", metadata.getTimeInfo().getTimeZone()); assertEquals(BigDecimal.valueOf(-6), metadata.getTimeInfo().getUtcOffset()); assertEquals(true, metadata.getTimeInfo().isDst()); Analysis analysis = addressResponse.getAnalysis(); assertEquals(DeliveryPointValidationType.Y, analysis.getDeliveryPointValidationType()); assertEquals("AABB", analysis.getDpvFootnotes()); assertEquals("N", analysis.getDpvCmra()); assertEquals("N", analysis.getDpvVacant()); assertEquals("Y", analysis.getActive()); assertEquals("N#", analysis.getFootnotes()); }
From source file:ffx.xray.CIFFilterTest.java
@Test public void testCIFFilter3DYC() { String filename = "ffx/xray/structures/3DYC.ent"; ClassLoader cl = this.getClass().getClassLoader(); File cifFile = new File(cl.getResource(filename).getPath()); // load any properties associated with it CompositeConfiguration properties = Keyword.loadProperties(cifFile); CIFFilter cifFilter = new CIFFilter(); ReflectionList reflectionList = cifFilter.getReflectionList(cifFile); assertNotNull(" Reflection list should not be null", reflectionList); DiffractionRefinementData refinementData = new DiffractionRefinementData(properties, reflectionList); assertTrue(" CIF data not read in correctly", cifFilter.readFile(cifFile, reflectionList, refinementData, properties)); HKL hkl = reflectionList.getHKL(58, 0, 13); assertEquals("58 0 13 F", 99.7, refinementData.getF(hkl.index()), 0.01); assertEquals("58 0 13 sigF", 69.7, refinementData.getSigF(hkl.index()), 0.01); assertEquals("58 0 13 freeR value", 1, refinementData.freer[hkl.index()]); hkl = reflectionList.getHKL(28, 20, 5); assertEquals("28 20 5 F", 428.1, refinementData.getF(hkl.index()), 0.01); assertEquals("28 20 5 sigF", 10.1, refinementData.getSigF(hkl.index()), 0.01); assertEquals("28 20 5 freeR value", 0, refinementData.freer[hkl.index()]); }
From source file:com.tera.common.dataload.xml.XMLDataLoadService.java
/** * @param directory//w w w. j a va 2s . c o m * @param clazz * @param xsdLocation * @return */ protected final T loadFromReal(String directory, String clazz, String xsdLocation, ClassLoader classLoader) { try { Unmarshaller un = JaxbUtil.create(clazz, classLoader, classLoader.getResource(xsdLocation)); File dir = new File(directory); T targetContainer = loadFromRealDirectory(un, dir); return targetContainer; } catch (Exception e) { log.error("Exception during unmarshalling", e); } return null; }
From source file:org.apache.logging.log4j.core.config.EDNConfigurationFactory.java
private boolean isAltConfigFile() { ClassLoader loader = LoaderUtil.getThreadContextClassLoader(); return null != loader.getResource(ALT_CONFIG_NAME); }
From source file:com.ibm.team.build.internal.hjplugin.RTCFacadeFactory.java
private static URL getHjplugin_rtcJar(ClassLoader originalClassLoader, String fullClassName, PrintStream debugLog) {/*ww w . j av a2 s . c o m*/ if (originalClassLoader instanceof URLClassLoader) { URLClassLoader urlClassLoader = (URLClassLoader) originalClassLoader; URL[] originalURLs = urlClassLoader.getURLs(); for (URL url : originalURLs) { String file = url.getFile(); if (file.contains("com.ibm.team.build.hjplugin-rtc")) { //$NON-NLS-1$ //$NON-NLS-2$ debug(debugLog, "Found hjplugin-rtc jar " + url.getFile()); //$NON-NLS-1$ return url; } } debug(debugLog, "Did not find hjplugin-rtc jar from URLClassLoader"); //$NON-NLS-1$ } String realClassName = fullClassName.replace('.', '/') + ".class"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ URL url = originalClassLoader.getResource(realClassName); debug(debugLog, "Found " + realClassName + " in " + url.toString()); //$NON-NLS-1$ //$NON-NLS-2$ try { URLConnection connection = url.openConnection(); if (connection instanceof JarURLConnection) { JarURLConnection jarConnection = (JarURLConnection) connection; debug(debugLog, "hjplugin-rtc jar from the connection " + jarConnection.getJarFileURL()); //$NON-NLS-1$ return jarConnection.getJarFileURL(); } } catch (IOException e) { debug(debugLog, "Unable to obtain URLConnection ", e); //$NON-NLS-1$ } debug(debugLog, "Unable to find hjplugin-rtc.jar"); //$NON-NLS-1$ return null; }