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:io.cloudslang.lang.cli.SlangBanner.java

@Override
public String getBanner() {
    StringBuilder sb = new StringBuilder();
    try (InputStream in = ClassLoader.getSystemResourceAsStream(BANNER)) {
        sb.append(IOUtils.toString(in));
    } catch (IOException e) {
        sb.append("CloudSlang");
    }//  www .j  a  va2  s .  co  m
    sb.append(System.lineSeparator());
    sb.append(getVersion());
    return sb.toString();
}

From source file:org.apache.camel.component.schematron.processor.SchematronProcessorTest.java

@Test
public void testValidXML() throws Exception {

    String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-1.xml"));
    logger.info("Validating payload: {}", payload);

    // validate/*  w w w.  ja va 2 s .c o  m*/
    String result = getProcessor("sch/schematron-1.sch").validate(payload);
    logger.info("Schematron Report: {}", result);
    assertEquals(0, Integer.valueOf(Utils.evaluate("count(//svrl:failed-assert)", result)).intValue());
    assertEquals(0, Integer.valueOf(Utils.evaluate("count(//svrl:successful-report)", result)).intValue());

}

From source file:com.taobao.tddl.common.config.impl.DefaultConfigDataHandlerFactory.java

private static void findSpecifiedConfigHandlerClass() {
    ClassLoader currentCL = getBaseClassLoader();
    InputStream resource;//from   w w  w  .j  a  v  a  2s . com
    for (;;) {
        if (currentCL != null) {
            resource = currentCL.getResourceAsStream(propertyFile);
        } else {
            resource = ClassLoader.getSystemResourceAsStream(propertyFile);
            break;
        }

        if (null != resource) {
            break;
        } else {
            currentCL = currentCL.getParent();
        }
    }

    if (null != resource) {
        prop = new Properties();
        try {
            prop.load(resource);
            handlerClassName = prop.getProperty(HANDLER_CLASS);
            if (null == handlerClassName || "".equals(handlerClassName)) {
                handlerClassName = DEFAULT_HANDLER_CLASS;
            }
        } catch (IOException e) {
            log.error("properties can not load " + propertyFile);
        }
    } else {
        handlerClassName = DEFAULT_HANDLER_CLASS;
    }
}

From source file:com.rockhoppertech.music.midi.js.xml.ModeFactoryXMLHelper.java

/**
 * Read modes.xml and create {@code Scale instances} from those definitions.
 *///from   w ww . ja v a2  s.  c  om
public static void init() {
    List<Integer> intervals = null;
    Scale currentMode = null;
    String tagContent = null;
    XMLInputFactory factory = XMLInputFactory.newInstance();
    XMLStreamReader reader = null;
    try {
        reader = factory.createXMLStreamReader(ClassLoader.getSystemResourceAsStream("modes.xml"));
    } catch (XMLStreamException e) {
        e.printStackTrace();
        return;
    }

    try {
        while (reader.hasNext()) {
            int event = reader.next();

            switch (event) {
            case XMLStreamConstants.START_ELEMENT:
                String el = reader.getLocalName();
                logger.debug("start element '{}'", el);
                if ("mode".equals(el)) {
                    currentMode = new Scale();
                    intervals = new ArrayList<>();
                }
                if ("modes".equals(el)) {
                    modeList = new ArrayList<>();
                }
                break;

            case XMLStreamConstants.CHARACTERS:
                tagContent = reader.getText().trim();
                logger.debug("tagcontent '{}'", tagContent);
                break;

            case XMLStreamConstants.END_ELEMENT:
                switch (reader.getLocalName()) {
                case "mode":
                    // wow. both guava and commmons to get an int[] array
                    Integer[] array = FluentIterable.from(intervals).toArray(Integer.class);
                    // same as Integer[] array = intervals.toArray(new
                    // Integer[intervals.size()]);
                    int[] a = ArrayUtils.toPrimitive(array);
                    currentMode.setIntervals(a);
                    modeList.add(currentMode);
                    ScaleFactory.registerScale(currentMode);
                    break;
                case "interval":
                    logger.debug("interval '{}'", tagContent);
                    logger.debug("intervals '{}'", intervals);
                    intervals.add(Integer.parseInt(tagContent));
                    break;
                case "name":
                    currentMode.setName(tagContent);
                    break;
                }
                break;

            case XMLStreamConstants.START_DOCUMENT:
                modeList = new ArrayList<>();
                intervals = new ArrayList<>();
                break;
            }
        }
    } catch (XMLStreamException e) {
        logger.error(e.getLocalizedMessage(), e);
        e.printStackTrace();
    }

    logger.debug("mode list \n{}", modeList);
}

From source file:com.hangum.tadpole.commons.sql.map.SQLMap.java

private static String getFileToString(String url) throws Exception {
    ClassLoader loader = SQLMap.class.getClassLoader();
    InputStream is = loader == null ? ClassLoader.getSystemResourceAsStream(url)
            : loader.getResourceAsStream(url);

    int size = is.available();
    byte[] dataByte = new byte[size];
    is.read(dataByte, 0, size);/*from   w  ww.ja v a 2s .c  om*/
    is.close();

    return new String(dataByte);
}

From source file:com.hangum.tadpole.engine.manager.internal.map.SQLMap.java

/**
 * SQLMap XML to string/*from   ww  w .  jav a  2  s.c  o m*/
 * 
 * @param url
 * @return
 * @throws Exception
 */
private static String getFileToString(String url) throws Exception {
    ClassLoader loader = SQLMap.class.getClassLoader();
    InputStream is = loader == null ? ClassLoader.getSystemResourceAsStream(url)
            : loader.getResourceAsStream(url);

    int size = is.available();
    byte[] dataByte = new byte[size];
    is.read(dataByte, 0, size);
    is.close();

    return new String(dataByte);
}

From source file:edu.usc.goffish.gofs.partition.gml.GMLPartitionerTest.java

public void testPartitioner() throws IOException {
    Path outputDir = Files.createTempDirectory("gofs_test");
    try {//w  ww .  j a v a 2  s  . co  m
        _partitioner.partitionTemplate(ClassLoader.getSystemResourceAsStream("simple_graph_template.gml"),
                outputDir, "partition_", "_template.gml");
        // TODO: test instance partitions

        Path p1_t = outputDir.resolve("partition_1_template.gml");
        // Path p1_i1 = _outputDir.resolve("partition_1_instance1.gml");
        GMLPartition p1 = GMLPartition.parseGML(1, new WCCComponentizer(), Files.newInputStream(p1_t),
                Collections.<InputStream>emptyList());

        ISubgraph s10 = p1.iterator().next();

        assertTrue(s10.getTemplate().isDirected());
        assertTrue(s10.containsVertex(1));
        assertTrue(s10.containsVertex(2));
        assertTrue(s10.containsVertex(3));
        assertTrue(s10.getVertex(1).containsOutEdgeTo(s10.getVertex(2)));
        assertFalse(s10.getVertex(2).containsOutEdgeTo(s10.getVertex(1)));
        assertFalse(s10.getVertex(1).isRemote());
        assertFalse(s10.getVertex(2).isRemote());
        assertTrue(s10.getVertex(3).isRemote());
        assertEquals(2, s10.getVertex(3).getRemotePartitionId());

        Path p2_t = outputDir.resolve("partition_2_template.gml");
        // Path p2_i1 = _outputDir.resolve("partition_2_instance1.gml");
        GMLPartition p2 = GMLPartition.parseGML(1, new WCCComponentizer(), Files.newInputStream(p2_t),
                Collections.<InputStream>emptyList());

        ISubgraph s20 = p2.iterator().next();

        assertTrue(s20.isDirected());
        assertFalse(s20.containsVertex(1));
        assertFalse(s20.containsVertex(2));
        assertTrue(s20.containsVertex(3));
        assertTrue(s20.containsVertex(4));
        assertTrue(s20.getVertex(3).containsOutEdgeTo(s20.getVertex(4)));
        assertFalse(s20.getVertex(4).containsOutEdgeTo(s20.getVertex(3)));
        assertFalse(s20.getVertex(3).isRemote());
        assertFalse(s20.getVertex(4).isRemote());
    } finally {
        FileUtils.deleteQuietly(outputDir.toFile());
    }
}

From source file:org.langera.freud.optional.css.cssrule.declaration.CssDeclarationJdomTest.java

@Before
public void setUp() throws Exception {
    final SAXBuilder saxBuilder = new SAXBuilder(false);
    Document document = saxBuilder.build(ClassLoader.getSystemResourceAsStream("parsed_css_example.xml"));
    JXPathContext context = JXPathContext.newContext(document.getRootElement());
    cssDeclarationJdom = new CssDeclarationJdom(null, (Element) context.selectSingleNode("//PROPERTY"));

}

From source file:cu.uci.uengine.runner.impl.FileRunner.java

@PostConstruct
private void loadLanguages() throws IOException {
    Properties langProps = new Properties();
    langProps.load(ClassLoader.getSystemResourceAsStream("languages.properties"));

    String[] languages = langProps.getProperty("language.list").split(",");
    executionCommands = new HashMap();

    for (String language : languages) {

        language = language.trim();/*from   ww  w .j a  v a  2 s. c  o  m*/

        String executionCommand = langProps.getProperty(language + ".exec").trim();

        if (!StringUtils.isEmpty(executionCommand)) {
            executionCommands.put(language, executionCommand);
        }
    }
}