List of usage examples for java.lang ClassLoader getSystemResourceAsStream
public static InputStream getSystemResourceAsStream(String name)
From source file:org.phenotips.ontology.internal.GeneNomenclatureTest.java
@Test public void checkURLConfigurable() throws ComponentLookupException, URISyntaxException, ClientProtocolException, IOException, InitializationException { when(this.configuration.getProperty("phenotips.ontologies.hgnc.serviceURL", "http://rest.genenames.org/")) .thenReturn("https://proxy/genenames/"); URI expectedURI = new URI("https://proxy/genenames/fetch/symbol/BRCA1"); CapturingMatcher<HttpUriRequest> reqCapture = new CapturingMatcher<>(); when(this.client.execute(Matchers.argThat(reqCapture))).thenReturn(this.response); when(this.response.getEntity()).thenReturn(this.responseEntity); when(this.responseEntity.getContent()).thenReturn(ClassLoader.getSystemResourceAsStream("BRCA1.json")); // Since the component was already initialized in setUp() with the default URL, re-initialize it // with the new configuration mock ((Initializable) this.mocker.getComponentUnderTest()).initialize(); OntologyTerm result = this.mocker.getComponentUnderTest().getTerm("BRCA1"); Assert.assertEquals(expectedURI, reqCapture.getLastValue().getURI()); Assert.assertEquals("application/json", reqCapture.getLastValue().getLastHeader("Accept").getValue()); Assert.assertNotNull(result);//www .jav a 2s .c o m Assert.assertEquals("BRCA1", result.get("symbol")); Assert.assertEquals("breast cancer 1, early onset", result.getName()); JSONArray aliases = (JSONArray) result.get("alias_symbol"); Assert.assertArrayEquals(new String[] { "RNF53", "BRCC1", "PPP1R53" }, aliases.toArray()); verify(this.cache).set("BRCA1", result); }
From source file:org.apache.james.mailbox.tika.TikaTextExtractorTest.java
@Test public void slideOdpTest() throws Exception { InputStream inputStream = ClassLoader.getSystemResourceAsStream("documents/slides.odp"); assertThat(inputStream).isNotNull(); assertThat(textExtractor.extractContent(inputStream, "application/vnd.oasis.opendocument.presentation") .getTextualContent()).contains( "James is awesome\n\nIt manages attachments so well!\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); }
From source file:org.jboss.arquillian.drone.factory.AjocadoFactory.java
@SuppressWarnings("unchecked") private List<String> getExtensionsListFromResource(String resourceName) { try {//from w w w . j a v a2 s . c o m return IOUtils.readLines(ClassLoader.getSystemResourceAsStream(resourceName)); } catch (IOException e) { throw new IllegalStateException(e); } }
From source file:org.apache.tika.server.UnpackerResourceTest.java
@Test public void testDocPicture() throws Exception { Response response = WebClient.create(endPoint + UNPACKER_PATH).type(APPLICATION_MSWORD) .accept("application/zip").put(ClassLoader.getSystemResourceAsStream(TEST_DOC_WAV)); Map<String, String> data = readZipArchive((InputStream) response.getEntity()); assertEquals(JPG_MD5, data.get(JPG_NAME)); }
From source file:org.apache.axis2.util.Loader.java
/** * Searches for <code>resource</code> in different * places. The search order is as follows: * <ol>//from w w w . j a v a 2 s.c om * <p><li>Search for <code>resource</code> using the thread context * class loader under Java2. If that fails, search for * <code>resource</code> using the class loader that loaded this * class (<code>Loader</code>). * <p><li>Try one last time with * <code>ClassLoader.getSystemResourceAsStream(resource)</code>, that is is * using the system class loader in JDK 1.2 and virtual machine's * built-in class loader in JDK 1.1. * </ol> * <p/> * * @param resource * @return Returns URL */ static public InputStream getResourceAsStream(String resource) { ClassLoader classLoader = null; try { // Let's try the Thread Context Class Loader classLoader = getTCL(); if (classLoader != null) { log.debug("Trying to find [" + resource + "] using " + classLoader + " class loader."); InputStream is = classLoader.getResourceAsStream(resource); if (is != null) { return is; } } } catch (Throwable t) { log.warn("Caught Exception while in Loader.getResourceAsStream. This may be innocuous.", t); } try { // We could not find resource. Ler us now try with the // classloader that loaded this class. classLoader = Loader.class.getClassLoader(); if (classLoader != null) { log.debug("Trying to find [" + resource + "] using " + classLoader + " class loader."); InputStream is = classLoader.getResourceAsStream(resource); if (is != null) { return is; } } } catch (Throwable t) { log.warn("Caught Exception while in Loader.getResourceAsStream. This may be innocuous.", t); } // Last ditch attempt: get the resource from the class path. It // may be the case that clazz was loaded by the Extentsion class // loader which the parent of the system class loader. Hence the // code below. log.debug("Trying to find [" + resource + "] using ClassLoader.getSystemResourceAsStream()."); return ClassLoader.getSystemResourceAsStream(resource); }
From source file:org.cloudifysource.esc.driver.provisioning.privateEc2.parser.PrivateEc2TemplateParserTest.java
@Test public void testTemplateWithRef() throws IOException, PrivateEc2ParserException { InputStream templateStream = ClassLoader.getSystemResourceAsStream("./cfn_templates/ref.template"); ToStringBuilder.setDefaultStyle(ToStringStyle.SHORT_PREFIX_STYLE); PrivateEc2Template template = ParserUtils.mapJson(PrivateEc2Template.class, templateStream); assertNotNull(template);//from www. j a v a2 s. c o m }
From source file:org.apache.ambari.server.api.services.StacksService.java
/** * Handles URL: /clusters/{clusterId}/category * Get all services for a cluster.// ww w . j a v a 2 s . c o m * * @param headers http headers * @param ui uri info * @return service collection resource representation */ @GET @Path("{stackName}/versions/{stackVersion}/category") @Produces("text/plain") public Response getServicesGroups(String body, @Context HttpHeaders headers, @Context UriInfo ui, @PathParam("stackName") String stackName, @PathParam("stackVersion") String stackVersion) { String SERVICE_TYPE_FILE = "service_type.json"; String result = ""; InputStream rcoInputStream = null; try { rcoInputStream = ClassLoader.getSystemResourceAsStream(SERVICE_TYPE_FILE); result = IOUtils.toString(rcoInputStream); } catch (Exception e) { } finally { if (rcoInputStream != null) { try { rcoInputStream.close(); } catch (Exception e) { System.out.println("inputstream close failed"); } } } ResponseBuilder builder = Response.ok(result); return builder.build(); }
From source file:org.apache.ambari.msi.ConfigurationProvider.java
@SuppressWarnings("unchecked") private void init() { allConfigs = new HashMap<String, Map<String, String>>(); XStream xstream = new XStream(new StaxDriver()); xstream.alias("configuration", Map.class); xstream.registerConverter(new ScomConfigConverter()); for (String configurationResource : clusterConfigurationResources) { String configFileName = configurationResource + "." + DESTINATION; InputStream is = ClassLoader.getSystemResourceAsStream(configFileName); if (is == null) continue; Map<String, String> properties = (HashMap<String, String>) xstream.fromXML(is); allConfigs.put(configurationResource, properties); }/*from w ww .java 2s .c o m*/ }
From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java
@Test public void htmlEmailShouldBeWellConvertedToJson() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris")); MailboxMessage htmlMail = new SimpleMailboxMessage(date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/htmlMail.eml"))), new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("social", "pocket-money").build(), propertyBuilder, MAILBOX_ID); htmlMail.setModSeq(MOD_SEQ);/* w w w.j a v a2 s.co m*/ htmlMail.setUid(UID); assertThatJson(messageToElasticSearchJson.convertToJson(htmlMail, ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER) .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/htmlMail.json"))); }
From source file:org.abs_models.backend.erlang.ErlApp.java
private void copyRuntime() throws IOException { InputStream is = null;//from w w w . j a v a 2s . c o m // TODO: this only works when the erlang compiler is invoked // from a jar file. See http://stackoverflow.com/a/2993908 on // how to handle the other case. URLConnection resource = getClass().getResource("").openConnection(); try { new File(destDir + "/absmodel/ebin").mkdirs(); if (resource instanceof JarURLConnection) { for (String f : RUNTIME_FILES) { if (f.endsWith("/*")) { String dirname = f.substring(0, f.length() - 2); String inname = JAR_PATH + dirname; String outname = destDir + "/" + dirname; new File(outname).mkdirs(); copyJarDirectory(((JarURLConnection) resource).getJarFile(), inname, outname); } else { is = ClassLoader.getSystemResourceAsStream(JAR_PATH + f); if (is == null) throw new RuntimeException("Could not locate Runtime file:" + f); String outputFile = f.replace('/', File.separatorChar); File file = new File(destDir, outputFile); file.getParentFile().mkdirs(); Files.asByteSink(file).writeFrom(is); } } } else if (resource.getURL().getProtocol().equals("file")) { /* stolz: This at least works for the unit tests from within Eclipse */ File file = new File("src/main/resources/erlang/"); assert file.exists(); FileUtils.copyDirectory(file, destDir); } else { throw new UnsupportedOperationException("File type: " + resource); } if (index_file != null) { File http_out_file = new File(destDir + "/absmodel/priv/index.html"); http_out_file.getParentFile().mkdirs(); FileUtils.copyFile(index_file, http_out_file); } if (static_dir != null) { File static_out_dir = new File(destDir + "/absmodel/priv/static"); static_out_dir.mkdirs(); FileUtils.copyDirectory(static_dir, static_out_dir); } } finally { if (is != null) is.close(); } for (String f : EXEC_FILES) { new File(destDir, f).setExecutable(true, false); } }