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:com.navient.portalupdater.Settings.java

public Settings() {
    //user_prop_file = "/tmp/user.properties";
    user_prop_file = portal_location + "/files/user.properties";

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

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

        username = userprop.getProperty("username");
        if ("t".equals(username.substring(username.length() - 1))) {
            id = username.substring(0, 6);
        } else {
            id = username;
        }

        ad_password = getADPass();
        tldap_password = getTLDAPPass();
        opsware_server = userprop.getProperty("opsware_server");

    } catch (IOException e) {
        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();
        }
    }

    InputStream in;
    try {
        in = ClassLoader.getSystemResourceAsStream("updating.gif");
        updating_splash = Toolkit.getDefaultToolkit().createImage(IOUtils.toByteArray(in));
        in = ClassLoader.getSystemResourceAsStream("downloading.gif");
        downloading_splash = Toolkit.getDefaultToolkit().createImage(IOUtils.toByteArray(in));
    } catch (IOException ex) {
        Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.apache.james.http.jetty.JettyHttpServerFactoryTest.java

@Test
public void shouldThrowOnConflictingPortConfiguration() throws Exception {
    HierarchicalConfiguration configuration = loadConfiguration(
            ClassLoader.getSystemResourceAsStream("conflictingport.xml"));
    assertThatThrownBy(() -> new JettyHttpServerFactory().createServers(configuration))
            .isInstanceOf(ConfigurationException.class);
}

From source file:com.wallellen.wechat.mp.api.WxMpMaterialAPITest.java

@Test(dataProvider = "uploadMaterial")
public void testUploadMaterial(String mediaType, String fileType, String fileName)
        throws WxErrorException, IOException {
    if (wxMaterialCountResultBeforeTest == null) {
        wxMaterialCountResultBeforeTest = wxService.materialCount();
    }//from  ww w .java  2s . c om
    InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName);
    File tempFile = FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), fileType);
    WxMpMaterial wxMaterial = new WxMpMaterial();
    wxMaterial.setFile(tempFile);
    wxMaterial.setName(fileName);
    if (WxConsts.MEDIA_VIDEO.equals(mediaType)) {
        wxMaterial.setVideoTitle("title");
        wxMaterial.setVideoIntroduction("test video description");
    }
    WxMpMaterialUploadResult res = wxService.materialFileUpload(mediaType, wxMaterial);
    Assert.assertNotNull(res.getMediaId());
    if (WxConsts.MEDIA_IMAGE.equals(mediaType) || WxConsts.MEDIA_THUMB.equals(mediaType)) {
        Assert.assertNotNull(res.getUrl());
    }
    if (WxConsts.MEDIA_THUMB.equals(mediaType)) {
        thumbMediaId = res.getMediaId();
    }

    Map<String, Object> materialInfo = new HashMap<>();
    materialInfo.put("media_id", res.getMediaId());
    materialInfo.put("length", tempFile.length());
    materialInfo.put("filename", tempFile.getName());
    media_ids.put(res.getMediaId(), materialInfo);
}

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

@Test
public void testTextMain() throws Exception {
    //boilerpipe/* w  w  w .ja  va 2  s .  c  o  m*/
    Response response = WebClient.create(endPoint + TIKA_PATH + "/main").accept("text/plain")
            .put(ClassLoader.getSystemResourceAsStream("testHTML.html"));
    String responseMsg = getStringFromInputStream((InputStream) response.getEntity());
    assertTrue(responseMsg.contains("Title : Test Indexation Html"));
    assertFalse(responseMsg.contains("Indexation du fichier"));
}

From source file:org.apache.flume.test.util.StagedInstall.java

public synchronized void startAgent(String name, String configResource) throws Exception {
    if (process != null) {
        throw new Exception("A process is already running");
    }//from   w  w w . jav a 2s.c om

    Properties props = new Properties();
    props.load(ClassLoader.getSystemResourceAsStream(configResource));

    startAgent(name, props);
}

From source file:SecuritySupport.java

InputStream getResourceAsStream(ClassLoader cl, String name) {
    InputStream ris;/*from   w w  w  .  j av  a  2 s .co  m*/
    if (cl == null) {
        ris = ClassLoader.getSystemResourceAsStream(name);
    } else {
        ris = cl.getResourceAsStream(name);
    }
    return ris;
}

From source file:org.reactor.monitoring.util.FileHandler.java

public static Properties loadResourceProperties(final String propertyFile) throws IOException {
    Properties prop = new Properties();
    InputStream is = null;//from w  w w . ja  va2s .com
    try {
        is = ClassLoader.getSystemResourceAsStream(propertyFile);
        prop.load(is);
    } finally {
        close(is);
    }

    System.out.println(prop.toString());
    return prop;

}

From source file:phex.common.Ip2CountryManager.java

private void loadIp2CountryDB() {
    InputStream inStream = ClassLoader.getSystemResourceAsStream("phex/resources/ip2country.csv");
    if (inStream == null) {
        Logger.logMessage(Logger.FINE, Logger.NETWORK, "Default GWebCache file not found.");
        return;/* w  ww.  ja  v a 2  s  .c o  m*/
    }
    BufferedReader reader = new BufferedReader(new InputStreamReader(inStream));

    ArrayList initialList = new ArrayList(5000);
    IpCountryRange range;
    String line;
    try {
        line = reader.readLine();
        while (line != null) {
            range = new IpCountryRange(line);
            initialList.add(range);
            line = reader.readLine();
        }
    } catch (IOException exp) {
        NLogger.error(NLoggerNames.GLOBAL, exp, exp);
    } finally {
        IOUtil.closeQuietly(reader);
    }
    initialList.trimToSize();
    Collections.sort(initialList);
    ipCountryRangeList = UnmodifiableList.decorate(initialList);
    isLoaded = true;
}

From source file:org.apache.james.mailbox.tika.TikaTextExtractorTest.java

@Test
public void textOdtTest() throws Exception {
    InputStream inputStream = ClassLoader.getSystemResourceAsStream("documents/writter.odt");
    assertThat(inputStream).isNotNull();
    assertThat(textExtractor.extractContent(inputStream, "application/vnd.oasis.opendocument.text")
            .getTextualContent()).contains("This is an awesome document on libroffice writter!\n");
}

From source file:com.github.jcooky.jaal.agent.bytecode.asm.ASM5InjectorTest.java

@Test
public void testInjectUsingReplace() throws Throwable {
    InjectorStrategy is = new ReplaceInjectorStrategy(Properties.class.getName(),
            ChangedProperties.class.getName());

    ASM5Injector injector = new ASM5Injector(is);

    Class<?> cls = classLoader.defineClass(injector.inject(IOUtils.toByteArray(
            ClassLoader.getSystemResourceAsStream(Target2.class.getName().replace('.', '/') + ".class"))));

    Object self = cls.newInstance();
    Class<? extends Properties> result = (Class<? extends Properties>) cls.getMethod("a").invoke(self);
    assertThat(result.getName(), is(ChangedProperties.class.getName()));
}