List of usage examples for java.lang ClassLoader getSystemResourceAsStream
public static InputStream getSystemResourceAsStream(String name)
From source file:com.hotelbeds.distribution.hotel_api_sdk.HotelApiClient.java
private String getHotelApiProperty(String propertyName) { if (properties == null) { try (InputStream hotelApiPropertiesIS = ClassLoader .getSystemResourceAsStream(HOTELAPI_PROPERTIES_FILE_NAME)) { properties = new Properties(); if (hotelApiPropertiesIS != null) { properties.load(hotelApiPropertiesIS); }// w ww .j a v a2s . com } catch (IOException e) { log.error("Error loading properties (){}.", HOTELAPI_PROPERTIES_FILE_NAME, e); } } return properties.getProperty(propertyName); }
From source file:org.wso2.carbon.utils.i18n.ResourceBundle.java
protected Properties loadProperties(String resname, ClassLoader loader) { Properties props = null;/*from w ww .ja va 2s.c om*/ // Attempt to open and load the properties InputStream in = null; try { if (loader != null) { in = loader.getResourceAsStream(resname); } // Either we're using the system class loader or we didn't find the // resource using the given class loader if (in == null) { in = ClassLoader.getSystemResourceAsStream(resname); } if (in != null) { props = new Properties(); try { props.load(in); } catch (IOException ex) { // On error, clear the props props = null; } } } finally { if (in != null) { try { in.close(); } catch (Exception ex) { // Ignore error on close if (log.isDebugEnabled()) { log.debug("Error closing input stream", ex); } } } } return props; }
From source file:org.apache.james.jmap.methods.integration.GetMessageListMethodTest.java
@Test public void getMessageListSetDraftFilterShouldWork() 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 ww.j a v a2 s.c om*/ given().header("Authorization", accessToken.serialize()) .body("[[\"getMessageList\", {\"filter\":{\"isDraft\":\"true\"}}, \"#0\"]]").when().post("/jmap") .then().statusCode(200).body(NAME, equalTo("messageList")) .body(ARGUMENTS + ".messageIds", allOf(containsInAnyOrder(messageDraft.getMessageId().serialize()), not(containsInAnyOrder(messageNotDraft.getMessageId().serialize())))); }
From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java
@Test public void emailWithAttachmentsShouldNotConvertAttachmentsWhenIndexAttachmentsIsFalse() throws IOException { // Given//from w w w . j a v a 2 s . co m MailboxMessage mailWithNoInternalDate = new SimpleMailboxMessage(MESSAGE_ID, null, 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, MAILBOX_ID); mailWithNoInternalDate.setModSeq(MOD_SEQ); mailWithNoInternalDate.setUid(UID); // When MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.NO); String convertToJson = messageToElasticSearchJson.convertToJson(mailWithNoInternalDate, ImmutableList.of(new MockMailboxSession("username").getUser())); // Then assertThatJson(convertToJson).when(IGNORING_ARRAY_ORDER).when(IGNORING_VALUES).isEqualTo( IOUtils.toString(ClassLoader.getSystemResource("eml/recursiveMailWithoutAttachments.json"))); }
From source file:org.phenotips.ontology.internal.GeneNomenclatureTest.java
@Test public void getSizeFetchesFromRemoteServer() 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")); long result = this.mocker.getComponentUnderTest().size(); Assert.assertEquals(expectedURI, reqCapture.getLastValue().getURI()); Assert.assertEquals("application/json", reqCapture.getLastValue().getLastHeader("Accept").getValue()); Assert.assertEquals(40045, result);//from w w w .j a v a 2s . c om }
From source file:phex.gui.dialogs.ExportDialog.java
private void startExport() { String outFileName = outputFileTF.getText(); File file = new File(outFileName); InputStream inStream = null;/* w w w .j av a 2s . c o m*/ OutputStream outStream = null; try { outStream = new BufferedOutputStream(new FileOutputStream(file)); if (standardExport.isSelected()) { int idx = standardExportFormatCB.getSelectedIndex(); switch (idx) { case DEFAULT_HTML_INDEX: inStream = ClassLoader .getSystemResourceAsStream("phex/resources/defaultSharedFilesHTMLExport.xsl"); break; case DEFAULT_MAGMA_YAML_INDEX: inStream = ClassLoader .getSystemResourceAsStream("phex/resources/magmaSharedFilesYAMLExport.xsl"); break; case DEFAULT_METALINK_XML_INDEX: inStream = ClassLoader .getSystemResourceAsStream("phex/resources/metalinkSharedFilesXMLExport.xsl"); break; case DEFAULT_RSS_XML_INDEX: inStream = ClassLoader.getSystemResourceAsStream("phex/resources/rssSharedFilesXMLExport.xsl"); break; } } else if (customExport.isSelected()) { String styleFileName = customExportFormatTF.getText(); File styleFile = new File(styleFileName); inStream = new BufferedInputStream(new FileInputStream(styleFile)); } else { return; } Map<String, String> exportOptions = new HashMap<String, String>(); if (magnetInclXs.isSelected()) { exportOptions.put(ExportEngine.USE_MAGNET_URL_WITH_XS, "true"); } if (magnetInclFreebase.isSelected()) { exportOptions.put(ExportEngine.USE_MAGNET_URL_WITH_FREEBASE, "true"); } List<ShareFile> exportData; if (exportAllFiles.isSelected()) { SharedFilesService sharedFilesService = GUIRegistry.getInstance().getServent() .getSharedFilesService(); exportData = sharedFilesService.getSharedFiles(); } else { exportData = shareFileList; } ExportEngine exportEngine = new ExportEngine(GUIRegistry.getInstance().getServent().getLocalAddress(), inStream, outStream, exportData, exportOptions); exportEngine.startExport(); } catch (IOException exp) { NLogger.error(ExportDialog.class, exp, exp); } finally { IOUtil.closeQuietly(inStream); IOUtil.closeQuietly(outStream); } }
From source file:ch.sdi.core.impl.ftp.FtpExecutorTest.java
/** * @param aTargetDir//w ww .j av a 2 s . com * @return */ private Map<String, InputStream> createFileUploadMap(String aTargetDir) { Map<String, InputStream> filesToUpload = new TreeMap<String, InputStream>(); filesToUpload.put(aTargetDir + "sdimain_test.properties", ClassLoader.getSystemResourceAsStream("sdimain.properties")); filesToUpload.put(aTargetDir + "log4j2.xml", ClassLoader.getSystemResourceAsStream("log4j2.xml")); return filesToUpload; }
From source file:de.tu.darmstadt.lt.ner.preprocessing.GermaNERMain.java
private static void setModelDir() throws IOException, FileNotFoundException { modelDirectory = (Configuration.modelDir == null || Configuration.modelDir.isEmpty()) ? new File("output") : new File(Configuration.modelDir); modelDirectory.mkdirs();/*ww w. j a v a 2s .c om*/ if (!new File(modelDirectory, "model.jar").exists()) { IOUtils.copyLarge(ClassLoader.getSystemResourceAsStream("model/model.jar"), new FileOutputStream(new File(modelDirectory, "model.jar"))); } if (!new File(modelDirectory, "MANIFEST.MF").exists()) { IOUtils.copyLarge(ClassLoader.getSystemResourceAsStream("model/MANIFEST.MF"), new FileOutputStream(new File(modelDirectory, "MANIFEST.MF"))); } if (!new File(modelDirectory, "feature.xml").exists()) { IOUtils.copyLarge(ClassLoader.getSystemResourceAsStream("feature/feature.xml"), new FileOutputStream(new File(modelDirectory, "feature.xml"))); } }
From source file:org.apache.tika.server.TikaResourceTest.java
@Test public void testExtractTextAcceptPlainText() throws Exception { //TIKA-2384//from w ww. jav a 2 s . co m Attachment attachmentPart = new Attachment("my-docx-file", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", ClassLoader.getSystemResourceAsStream("2pic.docx")); Response response = WebClient.create(endPoint + TIKA_PATH + "/form").type("multipart/form-data") .accept("text/plain").post(attachmentPart); String responseMsg = getStringFromInputStream((InputStream) response.getEntity()); assertTrue(responseMsg.contains("P1040893.JPG")); assertNotFound(STREAM_CLOSED_FAULT, responseMsg); }
From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java
@Test public void spamEmailShouldBeWellConvertedToJsonWithApacheTika() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new TikaTextExtractor(), ZoneId.of("Europe/Paris")); MailboxMessage spamMail = new SimpleMailboxMessage(date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/nonTextual.eml"))), new Flags(), propertyBuilder, MAILBOX_ID); spamMail.setModSeq(MOD_SEQ);/*w w w. j a va2 s . c o m*/ assertThatJson(messageToElasticSearchJson.convertToJson(spamMail, ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER) .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/nonTextual.json"), CHARSET)); }