List of usage examples for java.lang ClassLoader getSystemResourceAsStream
public static InputStream getSystemResourceAsStream(String name)
From source file:org.apache.tika.server.UnpackerResourceTest.java
@Test public void testExeDOCX() throws Exception { String TEST_DOCX_EXE = "2exe.docx"; Response response = WebClient.create(endPoint + UNPACKER_PATH).accept("application/zip") .put(ClassLoader.getSystemResourceAsStream(TEST_DOCX_EXE)); Map<String, String> data = readZipArchive((InputStream) response.getEntity()); assertEquals(DOCX_EXE1_MD5, data.get(DOCX_EXE1_NAME)); assertEquals(DOCX_EXE2_MD5, data.get(DOCX_EXE2_NAME)); }
From source file:org.apache.james.jmap.methods.integration.cucumber.GetMessagesMethodStepdefs.java
private void appendMessage(String emlFileName) throws Exception { ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z"); mainStepdefs.jmapServer.serverProbe().appendMessage(userStepdefs.lastConnectedUser, new MailboxPath(MailboxConstants.USER_NAMESPACE, userStepdefs.lastConnectedUser, "inbox"), ClassLoader.getSystemResourceAsStream(emlFileName), Date.from(dateTime.toInstant()), false, new Flags()); }
From source file:org.apache.tika.server.TikaResourceTest.java
@Test public void testPasswordXLSXML() throws Exception { Response response = WebClient.create(endPoint + TIKA_PATH).type("application/vnd.ms-excel") .accept("text/xml").put(ClassLoader.getSystemResourceAsStream("password.xls")); assertEquals(UNPROCESSEABLE, response.getStatus()); }
From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java
@Test public void pgpSignedEmailShouldBeWellConvertedToJson() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES); MailboxMessage pgpSignedMail = new SimpleMailboxMessage(MESSAGE_ID, date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/pgpSignedMail.eml"))), new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(), propertyBuilder, MAILBOX_ID); pgpSignedMail.setModSeq(MOD_SEQ);//w ww . j a va 2s . c om pgpSignedMail.setUid(UID); assertThatJson(messageToElasticSearchJson.convertToJson(pgpSignedMail, ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER) .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/pgpSignedMail.json"))); }
From source file:ste.cameracontrol.ui.CameraControlWindow.java
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed Photo photo = new Photo("demo"); try {// ww w . j a v a2 s . c om BufferedImage image = ImageIO.read(ClassLoader.getSystemResourceAsStream("images/about.png")); ByteArrayOutputStream out = new ByteArrayOutputStream(); ImageIO.write(image, "JPEG", out); photo.setJpegData(out.toByteArray()); photo.setRawData(new byte[] { 0 }); } catch (IOException e) { // // There is nothing we can do about it // e.printStackTrace(); } new ImageFrame(photo).setVisible(true); }
From source file:org.apache.tika.server.TikaResourceTest.java
@Test public void testSimpleWordMultipartXML() throws Exception { ClassLoader.getSystemResourceAsStream(TEST_DOC); Attachment attachmentPart = new Attachment("myworddoc", "application/msword", ClassLoader.getSystemResourceAsStream(TEST_DOC)); WebClient webClient = WebClient.create(endPoint + TIKA_PATH + "/form"); Response response = webClient.type("multipart/form-data").accept("text/xml").post(attachmentPart); String responseMsg = getStringFromInputStream((InputStream) response.getEntity()); assertTrue(responseMsg.contains("test")); assertContains("<meta name=\"X-TIKA:digest:MD5\" content=\"f8be45c34e8919eedba48cc8d207fbf0\"/>", responseMsg);/*from ww w .j ava 2s.c o m*/ }
From source file:com.amalto.commons.core.utils.xpath.JXPathContextFactory.java
/** * Private implementation method - will find the implementation * class in the specified order.//w w w.j av a 2 s. c o m * @param property Property name * @param defaultFactory Default implementation, if nothing else is found * * @return class name of the JXPathContextFactory */ private static String findFactory(String property, String defaultFactory) { // Use the factory ID system property first try { String systemProp = System.getProperty(property); if (systemProp != null) { if (debug) { System.err.println("JXPath: found system property" + systemProp); } return systemProp; } } catch (SecurityException se) { //NOPMD // Ignore } // try to read from $java.home/lib/xml.properties try { String javah = System.getProperty("java.home"); String configFile = javah + File.separator + "lib" + File.separator + "jxpath.properties"; File f = new File(configFile); if (f.exists()) { Properties props = new Properties(); FileInputStream fis = new FileInputStream(f); try { props.load(fis); } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { //NOPMD //swallow } } } String factory = props.getProperty(property); if (factory != null) { if (debug) { System.err.println("JXPath: found java.home property " + factory); } return factory; } } } catch (IOException ex) { if (debug) { ex.printStackTrace(); } } String serviceId = "META-INF/services/" + property; // try to find services in CLASSPATH try { ClassLoader cl = JXPathContextFactory.class.getClassLoader(); InputStream is = null; if (cl == null) { is = ClassLoader.getSystemResourceAsStream(serviceId); } else { is = cl.getResourceAsStream(serviceId); } if (is != null) { if (debug) { System.err.println("JXPath: found " + serviceId); } BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String factory = null; try { factory = rd.readLine(); } finally { try { rd.close(); } catch (IOException e) { //NOPMD //swallow } } if (factory != null && !"".equals(factory)) { if (debug) { System.err.println("JXPath: loaded from services: " + factory); } return factory; } } } catch (Exception ex) { if (debug) { ex.printStackTrace(); } } return defaultFactory; }
From source file:org.ebayopensource.turmeric.services.repository.listener.util.CommonUtil.java
public static Properties loadPropertyFile(String filePath) { Properties prop = new Properties(); InputStream in = ClassLoader.getSystemResourceAsStream(filePath); try {//w ww .j a va 2 s .c o m prop.load(in); } catch (IOException e) { e.printStackTrace(); } return prop; }
From source file:com.linkedin.thirdeye.hadoop.topk.TopkPhaseTest.java
@Before public void setUp() throws Exception { props.setProperty(ThirdEyeConfigProperties.THIRDEYE_TABLE_NAME.toString(), "collection"); props.setProperty(ThirdEyeConfigProperties.THIRDEYE_DIMENSION_NAMES.toString(), "d1,d2,d3"); props.setProperty(ThirdEyeConfigProperties.THIRDEYE_METRIC_NAMES.toString(), "m1,m2"); props.setProperty(ThirdEyeConfigProperties.THIRDEYE_METRIC_TYPES.toString(), "INT,INT"); props.setProperty(ThirdEyeConfigProperties.THIRDEYE_TIMECOLUMN_NAME.toString(), "hoursSinceEpoch"); props.setProperty(ThirdEyeConfigProperties.THIRDEYE_TOPK_DIMENSION_NAMES.toString(), "d2,"); props.setProperty(ThirdEyeConfigProperties.THIRDEYE_TOPK_METRICS.toString() + ".d2", "m1"); props.setProperty(ThirdEyeConfigProperties.THIRDEYE_TOPK_KVALUES.toString() + ".d2", "1"); props.setProperty(ThirdEyeConfigProperties.THIRDEYE_WHITELIST_DIMENSION_NAMES.toString(), "d3"); props.setProperty(ThirdEyeConfigProperties.THIRDEYE_WHITELIST_DIMENSION.toString() + ".d3", "xyz2"); thirdeyeConfig = ThirdEyeConfig.fromProperties(props); // Mapper config TopKPhaseMapper mapper = new TopKPhaseMapper(); mapDriver = MapDriver.newMapDriver(mapper); Configuration configuration = mapDriver.getConfiguration(); configuration.set("io.serializations", "org.apache.hadoop.io.serializer.JavaSerialization," + "org.apache.hadoop.io.serializer.WritableSerialization"); configuration.set(TopKPhaseConstants.TOPK_PHASE_THIRDEYE_CONFIG.toString(), OBJECT_MAPPER.writeValueAsString(thirdeyeConfig)); inputSchema = new Schema.Parser().parse(ClassLoader.getSystemResourceAsStream(AVRO_SCHEMA)); setUpAvroSerialization(mapDriver.getConfiguration(), inputSchema); // Reducer config TopKPhaseReducer reducer = new TopKPhaseReducer(); reduceDriver = ReduceDriver.newReduceDriver(reducer); configuration = reduceDriver.getConfiguration(); configuration.set("io.serializations", "org.apache.hadoop.io.serializer.JavaSerialization," + "org.apache.hadoop.io.serializer.WritableSerialization"); configuration.set(TopKPhaseConstants.TOPK_PHASE_THIRDEYE_CONFIG.toString(), OBJECT_MAPPER.writeValueAsString(thirdeyeConfig)); TemporaryPath tmpPath = new TemporaryPath(); outputPath = tmpPath.toString();/*from w ww. j a va2s. c om*/ configuration.set(TopKPhaseConstants.TOPK_PHASE_OUTPUT_PATH.toString(), outputPath); }
From source file:org.apache.tika.server.UnpackerResourceTest.java
@Test public void testImageXSL() throws Exception { Response response = WebClient.create(endPoint + UNPACKER_PATH).accept("application/zip") .put(ClassLoader.getSystemResourceAsStream("pic.xls")); Map<String, String> data = readZipArchive((InputStream) response.getEntity()); assertEquals(XSL_IMAGE1_MD5, data.get("0.jpg")); assertEquals(XSL_IMAGE2_MD5, data.get("1.jpg")); }