Example usage for org.springframework.core.io Resource getInputStream

List of usage examples for org.springframework.core.io Resource getInputStream

Introduction

In this page you can find the example usage for org.springframework.core.io Resource getInputStream.

Prototype

InputStream getInputStream() throws IOException;

Source Link

Document

Return an InputStream for the content of an underlying resource.

Usage

From source file:ru.jts_dev.gameserver.parser.impl.UserBasicActionsHolder.java

@PostConstruct
private void parse() throws IOException {
    log.info("Loading data file: userbasicaction.txt");
    Resource file = context.getResource("scripts/userbasicaction.txt");
    try (InputStream is = file.getInputStream()) {
        ANTLRInputStream input = new ANTLRInputStream(is);
        UserBasicActionsLexer lexer = new UserBasicActionsLexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        UserBasicActionsParser parser = new UserBasicActionsParser(tokens);

        ParseTree tree = parser.file();/*from w w  w.j a va  2 s .c  o m*/
        ParseTreeWalker walker = new ParseTreeWalker();
        walker.walk(this, tree);
    }
}

From source file:net.sf.springderby.IjSqlScriptExecutor.java

public void executeScript(Connection connection, Resource script, String encoding)
        throws SQLException, DataAccessException, IOException {
    InputStream in = script.getInputStream();
    try {/*ww w  .ja va  2  s.c o  m*/
        OutputStream out = new WriterOutputStream(new LoggerWriter(log), "UTF-8");
        try {
            // runScript returns the number of SQLExceptions thrown during the execution
            if (ij.runScript(connection, in, encoding, out, "UTF-8") > 0) {
                // TODO: this exception is no longer appropriate
                throw new SchemaCreationException("Script " + script.getFilename() + " executed with errors");
            }
        } finally {
            out.close();
        }
    } finally {
        in.close();
    }
}

From source file:org.jasig.portlet.campuslife.dao.ScreenScrapingDiningMenuDaoImplTest.java

@Test
public void testCleanHtml() throws ScanException, PolicyException, IOException {
    Resource menu = ctx.getResource("classpath:/yale-menu.html");
    String cleaned = service.getCleanedHtmlContent(IOUtils.toString(menu.getInputStream()));
}

From source file:com.medvision360.medrecord.engine.ArchetypeLoader.java

private void load(Resource resource) throws IOException, ParseException {
    InputStream is = resource.getInputStream();
    load(resource.getFilename().replaceFirst("\\.adl$", ""), is);
}

From source file:it.scoppelletti.sdk.schemaupdate.SpringResourceAccessor.java

/**
 * Restituisce il flusso di lettura di una risorsa.
 * //from  w w w  .  ja  v a 2 s .c  o m
 * @param  file Nome della risorsa.
 * @return      Flusso di lettura.
 */
public InputStream getResourceAsStream(String file) throws IOException {
    Resource res;

    try {
        res = getResource(file);
        return res.getInputStream();
    } catch (Exception ex) {
        // NOP
    }

    return null;
}

From source file:org.springframework.tuple.AbstractTupleMarshallerTests.java

public String readJson(Resource resource) throws IOException {
    Object jsonObject = mapper.readValue(resource.getInputStream(), Object.class);
    return mapper.writeValueAsString(jsonObject);
}

From source file:cz.cvut.zuul.samples.provider.FileQuotesDao.java

private List<Quote> loadQuotes(Resource file) throws IOException {
    List<Quote> list = new ArrayList<>(100);

    try (InputStream stream = file.getInputStream()) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream));

        String line;// ww w .jav a  2 s  .  c o m
        while ((line = reader.readLine()) != null) {
            list.add(parseLine(line));
        }
    }
    return list;
}

From source file:uk.ac.ebi.ricordo.rdfconverter.util.MappingExtractor.java

private void populateIdentMap(String mappingFile) {
    try {/*from   w  w w .  ja  va  2  s.  co m*/
        Resource resource = new ClassPathResource(mappingFile);
        BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream()));
        String line = null;
        while ((line = reader.readLine()) != null) {
            int splitPoint = line.lastIndexOf(" ");
            //String [] stringMap = line.split("|");
            identMap.put(line.substring(0, splitPoint), line.substring(splitPoint + 1));
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.textocat.textokit.commons.cpe.XmiCollectionReaderBase.java

public void getNext(CAS aCAS) throws IOException, CollectionException {
    Resource currentRes = resourcesIter.next();
    resourcesRead++;/*from w ww  .j av a2 s .com*/
    InputStream inputStream = currentRes.getInputStream();
    try {
        XmiCasDeserializer.deserialize(inputStream, aCAS, !mFailOnUnknownType);
    } catch (SAXException e) {
        throw new CollectionException(e);
    } finally {
        inputStream.close();
    }
}

From source file:CA.InternalCA.java

@Bean
public PrivateKey privateKey() throws IOException {
    //Get file from resources folder
    Resource resource = new ClassPathResource("certs/root/ca-key.pkcs8");
    return readPrivateKey(resource.getInputStream());
}