List of usage examples for java.lang ClassLoader getSystemResourceAsStream
public static InputStream getSystemResourceAsStream(String name)
From source file:org.apache.james.jmap.methods.integration.GetMessageListMethodTest.java
@Test public void getMessageListOROperatorShouldWork() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotSeenNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); ComposedMessageId messageNotSeenFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"), new Date(), false, new Flags(Flags.Flag.FLAGGED)); ComposedMessageId messageSeenNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/oneInlinedImage.eml"), new Date(), false, new Flags(Flags.Flag.SEEN)); ComposedMessageId messageSeenFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/oneInlinedImage.eml"), new Date(), false, FlagsBuilder.builder().add(Flags.Flag.SEEN, Flags.Flag.FLAGGED).build()); await();// w ww. ja v a2 s. c o m given().header("Authorization", accessToken.serialize()).body( "[[\"getMessageList\", {\"filter\":{\"operator\":\"OR\",\"conditions\":[{\"isFlagged\":\"true\"},{\"isUnread\":\"true\"}]}}, \"#0\"]]") .when().post("/jmap").then().statusCode(200).body(NAME, equalTo("messageList")) .body(ARGUMENTS + ".messageIds", allOf(containsInAnyOrder(messageNotSeenFlagged.getMessageId().serialize(), messageSeenFlagged.getMessageId().serialize(), messageNotSeenNotFlagged.getMessageId().serialize()), not(containsInAnyOrder(messageSeenNotFlagged.getMessageId().serialize())))); }
From source file:org.apache.ambari.server.controller.utilities.PropertyHelper.java
private static Map<Resource.InternalType, Map<Resource.Type, String>> readKeyPropertyIds(String filename) { ObjectMapper mapper = new ObjectMapper(); try {//from ww w.j a va 2s . c o m Map<Resource.InternalType, Map<Resource.InternalType, String>> map = mapper.readValue( ClassLoader.getSystemResourceAsStream(filename), new TypeReference<Map<Resource.InternalType, Map<Resource.InternalType, String>>>() { }); Map<Resource.InternalType, Map<Resource.Type, String>> returnMap = new HashMap<Resource.InternalType, Map<Resource.Type, String>>(); // convert inner maps from InternalType to Type for (Map.Entry<Resource.InternalType, Map<Resource.InternalType, String>> entry : map.entrySet()) { Map<Resource.Type, String> innerMap = new HashMap<Resource.Type, String>(); for (Map.Entry<Resource.InternalType, String> entry1 : entry.getValue().entrySet()) { innerMap.put(Resource.Type.values()[entry1.getKey().ordinal()], entry1.getValue()); } returnMap.put(entry.getKey(), innerMap); } return returnMap; } catch (IOException e) { throw new IllegalStateException("Can't read properties file " + filename, e); } }
From source file:org.phenotips.ontology.internal.GeneNomenclatureTest.java
@Test public void countFetchesFromRemoteServer() throws ComponentLookupException, URISyntaxException, ClientProtocolException, IOException { URI expectedURI = new URI("http://rest.genenames.org/search/" + "+status%3A%28Approved%29+AND+%28+symbol%3A%28brcA*%29+alias_symbol%3A%28brcA*%29%29"); 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("brca.json")); Map<String, Object> search = new LinkedHashMap<>(); search.put("status", "Approved"); Map<String, String> subquery = new LinkedHashMap<>(); subquery.put("symbol", "brcA*"); subquery.put("alias_symbol", "brcA*"); search.put("AND", subquery); long result = this.mocker.getComponentUnderTest().count(search); Assert.assertEquals(expectedURI, reqCapture.getLastValue().getURI()); Assert.assertEquals("application/json", reqCapture.getLastValue().getLastHeader("Accept").getValue()); Assert.assertEquals(6, result);//from www . j ava 2 s. c o m }
From source file:shuffle.fwk.config.ConfigManager.java
public InputStream getResourceInputStream(String path) { InputStream result = null;/*from ww w. j a va2 s . c o m*/ if (path != null) { result = ClassLoader.getSystemResourceAsStream(path); } return result; }
From source file:org.opencommercesearch.client.ProductApi.java
/** * Loads configuration properties defined in a file "config.properties" on the class path. * * @return A properties instance with any configuration options that are needed. * @throws IOException If the file config.properties can't be read. *//* w w w .ja va 2s. co m*/ protected Properties loadProperties() throws IOException { Properties properties = new Properties(); InputStream in = ClassLoader.getSystemResourceAsStream("config.properties"); if (in == null) { throw new IOException("File config.properties not found on classpath."); } properties.load(in); in.close(); return properties; }
From source file:corina.util.SimpleLog.java
private static InputStream getResourceAsStream(final String name) { return (InputStream) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { ClassLoader threadCL = getContextClassLoader(); if (threadCL != null) { return threadCL.getResourceAsStream(name); } else { return ClassLoader.getSystemResourceAsStream(name); }//from w ww. ja v a 2 s .c o m } }); }
From source file:org.phenotips.ontology.internal.GeneNomenclatureTest.java
@Test public void testQueryBuilder() throws URISyntaxException, ClientProtocolException, IOException, ComponentLookupException { URI expectedURI = new URI("http://rest.genenames.org/search/+status%3A%28Approved%29" + "+AND+locus_type%3A%28RNA%2C%5C+cluster+RNA%2C%5C+micro*+%29" + "+%28+symbol%3A%28br%5C%3AcA*%29+alias_symbol%3A%28br%5C%5EcA*%29%29" + "+AND+%28+locus_group%3A%28non%5C-coding%5C+RNA%29%29+-%28+symbol%3A%28M*%29%29"); 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("NOTHING.json")); Map<String, Object> search = new LinkedHashMap<>(); search.put("status", "Approved"); search.put("locus_type", Arrays.asList("RNA, cluster", "RNA, micro*")); search.put("hgnc_id", Collections.emptyList()); Map<String, String> subquery = new LinkedHashMap<>(); subquery.put("symbol", "br:cA*"); subquery.put("alias_symbol", "br^cA*"); search.put("OR", subquery); subquery = new LinkedHashMap<>(); subquery.put("locus_group", "non-coding RNA"); search.put("AND", subquery); subquery = new LinkedHashMap<>(); subquery.put("symbol", "M*"); search.put("NOT", subquery); subquery = new LinkedHashMap<>(); subquery.put("what", "where"); search.put("DISCARD", subquery); this.mocker.getComponentUnderTest().search(search); Assert.assertEquals(expectedURI, reqCapture.getLastValue().getURI()); Assert.assertEquals("application/json", reqCapture.getLastValue().getLastHeader("Accept").getValue()); }
From source file:org.apache.james.jmap.methods.integration.GetMessageListMethodTest.java
@Test public void getMessageListNOTOperatorShouldWork() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotSeenNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); ComposedMessageId messageNotSeenFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"), new Date(), false, new Flags(Flags.Flag.FLAGGED)); ComposedMessageId messageSeenNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/oneInlinedImage.eml"), new Date(), false, new Flags(Flags.Flag.SEEN)); ComposedMessageId messageSeenFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/oneInlinedImage.eml"), new Date(), false, FlagsBuilder.builder().add(Flags.Flag.SEEN, Flags.Flag.FLAGGED).build()); await();//w w w. jav a2s . c om given().header("Authorization", accessToken.serialize()).body( "[[\"getMessageList\", {\"filter\":{\"operator\":\"NOT\",\"conditions\":[{\"isFlagged\":\"true\"},{\"isUnread\":\"true\"}]}}, \"#0\"]]") .when().post("/jmap").then().statusCode(200).body(NAME, equalTo("messageList")) .body(ARGUMENTS + ".messageIds", allOf(containsInAnyOrder(messageSeenNotFlagged.getMessageId().serialize()), not(containsInAnyOrder(messageNotSeenFlagged.getMessageId().serialize(), messageSeenFlagged.getMessageId().serialize(), messageNotSeenNotFlagged.getMessageId().serialize())))); }
From source file:org.acmsl.commons.regexpplugin.RegexpManager.java
/** * Retrieves the stream associated to the resource * whose name is given, using a concrete class loader. * @param loader the class loader./*from w ww . java 2 s. c o m*/ * @param name the resource name. * @return the stream. */ @Nullable protected InputStream getResourceAsStream(@Nullable final ClassLoader loader, @NotNull final String name) { return AccessController.doPrivileged(new PrivilegedAction<InputStream>() { public InputStream run() { final InputStream result; if (loader != null) { result = loader.getResourceAsStream(name); } else { result = ClassLoader.getSystemResourceAsStream(name); } return result; } }); }
From source file:org.apache.ignite.internal.managers.deployment.GridDeploymentClassLoader.java
/** {@inheritDoc} */ @Nullable//www .j av a 2 s. c o m @Override public InputStream getResourceAsStream(String name) { assert !Thread.holdsLock(mux); if (byteMap != null && name.endsWith(".class")) { byte[] bytes = byteMap.get(name); if (bytes != null) { if (log.isDebugEnabled()) log.debug("Got class definition from byte code cache: " + name); return new ByteArrayInputStream(bytes); } } InputStream in = ClassLoader.getSystemResourceAsStream(name); if (in == null) in = super.getResourceAsStream(name); // Most probably, this is initiated by GridUtils.getUserVersion(). // No point to send request. if ("META-INF/services/org.apache.commons.logging.LogFactory".equalsIgnoreCase(name)) { if (log.isDebugEnabled()) log.debug( "Denied sending remote request for META-INF/services/org.apache.commons.logging.LogFactory."); return null; } if (in == null) in = sendResourceRequest(name); return in; }