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:pcgen.gui2.dialog.AboutDialog.java

/**
 * Construct the license panel. This panel shows the full
 * text of the license under which PCGen is distributed.
 *
 * @return The license panel.//from  ww  w. j a v  a 2s .  c o  m
 */
private JPanel buildLicensePanel() {
    JPanel lPanel = new JPanel();

    JScrollPane license = new JScrollPane();
    JTextArea lgplArea = new JTextArea();

    lPanel.setLayout(new BorderLayout());

    lgplArea.setEditable(false);

    InputStream lgpl = ClassLoader.getSystemResourceAsStream("LICENSE"); //$NON-NLS-1$

    if (lgpl != null) {
        try {
            lgplArea.read(new InputStreamReader(lgpl), "LICENSE"); //$NON-NLS-1$
        } catch (IOException ioe) {
            lgplArea.setText(LanguageBundle.getString("in_abt_license_read_err1")); //$NON-NLS-1$
        }
    } else {
        lgplArea.setText(LanguageBundle.getString("in_abt_license_read_err2")); //$NON-NLS-1$
    }

    license.setViewportView(lgplArea);
    lPanel.add(license, BorderLayout.CENTER);

    return lPanel;
}

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

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

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

    await();//from w  w  w.  ja v a 2s .c om

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

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

@Test
public void testTrustedMethodPrevention() {
    Response response = WebClient.create(endPoint + TIKA_PATH).type("application/pdf").accept("text/plain")
            .header(TikaResource.X_TIKA_OCR_HEADER_PREFIX + "trustedPageSeparator", "\u0020")
            .put(ClassLoader.getSystemResourceAsStream("testOCR.pdf"));
    assertEquals(500, response.getStatus());

}

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

@Test
public void checkReturnedTermsBehavior()
        throws ComponentLookupException, URISyntaxException, 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("BRCA1.json"));
    VocabularyTerm result = this.mocker.getComponentUnderTest().getTerm("BRCA1");
    Assert.assertEquals("BRCA1", result.get("symbol"));
    Assert.assertEquals("breast cancer 1, early onset", result.getName());
    Assert.assertEquals("", result.getDescription());
    Assert.assertEquals(-1, result.getDistanceTo(null));
    Assert.assertEquals(-1, result.getDistanceTo(result));
    Assert.assertEquals(-1, result.getDistanceTo(mock(VocabularyTerm.class)));
    Assert.assertEquals(this.mocker.getComponentUnderTest(), result.getVocabulary());
    Assert.assertTrue(result.getParents().isEmpty());
    Assert.assertTrue(result.getAncestors().isEmpty());
    Assert.assertEquals(1, result.getAncestorsAndSelf().size());
    Assert.assertTrue(result.getAncestorsAndSelf().contains(result));
    Assert.assertEquals("BRCA1", result.getId());
    Assert.assertEquals("HGNC:BRCA1", result.toString());
}

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

@Test
public void checkReturnedTermsBehavior()
        throws ComponentLookupException, URISyntaxException, 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("BRCA1.json"));
    OntologyTerm result = this.mocker.getComponentUnderTest().getTerm("BRCA1");
    Assert.assertEquals("BRCA1", result.get("symbol"));
    Assert.assertEquals("breast cancer 1, early onset", result.getName());
    Assert.assertEquals("", result.getDescription());
    Assert.assertEquals(-1, result.getDistanceTo(null));
    Assert.assertEquals(-1, result.getDistanceTo(result));
    Assert.assertEquals(-1, result.getDistanceTo(mock(OntologyTerm.class)));
    Assert.assertEquals(this.mocker.getComponentUnderTest(), result.getOntology());
    Assert.assertTrue(result.getParents().isEmpty());
    Assert.assertTrue(result.getAncestors().isEmpty());
    Assert.assertEquals(1, result.getAncestorsAndSelf().size());
    Assert.assertTrue(result.getAncestorsAndSelf().contains(result));
    Assert.assertEquals("BRCA1", result.getId());
    Assert.assertEquals("HGNC:BRCA1", result.toString());
}

From source file:cn.quickj.AbstractApplication.java

public void hibernateInit() {
    Properties properties = new Properties();
    Configuration cfg = new Configuration();
    // add model class to configuration.
    ArrayList<Class<?>> models = QuickUtils.getPackageClasses(Setting.packageRoot + ".model", null,
            Entity.class);
    models.addAll(QuickUtils.getPackageClassInJar(Setting.webRoot + "WEB-INF/lib/quick.jar",
            Setting.packageRoot + ".model", null, Entity.class));
    for (Plugin plugin : Setting.plugins) {
        if (plugin.getModels() != null)
            models.addAll(plugin.getModels());
    }/*from ww  w  . j a v a  2 s  .  com*/
    for (Class<?> model : models) {
        cfg.addAnnotatedClass(model);
    }

    models = getModels();
    if (models != null) {
        for (Class<?> model : models) {
            cfg.addAnnotatedClass(model);
        }
    }

    // dialectjdbcjdbc?mysqlinnodb for
    // mysql5dialect???
    if (Setting.dialect != null && Setting.dialect.length() > 0)
        properties.put("hibernate.dialect", Setting.dialect);
    else
        properties.put("hibernate.dialect", QuickUtils.getDialectByDriver(Setting.jdbcDriver));
    properties.put("hibernate.connection.driver_class", Setting.jdbcDriver);
    properties.put("hibernate.connection.url", Setting.jdbcUrl);
    properties.put("hibernate.connection.username", Setting.jdbcUser);
    properties.put("hibernate.connection.password", Setting.jdbcPassword);
    properties.put("hibernate.connection.provider_class", "org.hibernate.connection.C3P0ConnectionProvider");
    properties.put("hibernate.c3p0.min_size", Setting.initActive + "");
    properties.put("hibernate.c3p0.max_size", Setting.maxActive + "");
    properties.put("hibernate.c3p0.timeout", Setting.maxIdle + "");
    properties.put("hibernate.c3p0.idle_test_period", "600");//10
    properties.put("hibernate.c3p0.preferredTestQuery", "SELECT 1");
    if (Setting.runMode == Setting.DEV_MODE) {
        properties.put("hibernate.show_sql", "true");
    }
    properties.put("hibernate.order_updates", "true");
    properties.put("hibernate.cache.use_second_level_cache", "true");
    properties.put("hibernate.cache.provider_class", "org.hibernate.cache.EhCacheProvider");

    Properties extraProp = new Properties();
    try {
        InputStream extra = ClassLoader.getSystemResourceAsStream("hibernate.properties");
        if (extra != null) {
            extraProp.load(extra);
            properties.putAll(extraProp);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    onHibernateConfig(properties);
    cfg.mergeProperties(properties);
    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties())
            .buildServiceRegistry();
    Setting.sessionFactory = cfg.buildSessionFactory(serviceRegistry);

}

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

@Test
public void testFloatInHeader() {
    Response response = WebClient.create(endPoint + TIKA_PATH).type("application/pdf").accept("text/plain")
            .header(TikaResource.X_TIKA_PDF_HEADER_PREFIX + "averageCharTolerance", "2.0")
            .put(ClassLoader.getSystemResourceAsStream("testOCR.pdf"));
    assertEquals(200, response.getStatus());

}

From source file:com.navient.portal.portal.Settings.java

/**
 * Load the settings from the properties file
 *///from   ww w . ja v a 2 s  .  c  o  m
public Settings() {
    FileReader reader = null;
    try {
        //reader = new FileReader(new File(System.getProperty("user.home") + "/portal_location.txt"));
        File pl = new File(System.getProperty("user.home") + "/portal_location.txt");
        if (!pl.exists()) {
            pl.createNewFile();
        }
        //portal_location = new Scanner(pl)
        //        .useDelimiter("\\A").next().replaceAll("\\n", "");
        user_prop_file = portal_location + "files/user.properties";
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
    }

    try {
        String host = java.net.InetAddress.getLocalHost().getHostName();
        if (host.contains(".")) {
            hostname = host.substring(0, host.indexOf("."));
        } else {
            hostname = host;
        }
    } catch (UnknownHostException ex) {
        Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
    }

    prop = new Properties();
    userprop = new Properties();
    InputStream input = null;
    InputStream input2 = null;
    try {
        // Load the user properties file
        input = new FileInputStream(user_prop_file);
        userprop.load(input);

        // Load the portal properties file
        input2 = Portal.class.getClassLoader()
                .getResourceAsStream("com/navient/portal/resources/portal.properties");
        if (input2 == null) {
            System.out.println("portal.properties not found.");
            System.out.println("input: " + input2);
            return;
        }
        prop.load(input2);

        // MISC
        //portal_location = userprop.getProperty("portal_location");
        name = userprop.getProperty("name");
        password = getPass(); //userprop.getProperty("password");
        email_address = userprop.getProperty("email_address");
        sop_file = userprop.getProperty("sop_file");
        ldap_server = userprop.getProperty("ldap_server");
        ssh_server = userprop.getProperty("ssh_server");
        use_autocomplete = Boolean.parseBoolean(userprop.getProperty("use_autocomplete"));
        default_method = userprop.getProperty("default_method");
        terminal_type = userprop.getProperty("terminal_cmd").split(" ")[0];
        if (terminal_type.isEmpty()) {
            terminal_type = "gnome-terminal";
        }
        opsware_server = userprop.getProperty("opsware_server");
        releaseNotesFile = portal_location + "release_notes.txt";
        aboutReleaseFile = portal_location + "files/about_release_notes.txt";
        IconRedX = "com/navient/portal/resources/redx.png";
        IconBlueCheck = "com/navient/portal/resources/bluecheck.png";
        defaultSOP = userprop.getProperty("defaultSOP");
        selectedTicketMasterInitial = userprop.getProperty("ticketmaster_initial");

        // Terminal Settings
        selectedTerminalCmd = userprop.getProperty("selectedTerminalCmd");
        terminal_cmd = userprop.getProperty("terminal_cmd");
        termWidth = userprop.getProperty("termWidth");
        termHeight = userprop.getProperty("termHeight");
        termOptions = userprop.getProperty("termOptions");

        // KEYWORDS
        keyword_ack = userprop.getProperty("keyword_ack");
        keyword_close = userprop.getProperty("keyword_close");
        keyword_ackclose = userprop.getProperty("keyword_ackclose");
        keyword_translation = userprop.getProperty("keyword_translation");
        keyword_rosh = userprop.getProperty("keyword_rosh");
        keyword_gs = userprop.getProperty("keyword_gs");
        keyword_silence = userprop.getProperty("keyword_silence");
        keyword_update = userprop.getProperty("keyword_update");
        keyword_ldap = userprop.getProperty("keyword_ldap");
        keyword_ssh = userprop.getProperty("keyword_ssh");
        keyword_faillog = userprop.getProperty("keyword_faillog");
        keyword_notify = userprop.getProperty("keyword_notify");
        keyword_completeco = userprop.getProperty("keyword_completeco");
        keyword_createco = userprop.getProperty("keyword_createco");
        keyword_mass = userprop.getProperty("keyword_mass");
        keyword_help = userprop.getProperty("keyword_help");
        keyword_updatepass = userprop.getProperty("keyword_updatepass");
        keyword_settings = userprop.getProperty("keyword_settings");
        keyword_lookup = userprop.getProperty("keyword_lookup");
        keyword_term = userprop.getProperty("keyword_term");
        keyword_decom = userprop.getProperty("keyword_decom");
        keyword_tickets = userprop.getProperty("keyword_tickets");
        keyword_oncall = userprop.getProperty("keyword_oncall");
        keyword_patching = userprop.getProperty("keyword_patching");
        keyword_widget = userprop.getProperty("keyword_widget");
        keyword_monitoring = userprop.getProperty("keyword_monitoring");
        keyword_systray = userprop.getProperty("keyword_systray");

        gs_exp = portal_location + prop.getProperty("gs_exp");
        rh_exp = portal_location + prop.getProperty("rh_exp");
        gs_cmd_exp = portal_location + prop.getProperty("gs_cmd_exp");
        gs_cmd_sh = portal_location + prop.getProperty("gs_cmd_sh");
        silence_exp = portal_location + prop.getProperty("silence_exp");
        silence_sh = portal_location + prop.getProperty("silence_sh");
        launch_co_wiz_exp = portal_location + prop.getProperty("launch_co_wiz_exp");
        push_sop_exp = portal_location + prop.getProperty("push_sop_exp");
        get_sop_folder_list_exp = portal_location + prop.getProperty("get_sop_folder_list_exp");
        fetch_all_exp = portal_location + prop.getProperty("fetch_all_exp");
        fetch_one_exp = portal_location + prop.getProperty("fetch_one_exp");
        fetch_mass_exp = portal_location + prop.getProperty("fetch_mass_exp");
        ssh_ldap_exp = portal_location + prop.getProperty("ssh_ldap_exp");
        term_users_exp = portal_location + prop.getProperty("term_users_exp");
        fetch_co_tasks_exp = portal_location + prop.getProperty("fetch_co_tasks_exp");
        decom_exp = portal_location + prop.getProperty("decom_exp");
        fetch_ticket_info_exp = portal_location + prop.getProperty("fetch_ticket_info_exp");
        ssh_exp = portal_location + prop.getProperty("ssh_exp");
        envTest_exp = portal_location + prop.getProperty("envTest_exp");

        // FILES
        translation_file = portal_location + prop.getProperty("translation_file");
        ssh_config_file = portal_location + "files/server_list_file";
        termlist_file = portal_location + prop.getProperty("termlist_file");
        sop_location = portal_location + "SOP";
        patching_html = prop.getProperty("patching_html");
        patching_url = prop.getProperty("patching_url");
        unx100_html_file = prop.getProperty("unx100_html_file");

        //GlobalShell scripts
        ack_script = prop.getProperty("ack_script");
        close_script = prop.getProperty("close_script");
        silence_script = prop.getProperty("silence_script");
        command_low = prop.getProperty("command_low");
        command_std = prop.getProperty("command_std");
        command_med = prop.getProperty("command_med");
        command_task = prop.getProperty("command_task");
        command_task_skip = prop.getProperty("command_task_skip");
        command_owner = prop.getProperty("command_owner");
        command_approve = prop.getProperty("command_approve");
        listnonclosedtickets_script = prop.getProperty("listnonclosedtickets_script");
        listopentickets_script = prop.getProperty("listopentickets_script");
        listunassignedtickets_script = prop.getProperty("listunassignedtickets_script");
        list_co_tasks_script = prop.getProperty("list_co_tasks_script");
        co_wiz_script = prop.getProperty("co_wiz_script");
        listticketinfo_script = prop.getProperty("listticketinfo_script");
        listmytickets_script = prop.getProperty("listmytickets_script");
        listcoproperties_script = prop.getProperty("listcoproperties_script");
        setoncall_script = prop.getProperty("setoncall_script");

    } catch (IOException e) {
        //e.printStackTrace();
        MessageDialogs dialogs = new MessageDialogsImpl();
        dialogs.showError("Can't load user.properties file.\n\nNo such file or directory.");
        System.out.println("Error: " + e.getMessage());
        System.exit(1);
    } finally {
        try {
            input.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    // Splash Screens
    InputStream in;
    try {
        in = ClassLoader.getSystemResourceAsStream("com/navient/portal/resources/mass_loading.gif");
        mass_splash = Toolkit.getDefaultToolkit().createImage(IOUtils.toByteArray(in));

        imageURL = ClassLoader.getSystemResource("com/navient/portal/resources/nomatchfound.png");
        splash_nomatch = new ImageIcon(imageURL);

        imageURL = ClassLoader.getSystemResource("com/navient/portal/resources/hold-your-horses.png");
        splash_update = new ImageIcon(imageURL);

        in = ClassLoader.getSystemResourceAsStream("com/navient/portal/resources/tasks_loading.gif");
        tasks_loading = Toolkit.getDefaultToolkit().createImage(IOUtils.toByteArray(in));

        java.net.URL imageUrlStandby = ClassLoader.getSystemResource("com/navient/portal/resources/portal.png");
        standbyIcon = new ImageIcon(imageUrlStandby).getImage();

        in = ClassLoader.getSystemResourceAsStream("com/navient/portal/resources/systray_circle_loading.gif");
        workingIcon = Toolkit.getDefaultToolkit().createImage(IOUtils.toByteArray(in));

        //in = ClassLoader.getSystemResourceAsStream("resources/hold-your-horses.png");
        //splash_nomatch = Toolkit.getDefaultToolkit().createImage(IOUtils.toByteArray(in));
        //in = ClassLoader.getSystemResourceAsStream("resources/hold-your-horses.png");
        //splash_update = Toolkit.getDefaultToolkit().createImage(IOUtils.toByteArray(in));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.apache.ambari.server.stack.StackDirectory.java

private void parseServicePort() {
    Map<String, Map<String, List<String>>> result = null;
    ObjectMapper mapper = new ObjectMapper();
    try {//from w  w  w. jav a2 s  .  c o  m
        TypeReference<Map<String, Map<String, List<String>>>> spElementTypeReference = new TypeReference<Map<String, Map<String, List<String>>>>() {
        };
        if (spFilePath != null) {
            File file = new File(spFilePath);
            result = mapper.readValue(file, spElementTypeReference);
            LOG.info("Service port info was loaded from file: {}", file.getAbsolutePath());
        } else {
            InputStream spInputStream = ClassLoader.getSystemResourceAsStream(AmbariMetaInfo.SP_FILE_NAME);
            if (spInputStream != null) {
                result = mapper.readValue(spInputStream, spElementTypeReference);
                LOG.info("Service port info was loaded from classpath: "
                        + ClassLoader.getSystemResource(AmbariMetaInfo.SP_FILE_NAME));
            }
        }
        servicePort = new StackServicePort(result);
    } catch (IOException e) {
        LOG.error(String.format("Can not read service port info %s", spFilePath), e);
    }

}

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

@Test
public void testOOMInLegacyMode() throws Exception {

    Response response = null;/*from   w w  w . ja  v a 2 s . c  o  m*/
    try {
        response = WebClient.create(endPoint + TIKA_PATH).accept("text/plain")
                .put(ClassLoader.getSystemResourceAsStream(TEST_OOM));
    } catch (Exception e) {
        //oom may or may not cause an exception depending
        //on the timing
    }

    response = WebClient.create(endPoint + TIKA_PATH).accept("text/plain")
            .put(ClassLoader.getSystemResourceAsStream(TEST_RECURSIVE_DOC));
    String responseMsg = getStringFromInputStream((InputStream) response.getEntity());

    assertContains("plundered our seas", responseMsg);
}