List of usage examples for java.lang ClassLoader getResource
public URL getResource(String name)
From source file:com.autentia.tnt.bean.JPivotBean.java
public String showTable() { try {/*from w w w . j a va 2s. c o m*/ ClassLoader loader = Thread.currentThread().getContextClassLoader(); File file = new File(loader.getResource("com/autentia/tnt/jpivot/jpivot_test.xml").toURI()); cubeURL = file.toURL(); String mdxQuery = "select {[Measures].[Muestras]} on columns , {([Contacto])} on rows from [Informe]"; this.olapModel = JPivotUtils.executeOlapQuery(mdxQuery, cubeURL, (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false)); } catch (Exception e) { log.error("cannot generate the jpivot cube: ", e); return "error"; } return "jpivot"; }
From source file:azkaban.execapp.FlowPreparerTest.java
@Before public void setUp() throws Exception { tearDown();//from w w w .j av a2 s. c o m executionsDir.mkdirs(); projectsDir.mkdirs(); ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource(SAMPLE_FLOW_01 + ".zip").getFile()); ProjectFileHandler projectFileHandler = mock(ProjectFileHandler.class); when(projectFileHandler.getFileType()).thenReturn("zip"); when(projectFileHandler.getLocalFile()).thenReturn(file); ProjectLoader projectLoader = mock(ProjectLoader.class); when(projectLoader.getUploadedFile(12, 34)).thenReturn(projectFileHandler); instance = new FlowPreparer(projectLoader, executionsDir, projectsDir, installedProjects); }
From source file:azkaban.storage.LocalStorageTest.java
@Test public void testPutGet() throws Exception { ClassLoader classLoader = getClass().getClassLoader(); File testFile = new File(classLoader.getResource(SAMPLE_FILE).getFile()); final StorageMetadata metadata = new StorageMetadata(1, 1, "testuser", Md5Hasher.md5Hash(testFile)); final String key = localStorage.put(metadata, testFile); assertNotNull(key);/*from w w w .java2 s . c o m*/ log.info("Key URI: " + key); File expectedTargetFile = new File(BASE_DIRECTORY, new StringBuilder().append(metadata.getProjectId()).append(File.separator) .append(metadata.getProjectId()).append("-").append(new String(metadata.getHash())) .append(".zip").toString()); assertTrue(expectedTargetFile.exists()); assertTrue(FileUtils.contentEquals(testFile, expectedTargetFile)); // test get InputStream getIs = localStorage.get(key); assertNotNull(getIs); File getFile = new File("tmp.get"); FileUtils.copyInputStreamToFile(getIs, getFile); assertTrue(FileUtils.contentEquals(testFile, getFile)); getFile.delete(); }
From source file:com.kolich.curacao.embedded.mappers.ClasspathFileReturnMapper.java
@Override public final void render(final AsyncContext context, final HttpServletResponse response, final @Nonnull File entity) throws Exception { // Get the path, and remove the leading slash. final String path = entity.getAbsolutePath().substring(1); final ClassLoader loader = Thread.currentThread().getContextClassLoader(); final URL resource = loader.getResource(path); if (resource == null) { logger__.warn("Resource not found: {}", path); response.setStatus(HttpServletResponse.SC_NOT_FOUND); } else {// w w w. j a va2s . co m logger__.debug("Serving resource from classpath: {}", path); try (final InputStream in = loader.getResourceAsStream(path); final OutputStream out = response.getOutputStream()) { IOUtils.copyLarge(in, out); } } }
From source file:com.viddu.handlebars.HandlebarsMojoTest.java
public void testExecute() throws MojoExecutionException { ClassLoader ccl = Thread.currentThread().getContextClassLoader(); URL handleBarsUrl = ccl.getResource("handlebars-1.0.rc.1.js"); URL templatesUrl = ccl.getResource("templates"); String outputDir = "target/compiledTemplates"; HandlebarsMojo hbMojo = new HandlebarsMojo(); hbMojo.setHandlebarsLibrary(new File(handleBarsUrl.getPath())); hbMojo.setInputDirectory(new File(templatesUrl.getPath())); hbMojo.setOutputDirectory(new File(outputDir)); hbMojo.execute();/* w w w . j av a2s . co m*/ }
From source file:hudson.plugins.testlink.result.parser.tap.TestTapParser.java
public void testTapParser() { assertEquals(this.parser.getName(), "TAP"); ClassLoader cl = TestTapParser.class.getClassLoader(); URL url = cl.getResource("hudson/plugins/testlink/result/parser/tap/br.eti.kinoshita.tap.SampleTest.tap"); File file = new File(url.getFile()); TestSet testSet = null;// w ww . j av a 2s .c om try { testSet = this.parser.parse(file); } catch (ParserException pe) { fail("Failed to parse TAP file '" + file + "': " + pe.getMessage()); } assertNotNull("Failed to parse TAP. Null TestSet.", testSet); assertTrue("Wrong number of test results in TAP file '" + file + "'.", testSet.getNumberOfTestResults() == 1); assertTrue("Wrong status for test result 1", testSet.getTestResult(1).getStatus() == StatusValues.OK); assertTrue(testSet.getTestResult(1).getDescription().equals("testOk")); }
From source file:com.boundary.sdk.event.esper.EsperRouteTest.java
@Test public void testReadURIClasspath() throws IOException, URISyntaxException { ClassLoader classLoader = this.getClass().getClassLoader(); URL url = classLoader.getResource("test-esper-query-load.json"); File file = new File(url.toURI()); assertTrue("check if file", file.isFile()); assertTrue("check file exists", file.exists()); }
From source file:io.fabric8.maven.docker.util.DockerFileUtilTest.java
private File getDockerfilePath(int i, String dir) { ClassLoader classLoader = getClass().getClassLoader(); return new File(classLoader.getResource(String.format("interpolate/%s/Dockerfile_%d", dir, i)).getFile()); }
From source file:hudson.ClassicPluginStrategyTest.java
/** * Test finding resources under masking. * "foo1" plugin contains attribute of Mask-Classes: org.apache.http. *///w w w. j av a2 s . c om @LocalData @Issue("JENKINS-27289") public void testMaskResourceClassLoader() throws Exception { PluginWrapper pw = jenkins.getPluginManager().getPlugin("foo1"); Class<?> clazz = pw.classLoader.loadClass("org.apache.http.impl.io.SocketInputBuffer"); ClassLoader cl = clazz.getClassLoader(); URL url = cl.getResource("org/apache/http/impl/io/SocketInputBuffer.class"); assertNotNull(url); assertTrue("expected to find the class from foo1 plugin", url.toString().contains("plugins/foo1")); }
From source file:com.gu.conf.FileAndResourceLoader.java
private InputStream getResource(String resource) { ClassLoader classloader = FileAndResourceLoader.class.getClassLoader(); URL url = classloader.getResource(stripProtocol(resource)); if (url == null) { LOG.info("Ignoring missing configuration file " + resource); return null; }//from www . ja v a2 s . co m InputStream inputStream; try { inputStream = url.openStream(); } catch (IOException ioe) { LOG.warn("Cannot open resource trying to load properties from " + resource, ioe); return null; } return new BufferedInputStream(inputStream); }