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.kuali.kfs.module.ar.batch.CustomerInvoiceWriteoffBatchDigesterTest.java

public void NORUN_testCustomerInvoiceWriteoffBatchDigesterRules() throws Exception {

    Digester digester = buildDigester(SCHEMA_DIRECTORY + SCHEMA_FILE,
            DIGESTER_RULE_DIRECTORY + DIGESTER_RULE_FILE);

    //  get the right kind of input stream expected for the sample batch file
    InputStream inputStream = ClassLoader.getSystemResourceAsStream(XML_SAMPLE_DIRECTORY + XML_SAMPLE_FILE);
    byte[] byteArray = IOUtils.toByteArray(inputStream);
    ByteArrayInputStream sampleCustomerBatchFile = new ByteArrayInputStream(byteArray);

    Object parsedObject = null;/*from w  w w  .j  a  v a  2  s .com*/
    try {
        parsedObject = digester.parse(sampleCustomerBatchFile);
    } catch (Exception e) {
        throw new RuntimeException("Error parsing xml contents: " + e.getMessage(), e);
    }

    assertNotNull("Parsed object should not be null.", parsedObject);
    assertTrue(
            "Parsed object class [" + parsedObject.getClass().toString() + "] should be assignable to a List.",
            parsedObject instanceof CustomerInvoiceWriteoffBatchVO);

    parsedBatchVO = (CustomerInvoiceWriteoffBatchVO) parsedObject;

    assertTrue("SubmittedBy PersonUserID should not be blank.",
            StringUtils.isNotBlank(parsedBatchVO.getSubmittedByPrincipalName()));
    assertTrue("SubmittedOn should not be blank.", StringUtils.isNotBlank(parsedBatchVO.getSubmittedOn()));
    assertNotNull("InvoiceNumbers should not be null.", parsedBatchVO.getInvoiceNumbers());
    assertFalse("InvoiceNumbers should not be empty.", parsedBatchVO.getInvoiceNumbers().isEmpty());
    assertTrue("InvoiceNumbers should have 3 elements in the set.",
            (parsedBatchVO.getInvoiceNumbers().size() == 3));

    return;
}

From source file:org.kuali.kfs.module.ar.batch.CustomerLoadDigesterTest.java

public void NORUN_testCustomerLoadDigesterRules() throws Exception {

    Digester digester = buildDigester(SCHEMA_DIRECTORY + SCHEMA_FILE,
            DIGESTER_RULE_DIRECTORY + DIGESTER_RULE_FILE);

    //  get the right kind of input stream expected for the sample batch file
    InputStream inputStream = ClassLoader.getSystemResourceAsStream(XML_SAMPLE_DIRECTORY + XML_SAMPLE_FILE);
    byte[] byteArray = IOUtils.toByteArray(inputStream);
    ByteArrayInputStream sampleCustomerBatchFile = new ByteArrayInputStream(byteArray);

    Object parsedCustomers = null;
    try {/* ww w .jav  a 2s .  c om*/
        parsedCustomers = digester.parse(sampleCustomerBatchFile);
    } catch (Exception e) {
        throw new ParseException("Error parsing xml contents: " + e.getMessage(), e);
    }

    assertNotNull("Parsed object should not be null.", parsedCustomers);
    assertTrue("Parsed object class [" + parsedCustomers.getClass().toString()
            + "] should be assignable to a List.", parsedCustomers instanceof List);

    List parsedObjects = (List) parsedCustomers;

    assertTrue("Parsed object List should contain at least one item.", (parsedObjects.size() >= 1));

    parsedCustomerList = new ArrayList<CustomerDigesterVO>();

    //  look at every item, make sure its of type Customer 
    Integer i = 0;
    for (Iterator iterator = parsedObjects.iterator(); iterator.hasNext();) {
        Object item = (Object) iterator.next();

        assertNotNull("List item [" + i.toString() + "] should not be null.", item);
        assertTrue("List item [" + i.toString() + "] class [" + item.getClass().toString()
                + "] should be a Customer object.", item.getClass().equals(CustomerDigesterVO.class));

        parsedCustomerList.add((CustomerDigesterVO) item);

        i++;
    }

    return;
}

From source file:com.gameminers.mav.audio.AudioManager.java

private void loadClip(String key) {
    try {//  w  w w .java 2s  .c  o m
        InputStream in = ClassLoader.getSystemResourceAsStream("resources/audio/" + key + ".wav");
        clips.put(key, IOUtils.toByteArray(in));
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.kairosdb.testclient.QueryTests.java

private JsonElement readJsonFromStream(String path, String metricName) throws IOException, JSONException {
    InputStream is = ClassLoader.getSystemResourceAsStream(path);
    if (is == null)
        return (null);

    String str = IOUtils.toString(is);

    //replace metric name
    str = str.replace("<metric_name>", metricName);

    return (m_parser.parse(str));
}

From source file:SecuritySupport.java

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

From source file:gobblin.util.ClustersNames.java

protected ClustersNames() {

    try (Closer closer = Closer.create()) {
        InputStream propsInput = closer.register(getClass().getResourceAsStream(URL_TO_NAME_MAP_RESOURCE_NAME));
        if (null == propsInput) {
            propsInput = closer.register(ClassLoader.getSystemResourceAsStream(URL_TO_NAME_MAP_RESOURCE_NAME));
        }//from w ww  . j ava  2 s .  c o  m
        if (null != propsInput) {
            try {
                this.urlToNameMap.load(propsInput);
                LOG.info("Loaded cluster names map:" + this.urlToNameMap);
            } catch (IOException e) {
                LOG.warn("Unable to load cluster names map: " + e, e);
            }
        } else {
            LOG.info("no default cluster mapping found");
        }
    } catch (IOException e) {
        LOG.warn("unable to close resource input stream for " + URL_TO_NAME_MAP_RESOURCE_NAME + ":" + e, e);
    }
}

From source file:se.sics.kompics.simulation.TimeInterceptor.java

public void start(ClassPool pool) throws NotFoundException, CannotCompileException {

    // well known exceptions
    exceptions.add("se.sics.kompics.p2p.simulator.P2pSimulator");
    exceptions.add("org.apache.log4j.PropertyConfigurator");
    exceptions.add("org.apache.log4j.helpers.FileWatchdog");
    exceptions.add("org.mortbay.thread.QueuedThreadPool");
    exceptions.add("org.mortbay.io.nio.SelectorManager");
    exceptions.add("org.mortbay.io.nio.SelectorManager$SelectSet");
    exceptions.add("org.apache.commons.math.stat.descriptive.SummaryStatistics");
    exceptions.add("org.apache.commons.math.stat.descriptive.DescriptiveStatistics");

    // try to add user-defined exceptions from properties file
    InputStream in = ClassLoader.getSystemResourceAsStream("timer.interceptor.properties");
    Properties p = new Properties();
    if (in != null) {
        try {//from  www .ja  va2s. com
            p.load(in);
            for (String classname : p.stringPropertyNames()) {
                String value = p.getProperty(classname);
                if (value != null && value.equals("IGNORE")) {
                    exceptions.add(classname);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.kuali.kfs.module.ar.batch.CustomerLoadXMLSchemaTest.java

/**
 * //from www.ja  va  2  s  .c  om
 * Tests the AR Customer Load sample XML file against the XSD schema.  
 * 
 * The goal if this is to make sure that the Sample file stays current, even 
 * if someone changes the XSD schema file down the road.  This failing test will 
 * then force the sample file to be updated (hopefully).
 * 
 */
public void NORUN_testSampleAgainstSchema() throws Exception {

    InputStream inputStream;
    byte[] byteArray;

    //  XML file stream creation
    inputStream = ClassLoader.getSystemResourceAsStream(XML_SAMPLE_DIRECTORY + XML_SAMPLE_FILE);
    byteArray = IOUtils.toByteArray(inputStream);
    ByteArrayInputStream sampleXmlFile = new ByteArrayInputStream(byteArray);

    //  Schema file stream creation
    File schemaFile = new File(SCHEMA_DIRECTORY + SCHEMA_FILE);
    assertTrue("File should exist at the specified path.", schemaFile.exists());

    inputStream = new FileInputStream(schemaFile);
    byteArray = IOUtils.toByteArray(inputStream);
    ByteArrayInputStream schemaLocation = new ByteArrayInputStream(byteArray);

    validateContentsAgainstSchema(schemaLocation, sampleXmlFile);
}

From source file:org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.loadsimulator.jmetertest.jmetertest.AMSJMeterLoadTest.java

public static Properties readProperties(String propertiesFile) {
    try {//  ww w. j  av  a 2  s  .  c  o m
        Properties properties = new Properties();
        InputStream inputStream = ClassLoader.getSystemResourceAsStream(propertiesFile);
        if (inputStream == null) {
            inputStream = new FileInputStream(propertiesFile);
        }
        properties.load(inputStream);
        return properties;
    } catch (IOException ioEx) {
        LOG.error("Error reading properties file for jmeter");
        return null;
    }
}

From source file:org.ldp4j.rdf.query.FillableQueryTemplateTest.java

private String loadResource(String resource) throws IOException {
    InputStream is = ClassLoader.getSystemResourceAsStream(resource);
    try {//from   w w w.  j  av a  2  s  . c om
        return IOUtils.toString(is);
    } finally {
        IOUtils.closeQuietly(is);
    }
}