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.gameminers.mav.firstrun.TeachSphinxThread.java

@Override
public void run() {
    try {//from  w  w w .  ja  va2  s .  co m
        File training = new File(Mav.configDir, "training-data");
        training.mkdirs();
        while (Mav.silentFrames < 30) {
            sleep(100);
        }
        Mav.listening = true;
        InputStream prompts = ClassLoader.getSystemResourceAsStream("resources/sphinx/train/arcticAll.prompts");
        List<String> arctic = IOUtils.readLines(prompts);
        IOUtils.closeQuietly(prompts);
        Mav.audioManager.playClip("listen1");
        byte[] buf = new byte[2048];
        int start = 0;
        int end = 21;
        AudioInputStream in = Mav.audioManager.getSource().getAudioInputStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        while (true) {
            for (int i = start; i < end; i++) {
                baos.reset();
                String prompt = arctic.get(i);
                RenderState.setText("\u00A7LRead this aloud:\n" + Fonts.wrapStringToFit(
                        prompt.substring(prompt.indexOf(':') + 1), Fonts.base[1], Display.getWidth()));
                File file = new File(training, prompt.substring(0, prompt.indexOf(':')) + ".wav");
                file.createNewFile();
                int read = 0;
                while (Mav.silentListenFrames > 0) {
                    read = Mav.audioManager.getSource().getAudioInputStream().read(buf);
                }
                baos.write(buf, 0, read);
                while (Mav.silentListenFrames < 60) {
                    in.read(buf);
                    if (read == -1) {
                        RenderState.setText(
                                "\u00A7LAn error occurred\nUnexpected end of stream\nPlease restart Mav");
                        RenderState.targetHue = 0;
                        return;
                    }
                    baos.write(buf, 0, read);
                }
                AudioSystem.write(new AudioInputStream(new ByteArrayInputStream(baos.toByteArray()),
                        in.getFormat(), baos.size() / 2), AudioFileFormat.Type.WAVE, file);
                Mav.audioManager.playClip("notif2");
            }
            Mav.ttsInterface.say(Mav.phoneticUserName
                    + ", that should be enough for now. Do you want to keep training anyway?");
            RenderState.setText("\u00A7LOkay, " + Mav.userName
                    + "\nI think that should be\nenough. Do you want to\nkeep training anyway?\n\u00A7s(Say 'Yes' or 'No' out loud)");
            break;
            //start = end+1;
            //end += 20;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:de.tu.darmstadt.lt.ner.preprocessing.GermaNERMain.java

public static void initNERModel() throws IOException {
    configFile = configFile == null ? ClassLoader.getSystemResourceAsStream("config.properties") : configFile;
    prop = new Properties();
    loadConfig();//from   w ww  . j a v a 2s . co  m
}

From source file:org.apache.james.modules.server.DefaultProcessorsConfigurationProviderModule.java

@Override
protected void configure() {
    bind(CamelMailetContainerModule.DefaultProcessorsConfigurationSupplier.class).toInstance(() -> {
        try {/* ww  w  . j a v  a2s.  co  m*/
            return FileConfigurationProvider
                    .getConfig(ClassLoader.getSystemResourceAsStream("defaultMailetContainer.xml"));
        } catch (ConfigurationException e) {
            throw Throwables.propagate(e);
        }
    });
}

From source file:edu.hawaii.soest.pacioos.text.TextSourceFactoryTest.java

@Before
public void setUp() throws Exception {
    InputStream propsStream = ClassLoader.getSystemResourceAsStream("test.properties");
    Properties properties = new Properties();
    try {/* w  w  w . ja v  a 2s . c  om*/
        properties.load(propsStream);
        testResourcesDirectory = properties.getProperty("test.resources.directory");

    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:com.semsaas.jsonxml.tests.Tests.java

public void json2xjson(String jsonResource, String xmlResource) {
    InputStream is = ClassLoader.getSystemResourceAsStream(jsonResource);
    try {//w w w  .  j a  va2s . c  om
        // The real test
        Node node = Examples.Json2Dom.json2dom(is);

        // Check the results
        StringWriter result = new StringWriter();
        Examples.serialize(node, result);

        StringWriter expected = new StringWriter();
        InputStream xmlIs = ClassLoader.getSystemResourceAsStream(xmlResource);
        IOUtils.copy(xmlIs, expected);

        assertEquals(expected.toString().replaceAll("[\\n\\s]+", ""),
                result.toString().replaceAll("[\\n\\s]+", ""));

    } catch (SAXException e) {
        fail(e.getMessage());
    } catch (TransformerException e) {
        fail(e.getMessage());
    } catch (IOException e) {
        fail(e.getMessage());
    }
}

From source file:edu.usc.goffish.gofs.itest.KryoSerializerIntegrationTest.java

public void testKryoSerialization() throws IOException {
    Path sliceDir = Files.createTempDirectory("slices");
    try {/* ww w.j av  a  2 s  .  c om*/
        GMLPartition gmlPartition = GMLPartition.parseGML(1, new WCCComponentizer(),
                ClassLoader.getSystemResourceAsStream(TemplateFile), new GMLFileIterable(InstanceFiles));

        // Write the partition
        UUID partitionUUID = UUID.randomUUID();
        ISliceManager sliceManager = SliceManager.create(partitionUUID, new KryoSliceSerializer(),
                new FileStorageManager(sliceDir));
        sliceManager.writePartition(gmlPartition, 1, gmlPartition.size());

        // Read the partition
        sliceManager = SliceManager.create(partitionUUID, new KryoSliceSerializer(),
                new FileStorageManager(sliceDir));
        IPartition actualPartition = sliceManager.readPartition();
        assertNotNull(actualPartition);

        // Test the partition
        comparePartitionTemplates(gmlPartition, actualPartition);
        comparePartitionInstances(actualPartition);

    } finally {
        FileUtils.deleteQuietly(sliceDir.toFile());
    }
}

From source file:com.googlecode.sardine.AuthenticationTest.java

@Before
public void properties() throws Exception {
    properties = new Properties();
    properties.load(ClassLoader.getSystemResourceAsStream(TEST_PROPERTIES_FILENAME));
}

From source file:com.fujitsu.dc.test.jersey.bar.BarInstallTestUtils.java

/**
 * bar?./* www. j a va 2 s. co m*/
 * @param barFile bar?
 * @return ??bar
 */
public static byte[] readBarFile(File barFile) {
    InputStream is = ClassLoader.getSystemResourceAsStream(barFile.getPath());
    ByteBuffer buff = ByteBuffer.allocate(READ_BUFFER_SIZE);
    log.debug(String.valueOf(buff.capacity()));
    try {
        byte[] bbuf = new byte[SIZE_KB];
        int size;
        while ((size = is.read(bbuf)) != -1) {
            buff.put(bbuf, 0, size);
        }
    } catch (IOException e) {
        throw new RuntimeException("failed to load bar file:" + barFile.getPath(), e);
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            throw new RuntimeException("failed to close bar file:" + barFile.getPath(), e);
        }
    }
    int size = buff.position();
    buff.flip();
    byte[] retv = new byte[size];
    buff.get(retv, 0, size);
    return retv;
}

From source file:org.openmrs.module.metadatasharing.converter.ConceptMapConverterTest.java

@Before
public void before() throws Exception {
    File file = new File(ClassLoader.getSystemResource(TEXT_CONCEPT_MAP_XML_FILE).getPath());
    originalXml = FileUtils.readFileToString(file, "UTF-8");
    document = DocumentBuilderFactory.newInstance().newDocumentBuilder()
            .parse(ClassLoader.getSystemResourceAsStream(TEXT_CONCEPT_MAP_XML_FILE));
}

From source file:com.pinterest.pinlater.backends.mysql.MySQLQueueMonitorTest.java

@Override
protected MySQLQueueMonitor createQueueMonitor(long jobClaimedTimeoutMillis, long jobSucceededGCTimeoutMillis,
        long jobFailedGCTimeoutMillis) {
    InputStream mysqlConfigStream = ClassLoader.getSystemResourceAsStream("mysql.local.json");
    ImmutableMap<String, MySQLDataSources> shardMap = MySQLBackendUtils.buildShardMap(mysqlConfigStream,
            configuration);//w  ww.ja  v a2 s  . c  o  m
    return new MySQLQueueMonitor(shardMap, 1000, // update max size
            3, // auto retries
            1, // log interval
            jobClaimedTimeoutMillis, jobSucceededGCTimeoutMillis, jobFailedGCTimeoutMillis, 3 // max queue priority
    );
}