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:cu.uci.uengine.utils.FileUtils.java

public static boolean dos2unixFileFixer(String filePath) throws IOException, InterruptedException {
    // bash es muy sensible a los cambios de linea \r\n de Windows. Para
    // prevenir que esto cause Runtime Errors, es necesario convertirlos a
    // un sistema comprensible por ubuntu: \n normal en linux. El comando
    // dos2unix hace esto.
    // se lo dejamos a todos los codigos para evitar que algun otro lenguaje
    // tambien padezca de esto

    Properties langProps = new Properties();
    langProps.load(ClassLoader.getSystemResourceAsStream("uengine.properties"));

    String dos2unixPath = langProps.getProperty("dos2unix.path");

    ProcessBuilder pb = new ProcessBuilder(dos2unixPath, filePath);
    Process process = pb.start();
    process.waitFor();/*from w ww . j  a v  a 2 s  .co m*/

    return process.exitValue() == 0;
}

From source file:org.apache.james.util.ClassLoaderUtils.java

public static byte[] getSystemResourceAsByteArray(String filename) {
    try {/*ww w  . j a  v  a 2 s  .c o m*/
        return IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream(filename));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.linecorp.bot.model.profile.UserProfileResponseTest.java

@Test
public void test() throws IOException {
    try (InputStream resourceAsStream = ClassLoader.getSystemResourceAsStream("user-profiles.json")) {
        ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule())
                .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false);

        UserProfileResponse userProfileResponse = objectMapper.readValue(resourceAsStream,
                UserProfileResponse.class);
        assertThat(userProfileResponse.getDisplayName()).isNotNull();
    }/*from   ww  w  .  j av  a2 s .  c om*/
}

From source file:com.adobe.acs.commons.remoteassets.impl.RemoteAssetsTestUtil.java

public static byte[] getPlaceholderAsset(String fileExt) throws IOException {
    return getBytes(ClassLoader.getSystemResourceAsStream("remoteassets/remote_asset." + fileExt));
}

From source file:com.joconner.g11n.charprop.service.BlocksService.java

public BlocksService() {
    noBlock = new Block("No_Block", -1, -1);
    blocks = new ArrayList<>();
    InputStream blockInputStream = ClassLoader.getSystemResourceAsStream("unicode/Blocks.txt");
    InputStreamReader blockReader = new InputStreamReader(blockInputStream, Charset.forName("UTF-8"));
    BufferedReader reader = new BufferedReader(blockReader);
    reader.lines().filter(s -> s.matches("^\\p{XDigit}{4,6}\\.\\.\\p{XDigit}{4,6};\\s.+"))
            .forEach((String t) -> {
                int rangeIdx = t.indexOf("..");
                int rangeEndIdx = t.indexOf(";");
                int nameIdx = t.indexOf(" ", rangeIdx) + 1;
                int blockStart = Integer.parseInt(t.substring(0, rangeIdx), 16);
                int blockEnd = Integer.parseInt(t.substring(rangeIdx + 2, rangeEndIdx), 16);
                Block b = new Block(t.substring(nameIdx), blockStart, blockEnd);
                blocks.add(b);//  ww  w.j a  va 2  s.c o m
            });
    try {
        reader.close();
    } catch (IOException ex) {

    }

}

From source file:joinery.DataFrameAggregationTest.java

@Before
public void setUp() throws Exception {
    df = DataFrame.readCsv(ClassLoader.getSystemResourceAsStream("grouping.csv"));
}

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

public void setUp() throws IOException {
    _partitioner = new GMLPartitioner(
            MetisPartitioning.read(ClassLoader.getSystemResourceAsStream("simple_partition.txt")));
}

From source file:org.openscore.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("Slang");
    }//  www. ja v a2 s.c o  m
    sb.append(System.lineSeparator());
    sb.append(SlangCLI.getVersion());
    return sb.toString();
}

From source file:org.microtitan.diffusive.utils.ClassLoaderUtils.java

/**
 * Converts the {@link Class} into a {@code byte[]}.
 * @param className The name of the {@link Class} to convert into a {@code byte[]}
 * @return a {@code byte[]} representation of the {@link Class}
 *//*from w w  w. j  a  v  a2 s . co  m*/
public static byte[] loadClassToByteArray(final String className) {
    byte[] bytes = null;
    try {
        // mangle the class name as specified by the ClassLoader.getSystemResourceAsStream docs
        final String classAsPath = className.replace('.', '/') + ".class";

        // grab the input stream
        final InputStream input = ClassLoader.getSystemResourceAsStream(classAsPath);

        // convert to bytes if the input stream exists
        if (input != null) {
            bytes = IOUtils.toByteArray(input);
        }
    } catch (IOException e) {
        final StringBuilder message = new StringBuilder();
        message.append("Error writing out to the Class< ? > to a byte array.").append(Constants.NEW_LINE)
                .append("  Class: ").append(className);
        LOGGER.error(message.toString(), e);
        throw new IllegalStateException(message.toString(), e);
    }

    return bytes;
}

From source file:com.github.brandtg.stl.PlotTest.java

@Test
public void testMinimalCase() throws Exception {
    List<Number> times = new ArrayList<Number>();
    List<Number> measures = new ArrayList<Number>();

    // Read from STDIN
    String line;//from w  ww  .ja v  a2 s.  co m
    BufferedReader reader = new BufferedReader(
            new InputStreamReader(ClassLoader.getSystemResourceAsStream("minimal.csv")));
    while ((line = reader.readLine()) != null) {
        String[] tokens = line.split(",");
        times.add(Long.valueOf(tokens[0]));
        measures.add(Double.valueOf(tokens[1]));
    }

    StlDecomposition stl = new StlDecomposition(288);
    stl.getConfig().setTrendComponentBandwidth(0.751);
    stl.getConfig().setSeasonalComponentBandwidth(0.85);
    // TODO: With default 10 we get decent results, but with 1 the head end seems a little off
    //    stl.getConfig().setNumberOfInnerLoopPasses(1);
    stl.getConfig().setPeriodic(false);
    StlResult res = stl.decompose(times, measures);

    // TODO: Validate more somehow (from https://github.com/brandtg/stl-java/issues/9)
    //    for (int i = 0; i < times.size(); i++) {
    //      System.out.println(String.format("%d,%02f,%02f,%02f,%02f",
    //          (long) res.getTimes()[i],
    //          res.getSeries()[i],
    //          res.getTrend()[i],
    //          res.getSeasonal()[i],
    //          res.getRemainder()[i]));
    //    }
}