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.cucumber.DownloadStepdefs.java

@Given("^\"([^\"]*)\" mailbox \"([^\"]*)\" contains a message \"([^\"]*)\" with an inlined attachment \"([^\"]*)\"$")
public void appendMessageWithInlinedAttachmentToMailbox(String user, String mailbox, String messageId,
        String attachmentId) throws Throwable {
    MailboxPath mailboxPath = new MailboxPath(MailboxConstants.USER_NAMESPACE, user, mailbox);

    mainStepdefs.jmapServer.serverProbe().appendMessage(user, mailboxPath,
            ClassLoader.getSystemResourceAsStream("eml/oneInlinedImage.eml"), new Date(), false, new Flags());

    attachmentsByMessageId.put(messageId, attachmentId);
    // TODO//from w  w w . j a  v a 2 s. co  m
    //blobIdByAttachmentId.put(attachmentId, "<correctComputedBlobId>");
}

From source file:org.apache.ranger.audit.utils.InMemoryJAASConfiguration.java

public static void init(String propFile) throws Exception {
    LOG.debug("==> InMemoryJAASConfiguration.init( {} ) ", propFile);

    InputStream in = null;/*from  w  w  w.  ja  v a2  s .co m*/

    try {
        Properties properties = new Properties();
        in = ClassLoader.getSystemResourceAsStream(propFile);
        if (in == null) {
            if (!propFile.startsWith("/")) {
                in = ClassLoader.getSystemResourceAsStream("/" + propFile);
            }
            if (in == null) {
                in = new FileInputStream(new File(propFile));
            }
        }
        properties.load(in);
        init(properties);
    } catch (IOException e) {
        throw new Exception("Failed to load JAAS application properties", e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (Exception e) {
                //Ignore
            }
        }
    }
    LOG.debug("<== InMemoryJAASConfiguration.init( {} ) ", propFile);
}

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

private List<GenericRecord> generateTestData() throws Exception {
    Schema schema = new Schema.Parser().parse(ClassLoader.getSystemResourceAsStream(AVRO_SCHEMA));
    List<GenericRecord> inputRecords = new ArrayList<GenericRecord>();

    GenericRecord input = new GenericData.Record(schema);
    input.put("d1", "abc1");
    input.put("d2", "pqr1");
    input.put("d3", "xyz1");
    input.put("hoursSinceEpoch", generateRandomHoursSinceEpoch());
    input.put("m1", 10);
    input.put("m2", 20);
    inputRecords.add(input);/*from w  ww  .ja  v  a 2 s. co m*/

    input = new GenericData.Record(schema);
    input.put("d1", "abc2");
    input.put("d2", "pqr2");
    input.put("d3", "xyz2");
    input.put("hoursSinceEpoch", generateRandomHoursSinceEpoch());
    input.put("m1", 10);
    input.put("m2", 20);
    inputRecords.add(input);

    return inputRecords;
}

From source file:org.apache.tika.server.TikaResourceTest.java

@Test
public void testSimpleWordHTML() throws Exception {
    Response response = WebClient.create(endPoint + TIKA_PATH).type("application/msword").accept("text/html")
            .put(ClassLoader.getSystemResourceAsStream(TEST_DOC));
    String responseMsg = getStringFromInputStream((InputStream) response.getEntity());
    assertTrue(responseMsg.contains("test"));
    assertContains("<meta name=\"X-TIKA:digest:MD5\" content=\"f8be45c34e8919eedba48cc8d207fbf0\"/>",
            responseMsg);/*from w w w.  j  ava2  s.  c  om*/
    assertContains("<meta name=\"X-TIKA:digest:SHA1\" content=\"N4EBCE7EGTIGZWETEJ6WD3W4KN32TLPG\"/>",
            responseMsg);
}

From source file:org.apache.atlas.security.InMemoryJAASConfiguration.java

public static void init(String propFile) throws AtlasException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> InMemoryJAASConfiguration.init({})", propFile);
    }/*w  w w . j  a v  a2  s  . c o m*/

    InputStream in = null;

    try {
        Properties properties = new Properties();
        in = ClassLoader.getSystemResourceAsStream(propFile);
        if (in == null) {
            if (!propFile.startsWith("/")) {
                in = ClassLoader.getSystemResourceAsStream("/" + propFile);
            }
            if (in == null) {
                in = new FileInputStream(new File(propFile));
            }
        }
        properties.load(in);
        init(properties);
    } catch (IOException e) {
        throw new AtlasException("Failed to load JAAS application properties", e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (Exception exception) {
                // Ignore
            }
        }
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== InMemoryJAASConfiguration.init({})", propFile);
    }
}

From source file:net.sourceforge.mavenhippo.gen.BeanGeneratorTest.java

private void compareFiles(String pathToExpectedFile, File generatedFile)
        throws FileNotFoundException, IOException {
    BufferedReader generated = new BufferedReader(new FileReader(generatedFile));
    BufferedReader expected = new BufferedReader(
            new InputStreamReader(ClassLoader.getSystemResourceAsStream(pathToExpectedFile)));
    String line;//  w  w w  .  ja  v a 2s . com
    do {
        line = expected.readLine();
        Assert.assertEquals(line, generated.readLine());
    } while (line != null);

    generated.close();
}

From source file:org.apache.ranger.tagsync.process.TagSyncConfig.java

public static InputStream getFileInputStream(String path) throws FileNotFoundException {

    InputStream ret = null;/* w  w  w . java  2  s  .  c  o  m*/

    File f = new File(path);

    if (f.exists() && f.isFile() && f.canRead()) {
        ret = new FileInputStream(f);
    } else {
        ret = TagSyncConfig.class.getResourceAsStream(path);

        if (ret == null) {
            if (!path.startsWith("/")) {
                ret = TagSyncConfig.class.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.interreg.docexplore.DocExploreTool.java

private static void readVersion() throws Exception {
    InputStream in = ClassLoader.getSystemResourceAsStream("version.xml");
    String xml = StringUtils.readStream(in);
    in.close();/*  w  w  w .ja v  a2 s.c om*/
    version = StringUtils.getTagContent(xml, "major").trim() + "."
            + StringUtils.getTagContent(xml, "minor").trim() + "."
            + StringUtils.getTagContent(xml, "build").trim();
}

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

@Test
public void cryptedMessageShouldBeDecryptedWhenCertificateMatches() 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/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("Crypted content");
    }/*from   w w w  .  j  a v  a2s.co m*/
}

From source file:net.gazeplay.commons.utils.games.Utils.java

public static boolean copyFromJar(String filePath, String destinationPath) {
    InputStream sourceFile = null;
    OutputStream destinationFile = null;
    try {/*from ww w.j a  va2 s. c om*/
        sourceFile = ClassLoader.getSystemResourceAsStream(filePath);
        if (sourceFile == null) {
            throw new IOException("Resource not found " + filePath);
        }
        destinationFile = new FileOutputStream(destinationPath);
        org.apache.commons.io.IOUtils.copy(sourceFile, destinationFile);
    } catch (IOException e) {
        log.error("Exception", e);
        return false; // Erreur
    } finally {
        IOUtils.closeQuietly(destinationFile);
        IOUtils.closeQuietly(sourceFile);
    }
    return true; // Rsultat OK
}