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 getMessageListUnsetDraftFilterShouldWork() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotDraft = 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 messageDraft = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"), new Date(), false, new Flags(Flags.Flag.DRAFT)); await();/*from w w w . j ava2 s . c o m*/ given().header("Authorization", accessToken.serialize()) .body("[[\"getMessageList\", {\"filter\":{\"isDraft\":\"false\"}}, \"#0\"]]").when().post("/jmap") .then().statusCode(200).body(NAME, equalTo("messageList")).body(ARGUMENTS + ".messageIds", allOf(containsInAnyOrder(messageNotDraft.getMessageId().serialize()), not(containsInAnyOrder(messageDraft.getMessageId().serialize())))); }
From source file:org.phenotips.ontology.internal.GeneNomenclatureTest.java
@Test public void getVersionFetchesFromRemoteServer() throws ComponentLookupException, URISyntaxException, ClientProtocolException, IOException { URI expectedURI = new URI("http://rest.genenames.org/info"); 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("info.json")); String result = this.mocker.getComponentUnderTest().getVersion(); Assert.assertEquals(expectedURI, reqCapture.getLastValue().getURI()); Assert.assertEquals("application/json", reqCapture.getLastValue().getLastHeader("Accept").getValue()); Assert.assertEquals("2014-09-01T04:42:14.649Z", result); }
From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java
@Test(expected = NullPointerException.class) public void emailWithNoMailboxIdShouldThrow() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES); MailboxMessage mailWithNoMailboxId;//from w w w . ja va 2s .c o m try { mailWithNoMailboxId = new SimpleMailboxMessage(MESSAGE_ID, date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/recursiveMail.eml"))), new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(), propertyBuilder, null); mailWithNoMailboxId.setModSeq(MOD_SEQ); mailWithNoMailboxId.setUid(UID); } catch (Exception exception) { throw Throwables.propagate(exception); } messageToElasticSearchJson.convertToJson(mailWithNoMailboxId, ImmutableList.of(new MockMailboxSession("username").getUser())); }
From source file:org.apache.tika.server.TikaResourceTest.java
@Test public void testDataIntegrityCheck() throws Exception { Response response = null;//w ww .j a v a2s . c o m try { response = WebClient.create(endPoint + TIKA_PATH).type("application/pdf").accept("text/plain") .header(TikaResource.X_TIKA_OCR_HEADER_PREFIX + "tesseractPath", "C://tmp//hello.bat\u0000") .put(ClassLoader.getSystemResourceAsStream("testOCR.pdf")); assertEquals(400, response.getStatus()); } catch (ProcessingException e) { //can't tell why this intermittently happens. :( //started after the upgrade to 3.2.7 } response = WebClient.create(endPoint + TIKA_PATH).type("application/pdf").accept("text/plain") .header(TikaResource.X_TIKA_OCR_HEADER_PREFIX + "tesseractPath", "bogus path") .put(ClassLoader.getSystemResourceAsStream("testOCR.pdf")); assertEquals(200, response.getStatus()); }
From source file:org.apache.any23.mime.TikaMIMETypeDetector.java
/** * Loads the <code>Tika</code> configuration file. * * @return the input stream containing the configuration. */// w ww. j a va 2 s . c om private InputStream getResourceAsStream() { InputStream result; result = TikaMIMETypeDetector.class.getResourceAsStream(RESOURCE_NAME); if (result == null) { result = TikaMIMETypeDetector.class.getClassLoader().getResourceAsStream(RESOURCE_NAME); if (result == null) { result = ClassLoader.getSystemResourceAsStream(RESOURCE_NAME); } } return result; }
From source file:org.apache.ambari.server.stack.StackDirectory.java
/** * Parse role command order file// www. j a va 2 s .co m */ private void parseRoleCommandOrder() { HashMap<String, Object> result = null; ObjectMapper mapper = new ObjectMapper(); try { TypeReference<Map<String, Object>> rcoElementTypeReference = new TypeReference<Map<String, Object>>() { }; if (rcoFilePath != null) { File file = new File(rcoFilePath); result = mapper.readValue(file, rcoElementTypeReference); LOG.info("Role command order info was loaded from file: {}", file.getAbsolutePath()); } else { InputStream rcoInputStream = ClassLoader.getSystemResourceAsStream(ROLE_COMMAND_ORDER_FILE); result = mapper.readValue(rcoInputStream, rcoElementTypeReference); LOG.info("Role command order info was loaded from classpath: " + ClassLoader.getSystemResource(ROLE_COMMAND_ORDER_FILE)); } roleCommandOrder = new StackRoleCommandOrder(result); } catch (IOException e) { LOG.error(String.format("Can not read role command order info %s", rcoFilePath), e); } }
From source file:com.viadeo.kasper.exposition.http.jetty.resource.KasperDocResourceTest.java
/** * Get the JSON contents of the given claspath resource * // ww w .j ava 2s . c om * @param jsonFilename the classpath resource relative location * @return the json file contents * @throws IOException */ private String getJson(final String jsonFilename) throws IOException { final InputStream jsonStream = ClassLoader.getSystemResourceAsStream(jsonFilename); if (null == jsonStream) { fail(String.format("Unable to find response file %s", jsonFilename)); } final String jsonString = IOUtils.toString(jsonStream, "UTF-8"); // Check jsonStream null jsonStream.close(); return jsonString.isEmpty() ? "{}" : jsonString; }
From source file:com.mycompany.istudy.controller.pdf.PerformancePdfController.java
private String getFile(String fileName) throws Exception { InputStream in = ClassLoader.getSystemResourceAsStream(fileName); StringWriter writer = new StringWriter(); IOUtils.copy(in, writer, "utf-8"); return writer.toString(); }
From source file:org.kurento.test.client.BrowserClient.java
public InputStream getExtensionAsInputStream(String extension) { InputStream is = null;/* w w w . j av a 2 s .c o m*/ try { log.info("Trying to locate extension in the classpath ({}) ...", extension); is = ClassLoader.getSystemResourceAsStream(extension); if (is.available() < 0) { log.warn("Extension {} is not located in the classpath", extension); is = null; } else { log.info("Success. Loading extension {} from classpath", extension); } } catch (Throwable t) { log.warn("Exception reading extension {} in the classpath ({} : {})", extension, t.getClass(), t.getMessage()); is = null; } if (is == null) { try { log.info("Trying to locate extension as URL ({}) ...", extension); URL url = new URL(extension); is = url.openStream(); log.info("Success. Loading extension {} from URL", extension); } catch (Throwable t) { log.warn("Exception reading extension {} as URL ({} : {})", extension, t.getClass(), t.getMessage()); } } if (is == null) { throw new RuntimeException(extension + " is not a valid extension (it is not located in project" + " classpath neither is a valid URL)"); } return is; }
From source file:org.apache.ranger.plugin.util.RangerRESTClient.java
private InputStream getFileInputStream(String fileName) throws IOException { InputStream in = null;/*w w w .jav a 2s.c om*/ if (!StringUtil.isEmpty(fileName)) { File f = new File(fileName); if (f.exists()) { in = new FileInputStream(f); } else { in = ClassLoader.getSystemResourceAsStream(fileName); } } return in; }