List of usage examples for java.lang ClassLoader getSystemResourceAsStream
public static InputStream getSystemResourceAsStream(String name)
From source file:net.sourceforge.mavenhippo.gen.BeanGeneratorTest.java
private ContentTypeBean getContentTypeBean(String fileName) { Node node = JAXB.unmarshal(ClassLoader.getSystemResourceAsStream(fileName), Node.class); @SuppressWarnings("unchecked") ContentTypeBean contentTypeBean = new ContentTypeBean(node, ((BidiMap) namespaces).inverseBidiMap()); return contentTypeBean; }
From source file:org.apache.tika.server.UnpackerResourceTest.java
@Test public void testTarDocPicture() throws Exception { Response response = WebClient.create(endPoint + UNPACKER_PATH).type(APPLICATION_MSWORD) .accept("application/x-tar").put(ClassLoader.getSystemResourceAsStream(TEST_DOC_WAV)); Map<String, String> data = readArchiveFromStream( new TarArchiveInputStream((InputStream) response.getEntity())); assertEquals(JPG_MD5, data.get(JPG_NAME)); }
From source file:com.linkedin.thirdeye.hadoop.derivedcolumn.transformation.DerivedColumnTransformationTest.java
@Before public void setUp() throws Exception { DerivedColumnTransformationPhaseMapper mapper = new DerivedColumnTransformationPhaseMapper(); mapDriver = MapDriver.newMapDriver(mapper); Configuration configuration = mapDriver.getConfiguration(); configuration.set("io.serializations", "org.apache.hadoop.io.serializer.JavaSerialization," + "org.apache.hadoop.io.serializer.WritableSerialization"); 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"); ThirdEyeConfig thirdeyeConfig = ThirdEyeConfig.fromProperties(props); configuration//from w w w. j a v a2 s . c om .set(DerivedColumnTransformationPhaseConstants.DERIVED_COLUMN_TRANSFORMATION_PHASE_THIRDEYE_CONFIG .toString(), OBJECT_MAPPER.writeValueAsString(thirdeyeConfig)); Schema inputSchema = new Schema.Parser().parse(ClassLoader.getSystemResourceAsStream(AVRO_SCHEMA)); setUpAvroSerialization(mapDriver.getConfiguration(), inputSchema); Schema outputSchema = new Schema.Parser() .parse(ClassLoader.getSystemResourceAsStream(TRANSFORMATION_SCHEMA)); configuration .set(DerivedColumnTransformationPhaseConstants.DERIVED_COLUMN_TRANSFORMATION_PHASE_OUTPUT_SCHEMA .toString(), outputSchema.toString()); configuration.set( DerivedColumnTransformationPhaseConstants.DERIVED_COLUMN_TRANSFORMATION_PHASE_TOPK_PATH.toString(), ClassLoader.getSystemResource(TOPK_PATH).toString()); TemporaryPath tmpPath = new TemporaryPath(); outputPath = tmpPath.toString(); configuration.set(DerivedColumnTransformationPhaseConstants.DERIVED_COLUMN_TRANSFORMATION_PHASE_OUTPUT_PATH .toString(), outputPath); }
From source file:org.apache.james.mailbox.elasticsearch.json.IndexableMessageTest.java
@Test public void textShouldContainsAllFieldsWhenAllSet() throws Exception { MailboxMessage mailboxMessage = mock(MailboxMessage.class); TestId mailboxId = TestId.of(1);/*from w w w . j av a 2s .co m*/ when(mailboxMessage.getMailboxId()).thenReturn(mailboxId); when(mailboxMessage.getFullContent()).thenReturn(new ByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/mailWithHeaders.eml")))); when(mailboxMessage.createFlags()).thenReturn(new Flags()); IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage, ImmutableList.of(new MockMailboxSession("username").getUser()), new DefaultTextExtractor(), ZoneId.of("Europe/Paris")); assertThat(indexableMessage.getText()).isEqualTo("Ad Min admin@opush.test " + "a@test a@test B b@test " + "c@test c@test " + "dD d@test " + "my subject " + "Mail content\n" + "\n" + "-- \n" + "Ad Min\n"); }
From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java
@Test public void simpleEmailShouldBeWellConvertedToJson() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES); MailboxMessage mail = new SimpleMailboxMessage(MESSAGE_ID, date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/mail.eml"))), new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(), propertyBuilder, MAILBOX_ID); mail.setModSeq(MOD_SEQ);//ww w . j a v a 2s .c om mail.setUid(UID); assertThatJson(messageToElasticSearchJson.convertToJson(mail, ImmutableList.of(new MockMailboxSession("user1").getUser(), new MockMailboxSession("user2").getUser()))).when(IGNORING_ARRAY_ORDER) .when(IGNORING_VALUES) .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/mail.json"))); }
From source file:org.java.plugin.ObjectFactory.java
private static String findProperty(final ClassLoader cl, final ExtendedProperties props) { Log log = LogFactory.getLog(ObjectFactory.class); String name = ObjectFactory.class.getName(); String result = System.getProperty(name); if (result != null) { log.debug("property " + name //$NON-NLS-1$ + " found as system property"); //$NON-NLS-1$ return result; }/* w w w . j a va2 s .c o m*/ if (props != null) { result = props.getProperty(name); if (result != null) { log.debug("property " + name //$NON-NLS-1$ + " found in properties file"); //$NON-NLS-1$ return result; } } String serviceId = "META-INF/services/" //$NON-NLS-1$ + ObjectFactory.class.getName(); InputStream strm; if (cl == null) { strm = ClassLoader.getSystemResourceAsStream(serviceId); } else { strm = cl.getResourceAsStream(serviceId); } if (strm != null) { try { BufferedReader reader = new BufferedReader(new InputStreamReader(strm, "UTF-8")); //$NON-NLS-1$ try { result = reader.readLine(); } finally { try { reader.close(); } catch (IOException ioe) { // ignore } } } catch (IOException ioe) { try { strm.close(); } catch (IOException ioe2) { // ignore } } } if (result != null) { log.debug("property " + name //$NON-NLS-1$ + " found as service"); //$NON-NLS-1$ return result; } log.debug("no property " + name //$NON-NLS-1$ + " found"); //$NON-NLS-1$ return result; }
From source file:WarUtil.java
/** * ?????????????????//from w ww . j a va 2 s . co m * * @param path * @param caller * @return */ public static InputStream getResourceAsStream(String path, Class<?> caller) { String resource = path; if (resource.startsWith(SLASH)) { resource = resource.substring(1); } InputStream is = null; File file = new File(path); if (file.exists() && file.isFile()) { try { is = new FileInputStream(file); } catch (FileNotFoundException e) { } } if (is == null) { ClassLoader tcl = Thread.currentThread().getContextClassLoader(); if (tcl != null) { is = tcl.getResourceAsStream(resource); } } if (is == null) { is = caller.getResourceAsStream(path); } if (is == null) { is = ClassLoader.class.getResourceAsStream(path); } if (is == null) { is = ClassLoader.getSystemResourceAsStream(resource); } return is; }
From source file:org.apache.tika.server.TikaResourceTest.java
@Test public void testEmbedded() throws Exception { //first try text Response response = WebClient.create(endPoint + TIKA_PATH).accept("text/plain") .put(ClassLoader.getSystemResourceAsStream(TEST_RECURSIVE_DOC)); String responseMsg = getStringFromInputStream((InputStream) response.getEntity()); assertTrue(responseMsg.contains("Course of human events")); //now go for xml -- different call than text response = WebClient.create(endPoint + TIKA_PATH).accept("text/xml") .put(ClassLoader.getSystemResourceAsStream(TEST_RECURSIVE_DOC)); responseMsg = getStringFromInputStream((InputStream) response.getEntity()); assertTrue(responseMsg.contains("Course of human events")); assertContains("<meta name=\"X-TIKA:digest:MD5\" content=\"59f626e09a8c16ab6dbc2800c685f772\"/>", responseMsg);//from w w w . j av a 2 s. c o m }
From source file:org.jahia.utils.i18n.JahiaTemplatesRBLoader.java
public InputStream getResourceAsStream(String name) { name = Patterns.TRIPPLE_UNDERSCORE.matcher(name).replaceAll("."); if (loader != null) { InputStream stream = loader.getResourceAsStream(name); if (stream != null) { return stream; } else {/*w w w. j a va2 s. com*/ String fileName = NAME_PATTERN.matcher(name).replaceAll(File.separator); if (aPackage != null) { String path = aPackage.getRootFolderPath() + (!fileName.startsWith("/") ? "/" : "") + fileName; path = JahiaContextLoaderListener.getServletContext().getResourceAsStream(path) != null ? path : null; if (path != null) { stream = JahiaContextLoaderListener.getServletContext().getResourceAsStream(path); } if (stream == null) { stream = JahiaContextLoaderListener.getServletContext().getResourceAsStream( (!name.startsWith("/") ? "/" : "") + NAME_PATTERN.matcher(name).replaceAll("/")); } if (stream == null) { String resourcePath = "resources/" + StringUtils.substringAfter(fileName, "/resources/"); try { stream = aPackage.getResource(resourcePath).getInputStream(); } catch (IOException e) { // } } if (stream != null) { return stream; } } try { if (SettingsBean.getInstance() != null) { File file = new File(SettingsBean.getInstance().getClassDiskPath(), fileName); if (file.exists()) { return new BufferedInputStream(new FileInputStream(file)); } } } catch (FileNotFoundException e) { logger.warn(e.getMessage(), e); } } } return ClassLoader.getSystemResourceAsStream(name); }
From source file:org.kuali.kfs.sys.batch.service.BatchInputServiceParseTest.java
/** * Verifies error message occurs on parse when an invalid xml format is given. *//*from ww w . ja v a 2 s . c o m*/ public final void DISABLED_testParse_missingRequiredField() throws Exception { InputStream fileContents = ClassLoader .getSystemResourceAsStream(TEST_BATCH_XML_DIRECTORY + "BatchInputMissingTagPCDO.xml"); byte[] missingTagPCDOFileContents = IOUtils.toByteArray(fileContents); boolean failedAsExpected = false; try { batchInputFileService.parse(pcdoBatchInputFileType, missingTagPCDOFileContents); } catch (ParseException e) { failedAsExpected = true; } assertTrue("parse exception not thrown for xml missing a required field", failedAsExpected); }