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.phenotips.vocabulary.internal.GeneNomenclatureTest.java

@Test
public void invalidResponseReturnsEmptySearch()
        throws ComponentLookupException, ClientProtocolException, IOException {
    when(this.client.execute(any(HttpUriRequest.class))).thenReturn(this.response);
    when(this.response.getEntity()).thenReturn(this.responseEntity);
    when(this.responseEntity.getContent()).thenReturn(ClassLoader.getSystemResourceAsStream(""));
    Map<String, Object> search = new LinkedHashMap<>();
    search.put("status", "Approved");
    Map<String, String> queryOptions = new LinkedHashMap<>();

    queryOptions.put("start", "three");
    queryOptions.put("rows", "");
    Assert.assertTrue(this.mocker.getComponentUnderTest().search(search, queryOptions).isEmpty());
}

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

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

    ComposedMessageId messageNotSeenNotFlagged = 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 messageNotSeenFlagged = mailboxProbe.appendMessage(username,
            new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
            ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"), new Date(), false,
            new Flags(Flags.Flag.FLAGGED));
    ComposedMessageId messageSeenNotFlagged = mailboxProbe.appendMessage(username,
            new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
            ClassLoader.getSystemResourceAsStream("eml/oneInlinedImage.eml"), new Date(), false,
            new Flags(Flags.Flag.SEEN));
    ComposedMessageId messageSeenFlagged = mailboxProbe.appendMessage(username,
            new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
            ClassLoader.getSystemResourceAsStream("eml/oneInlinedImage.eml"), new Date(), false,
            FlagsBuilder.builder().add(Flags.Flag.SEEN, Flags.Flag.FLAGGED).build());

    await();//from w w  w .j  a  va  2s. c o m

    given().header("Authorization", accessToken.serialize())
            .body("[[\"getMessageList\", {\"filter\":{\"operator\":\"OR\",\"conditions\":["
                    + "{\"operator\":\"AND\", \"conditions\":[{\"isFlagged\":\"true\"},{\"isUnread\":\"true\"}]},"
                    + "{\"operator\":\"AND\", \"conditions\":[{\"isFlagged\":\"true\"},{\"isUnread\":\"false\"}]}"
                    + "]}}, \"#0\"]]")
            .when().post("/jmap").then().statusCode(200).body(NAME, equalTo("messageList"))
            .body(ARGUMENTS + ".messageIds",
                    allOf(containsInAnyOrder(messageSeenFlagged.getMessageId().serialize(),
                            messageNotSeenFlagged.getMessageId().serialize()),
                            not(containsInAnyOrder(messageNotSeenNotFlagged.getMessageId().serialize(),
                                    messageSeenNotFlagged.getMessageId().serialize()))));
}

From source file:org.eclipse.swt.snippets.SnippetExplorer.java

/**
 * Get the preview image for the Snippet.
 *
 * @param snippet Snippet's metadata to load preview image for
 * @return the preview image or <code>null</code> if none available
 * @throws IOException if image loading failed
 *///from w  w w.ja v a2  s.  c  o  m
private Image getPreviewImage(Snippet snippet) throws IOException {
    final Path previewFile = Paths.get("previews", snippet.snippetName + ".png");
    if (Files.exists(previewFile)) {
        try (InputStream imageStream = Files.newInputStream(previewFile)) {
            return new Image(display, imageStream);
        }
    }
    try (InputStream imageStream = SnippetExplorer.class
            .getResourceAsStream("/previews/" + snippet.snippetName + ".png")) {
        if (imageStream != null) {
            return new Image(display, imageStream);
        }
    }
    try (InputStream imageStream = ClassLoader
            .getSystemResourceAsStream("previews/" + snippet.snippetName + ".png")) {
        if (imageStream != null) {
            return new Image(display, imageStream);
        }
    }
    return null;
}

From source file:org.phenotips.vocabulary.internal.GeneNomenclatureTest.java

@Test
public void invalidOrEmptyResponseReturnsNoInfo()
        throws ComponentLookupException, ClientProtocolException, IOException {
    when(this.client.execute(any(HttpUriRequest.class))).thenReturn(this.response);
    when(this.response.getEntity()).thenReturn(this.responseEntity);
    when(this.responseEntity.getContent()).thenReturn(ClassLoader.getSystemResourceAsStream(""));
    Assert.assertEquals("", this.mocker.getComponentUnderTest().getVersion());
}

From source file:oracle.kv.hadoop.hive.table.TableSerDeBase.java

private String createLocalKVSecurity(final String loginFlnm, final String trustFlnm) throws SerDeException {

    if (loginFlnm == null) {
        return null;
    }//www.  j  a  v a2s.co  m

    if (trustFlnm == null) {
        return null;
    }

    String localLoginFile = loginFlnm;
    String localTrustFile = trustFlnm;

    final File localLoginFileFd = new File(localLoginFile);
    final File localTrustFileFd = new File(localTrustFile);

    if (!localLoginFileFd.exists() || !localTrustFileFd.exists()) {

        final ClassLoader cl = TableSerDeBase.class.getClassLoader();
        final File userSecurityDirFd = new File(USER_SECURITY_DIR);
        if (!userSecurityDirFd.exists()) {
            if (!userSecurityDirFd.mkdirs()) {
                throw new SerDeException(new IOException("failed to create " + userSecurityDirFd));
            }
        }

        try {
            if (!localTrustFileFd.exists()) {
                if (localTrustFileFd.isAbsolute()) {
                    localTrustFile = localTrustFileFd.getName();
                }
                InputStream trustStream = null;
                if (cl != null) {
                    trustStream = cl.getResourceAsStream(localTrustFile);
                } else {
                    trustStream = ClassLoader.getSystemResourceAsStream(localTrustFile);
                }

                final File trustFd = new File(USER_SECURITY_DIR + FILE_SEP + localTrustFile);
                final FileOutputStream trustFlnmFos = new FileOutputStream(trustFd);

                if (trustStream != null) {
                    int nextByte = trustStream.read();
                    while (nextByte != -1) {
                        trustFlnmFos.write(nextByte);
                        nextByte = trustStream.read();
                    }
                }
                trustFlnmFos.close();
            }

            if (!localLoginFileFd.exists()) {
                String loginFileNoPath = localLoginFile;
                if (localLoginFileFd.isAbsolute()) {
                    loginFileNoPath = localLoginFileFd.getName();
                }
                InputStream loginStream = null;
                if (cl != null) {
                    loginStream = cl.getResourceAsStream(loginFileNoPath);
                } else {
                    loginStream = ClassLoader.getSystemResourceAsStream(loginFileNoPath);
                }
                final Properties loginProps = new Properties();
                if (loginStream != null) {
                    loginProps.load(loginStream);
                }

                final String trustFlnmFromLogin = loginProps
                        .getProperty(KVSecurityConstants.SSL_TRUSTSTORE_FILE_PROPERTY);
                if (trustFlnmFromLogin != null && !trustFlnmFromLogin.equals(localTrustFile)) {

                    /* Replace <path>/trustFlnm with existing trustFlnm. */
                    loginProps.setProperty(KVSecurityConstants.SSL_TRUSTSTORE_FILE_PROPERTY, localTrustFile);
                }
                localLoginFile = USER_SECURITY_DIR + FILE_SEP + loginFileNoPath;
                final File loginFd = new File(localLoginFile);
                final FileOutputStream loginFos = new FileOutputStream(loginFd);
                loginProps.store(loginFos, null);
                loginFos.close();
            }
        } catch (IOException e) {
            throw new SerDeException(e);
        }
    }
    return localLoginFile;
}

From source file:com.github.venkateshamurthy.designpatterns.builders.FluentBuilders.java

/**
 * This method checks for class names listing from either the
 * {@value #FILE_LISTING_OPTION} option or from the option
 * {@value #CLASS_NAMES_OPTION}//from  w  w w.  j av a2 s  .c o  m
 * 
 * @param cmdLine
 * @return Class names as CSV
 * @throws IOException
 */
private static String getClassNamesAsCSV(final CommandLine cmdLine) throws IOException {
    String classNamesCSV = null;
    if (FILE_LISTING.selected(cmdLine)) {
        try (final BufferedReader reader = new BufferedReader(
                new InputStreamReader(ClassLoader.getSystemResourceAsStream(FILE_LISTING.option(cmdLine))))) {
            final StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line).append(",");
            }
            classNamesCSV = sb.toString();
        }
    } else if (CLASS_NAMES.selected(cmdLine)) {
        classNamesCSV = CLASS_NAMES.option(cmdLine);
    }
    return classNamesCSV;
}

From source file:org.apromore.service.impl.CanoniserServiceImplIntgTest.java

private CanonisedProcess canoniseYAWLModel(String yawlFile, String yawlOrgFile)
        throws CanoniserException, IOException {
    CanonisedProcess oFCanonised;/*www.  ja v  a2  s  .  c o m*/
    try (InputStream oFProcess = ClassLoader.getSystemResourceAsStream(yawlFile)) {
        if (yawlOrgFile != null) {
            try (InputStream oFProcessOrgData = ClassLoader.getSystemResourceAsStream(yawlOrgFile)) {

                HashSet<RequestParameterType<?>> yawlParameters = new HashSet<>();
                yawlParameters.add(new RequestParameterType<>("readOrgData", oFProcessOrgData));
                oFCanonised = cSrv.canonise("YAWL 2.2", oFProcess, yawlParameters);

            }
        } else {
            HashSet<RequestParameterType<?>> yawlParameters = new HashSet<>();
            oFCanonised = cSrv.canonise("YAWL 2.2", oFProcess, yawlParameters);
        }
    }
    return oFCanonised;
}

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

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

    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 message2 = mailboxProbe.appendMessage(username,
            new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
            ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"), new Date(), false, new Flags());
    mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
            ClassLoader.getSystemResourceAsStream("eml/oneInlinedImage.eml"), new Date(), false, new Flags());
    await();/*from w  w  w  .j av  a  2 s. com*/

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

From source file:com.sworddance.util.CUtilities.java

private static InputStream getResourceAsStream(Object searchRoot, String fileName, boolean optional,
        List<String> searchPaths) {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    for (String searchPath : searchPaths) {
        InputStream resource = null;
        if (searchRoot != null) {
            resource = searchRoot.getClass().getResourceAsStream(searchPath);
        }//from   ww w .ja  va2  s. com

        if (resource == null && contextClassLoader != null) {
            resource = contextClassLoader.getResourceAsStream(searchPath);
        }
        if (resource == null) {
            resource = ClassLoader.getSystemResourceAsStream(searchPath);
        }
        if (resource != null) {
            return resource;
        }
    }
    if (!optional) {
        if (fileName != null) {
            throw new ApplicationNullPointerException(fileName, " not found in ", join(searchPaths, ","),
                    " java.class.path=", System.getProperty("java.class.path"), " java.library.path=",
                    System.getProperty("java.library.path"), " searchRoot =", getClassSafely(searchRoot));
        } else {
            throw new ApplicationNullPointerException("No listed file found ", join(searchPaths, ","),
                    " java.class.path=", System.getProperty("java.class.path"), " java.library.path=",
                    System.getProperty("java.library.path"), " searchRoot =", getClassSafely(searchRoot));
        }
    } else {
        return null;
    }
}

From source file:org.apromore.service.impl.CanoniserServiceImplIntgTest.java

private CanonisedProcess canoniseXPDLProcess(String fileName) throws CanoniserException, IOException {
    CanonisedProcess oFCanonised;//from www. j  a v  a  2 s  .  c  o m
    try (InputStream oFProcess = ClassLoader.getSystemResourceAsStream(fileName)) {
        HashSet<RequestParameterType<?>> xpdlParameters = new HashSet<>();
        oFCanonised = cSrv.canonise("XPDL 2.2", oFProcess, xpdlParameters);
    }
    return oFCanonised;
}