Example usage for java.lang ClassLoader getSystemResourceAsStream

List of usage examples for java.lang ClassLoader getSystemResourceAsStream

Introduction

In this page you can find the example usage for java.lang ClassLoader getSystemResourceAsStream.

Prototype

public static InputStream getSystemResourceAsStream(String name) 

Source Link

Document

Open for reading, a resource of the specified name from the search path used to load classes.

Usage

From source file:org.apache.james.jmap.methods.integration.GetMessageListMethodTest.java

@Test
public void getMessageListSetFlaggedFilterShouldWork() throws Exception {
    mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");

    ComposedMessageId messageNotFlagged = 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 messageFlagged = mailboxProbe.appendMessage(username,
            new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
            ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"), new Date(), false,
            new Flags(Flags.Flag.FLAGGED));

    await();/*from w ww  .j av a2  s .c  o m*/

    given().header("Authorization", accessToken.serialize())
            .body("[[\"getMessageList\", {\"filter\":{\"isFlagged\":\"true\"}}, \"#0\"]]").when().post("/jmap")
            .then().statusCode(200).body(NAME, equalTo("messageList")).body(ARGUMENTS + ".messageIds",
                    allOf(containsInAnyOrder(messageFlagged.getMessageId().serialize()),
                            not(containsInAnyOrder(messageNotFlagged.getMessageId().serialize()))));
}

From source file:com.linkedin.thirdeye.hadoop.aggregation.AggregationPhaseTest.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_INPUT_TIMECOLUMN_SIZE.toString(), "1");
    props.setProperty(ThirdEyeConfigProperties.THIRDEYE_INPUT_TIMECOLUMN_TYPE.toString(),
            TimeUnit.HOURS.toString());
    props.setProperty(ThirdEyeConfigProperties.THIRDEYE_INPUT_TIMECOLUMN_SIZE.toString(), "1");
    props.setProperty(ThirdEyeConfigProperties.THIRDEYE_INPUT_TIMECOLUMN_TYPE.toString(),
            TimeUnit.MILLISECONDS.toString());
    thirdeyeConfig = ThirdEyeConfig.fromProperties(props);

    // Mapper config
    AggregationMapper mapper = new AggregationMapper();
    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(AggregationPhaseConstants.AGG_PHASE_THIRDEYE_CONFIG.toString(),
            OBJECT_MAPPER.writeValueAsString(thirdeyeConfig));

    inputSchema = new Schema.Parser().parse(ClassLoader.getSystemResourceAsStream(AVRO_SCHEMA));
    setUpAvroSerialization(mapDriver.getConfiguration(), inputSchema);

    // Reducer config
    AggregationReducer reducer = new AggregationReducer();
    reduceDriver = ReduceDriver.newReduceDriver(reducer);
    configuration = reduceDriver.getConfiguration();
    configuration.set("io.serializations", "org.apache.hadoop.io.serializer.JavaSerialization,"
            + "org.apache.hadoop.io.serializer.WritableSerialization");

    Schema avroSchema = new Schema.Parser().parse(ClassLoader.getSystemResourceAsStream(AVRO_SCHEMA));
    configuration.set(AggregationPhaseConstants.AGG_PHASE_AVRO_SCHEMA.toString(), avroSchema.toString());

    configuration.set(AggregationPhaseConstants.AGG_PHASE_THIRDEYE_CONFIG.toString(),
            OBJECT_MAPPER.writeValueAsString(thirdeyeConfig));

    TemporaryPath tmpPath = new TemporaryPath();
    outputPath = tmpPath.toString();/*from w ww .  j a  v a2 s.c om*/
    configuration.set(AggregationPhaseConstants.AGG_PHASE_OUTPUT_PATH.toString(), outputPath);
    setUpAvroSerialization(reduceDriver.getConfiguration(), inputSchema);

}

From source file:org.apache.ranger.ldapconfigcheck.LdapConfig.java

private InputStream getFileInputStream(String path) throws FileNotFoundException {

    InputStream ret = null;//  w w  w.  jav a  2 s  .co  m

    File f = new File(path);

    if (f.exists()) {
        ret = new FileInputStream(f);
    } else {
        ret = getClass().getResourceAsStream(path);

        if (ret == null) {
            if (!path.startsWith("/")) {
                ret = getClass().getResourceAsStream("/" + path);
            }
        }

        if (ret == null) {
            ret = ClassLoader.getSystemClassLoader().getResourceAsStream(path);
            if (ret == null) {
                if (!path.startsWith("/")) {
                    ret = ClassLoader.getSystemResourceAsStream("/" + path);
                }
            }
        }
    }

    return ret;
}

From source file:org.kuali.kfs.sys.batch.service.BatchInputServiceParseTest.java

/**
 * Verifies error message occurs on parse when an invalid xml format is given.
 *//*  w  w  w.j  a va2 s  .  co  m*/
public final void DISABLED_testParse_invalidTagOrder() throws Exception {
    InputStream fileContents = ClassLoader
            .getSystemResourceAsStream(TEST_BATCH_XML_DIRECTORY + "BatchInputInvalidTagOrderPCDO.xml");
    byte[] invalidTagOrderPCDOFileContents = IOUtils.toByteArray(fileContents);

    boolean failedAsExpected = false;
    try {
        batchInputFileService.parse(pcdoBatchInputFileType, invalidTagOrderPCDOFileContents);
    } catch (ParseException e) {
        failedAsExpected = true;
    }

    assertTrue("parse exception not thrown for xml with invalid tag order", failedAsExpected);
}

From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java

@Test
public void simpleEmailShouldBeWellConvertedToJson() throws IOException {
    MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
            new DefaultTextExtractor(), ZoneId.of("Europe/Paris"));
    MailboxMessage mail = new SimpleMailboxMessage(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);/*from  w w  w .j  av  a  2 s.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.apache.hadoop.gateway.GatewayServer.java

private static void extractToFile(String resource, File file) throws IOException {
    InputStream input = ClassLoader.getSystemResourceAsStream(resource);
    OutputStream output = new FileOutputStream(file);
    IOUtils.copy(input, output);//from w w w.  jav  a 2s  .  c o  m
    output.close();
    input.close();
}

From source file:org.apache.james.mailets.crypto.SMIMEDecryptIntegrationTest.java

@Test
public void cryptedMessageShouldNotBeDecryptedWhenCertificateDoesntMatch() throws Exception {

    try (SMTPMessageSender messageSender = SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_SECURE_PORT,
            DEFAULT_DOMAIN, FROM, PASSWORD);
            IMAPMessageReader imapMessageReader = new IMAPMessageReader(LOCALHOST_IP, IMAP_PORT)) {
        messageSender.sendMessageWithHeaders(FROM, FROM,
                IOUtils.toString(ClassLoader.getSystemResourceAsStream("eml/bad_crypted.eml")));
        calmlyAwait.atMost(Duration.ONE_MINUTE).until(messageSender::messageHasBeenSent);
        calmlyAwait.atMost(Duration.ONE_MINUTE)
                .until(() -> imapMessageReader.userReceivedMessage(FROM, PASSWORD));

        assertThat(imapMessageReader.readFirstMessageInInbox(FROM, PASSWORD))
                .containsSequence("MIAGCSqGSIb3DQEHA6CAMIACAQAxggKpMIICpQIBADCBjDCBhjELMAkGA1UE");
    }/* ww w.j av  a 2 s . co m*/
}

From source file:SecuritySupport.java

InputStream getResourceAsStream(final ClassLoader cl, final String name) {
    return (InputStream) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            InputStream ris;/*  ww  w .  j a  v a  2s .com*/
            if (cl == null) {
                ris = ClassLoader.getSystemResourceAsStream(name);
            } else {
                ris = cl.getResourceAsStream(name);
            }
            return ris;
        }
    });
}

From source file:org.apache.rya.sail.config.RyaAccumuloSailFactoryTest.java

@Test
public void testParseTemplate() throws Exception {
    String template = IOUtils.toString(
            ClassLoader.getSystemResourceAsStream("org/openrdf/repository/config/RyaAccumuloSail.ttl"));
    ConfigTemplate ct = new ConfigTemplate(template);
    System.out.println(ct.getVariableMap());
}

From source file:com.linkedin.thirdeye.hadoop.derivedcolumn.transformation.DerivedColumnNoTransformationTest.java

@Before
public void setUp() throws Exception {
    DerivedColumnNoTransformationPhaseMapper mapper = new DerivedColumnNoTransformationPhaseMapper();
    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");

    ThirdEyeConfig thirdeyeConfig = ThirdEyeConfig.fromProperties(props);
    configuration/* w  w w  .ja va 2 s  .c  o  m*/
            .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(NO_TRANSFORMATION_SCHEMA));
    configuration
            .set(DerivedColumnTransformationPhaseConstants.DERIVED_COLUMN_TRANSFORMATION_PHASE_OUTPUT_SCHEMA
                    .toString(), outputSchema.toString());

    configuration.set(
            DerivedColumnTransformationPhaseConstants.DERIVED_COLUMN_TRANSFORMATION_PHASE_TOPK_PATH.toString(),
            TOPK_PATH);

    TemporaryPath tmpPath = new TemporaryPath();
    outputPath = tmpPath.toString();
    configuration.set(DerivedColumnTransformationPhaseConstants.DERIVED_COLUMN_TRANSFORMATION_PHASE_OUTPUT_PATH
            .toString(), outputPath);
}