Example usage for org.apache.commons.io IOUtils readLines

List of usage examples for org.apache.commons.io IOUtils readLines

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils readLines.

Prototype

public static List readLines(Reader input) throws IOException 

Source Link

Document

Get the contents of a Reader as a list of Strings, one entry per line.

Usage

From source file:io.rhiot.utils.process.DefaultProcessManager.java

@Override
public List<String> executeAndJoinOutput(String... command) {
    try {//from  ww  w .java2 s .c om
        Process process = new ProcessBuilder().redirectErrorStream(true).command(command).start();
        return IOUtils.readLines(process.getInputStream());
    } catch (IOException e) {
        throw new ProcessExecutionException(e);
    }
}

From source file:com.presidentio.testdatagenerator.CsvFileTest.java

@Override
protected void testResult(Output output) {
    File file = new File(output.getProps().get("file"));
    try {//  w  w  w . java2 s  .  c  o  m
        List<String> csvFile = IOUtils.readLines(new FileInputStream(file));
        Assert.assertEquals(10 + 10 * 5 + 10 * 5 * 5 + 1 + 1 * 5 + 1 * 5 * 5, csvFile.size());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.adobe.acs.commons.redirectmaps.impl.RedirectEntriesUtils.java

protected static final List<String> readEntries(SlingHttpServletRequest request) throws IOException {
    List<String> lines = null;
    InputStream is = null;//from  ww  w  .  j av  a 2s.c o  m
    try {
        is = request.getResource().getChild(RedirectMapModel.MAP_FILE_NODE).adaptTo(InputStream.class);
        lines = IOUtils.readLines(is);
        log.debug("Loaded {} lines", lines.size());
    } finally {
        IOUtils.closeQuietly(is);
    }
    return lines;
}

From source file:de.tudarmstadt.ukp.dkpro.c4corpus.boilerplate.impl.Utils.java

/**
 * Loads the stop-words list of a given language
 *
 * @param locale locale//from  w ww. j av  a2s  .  c  o m
 * @return set of stop words
 * @throws IOException exception
 */
public static Set<String> loadStopWords(Locale locale) throws IOException {

    String streamName = "/stoplists/" + locale.getLanguage() + ".txt";
    InputStream stream = Utils.class.getResourceAsStream(streamName);

    if (stream == null) {
        throw new IOException("Stream " + streamName + " not found");
    }

    List<String> stopList = IOUtils.readLines(stream);
    return new HashSet<>(stopList);

}

From source file:com.t3.persistence.FileUtil.java

public static List<String> getLines(File file) throws IOException {
    List<String> list;
    try (FileReader reader = new FileReader(file)) {
        list = IOUtils.readLines(reader);
    }/*from   w ww  .j  a  v  a  2 s. co  m*/
    return list;
}

From source file:com.qualogy.qafe.bind.orm.jibx.JIBXExceptionTranslator.java

/**
 * Method to get the line JIBX complains about in its error message
 * Method resets the given inputstream to get a clear vision
 * @param e//from w w w .ja v a 2  s. co m
 * @param in
 * @return
 * @throws BindException - when IOException occurs reading inputstream
 */
public static String getLine(JiBXException exception, InputStream in) throws BindException {
    String line = null;

    try {
        in.reset();
    } catch (IOException e) {
        throw new BindException("Getting the original line failed", e);
    }
    if (exception.getMessage() != null) {
        String message = exception.getMessage();

        int start = message.indexOf(JIBX_LINE_INDICATION_START_MARK) + JIBX_LINE_INDICATION_START_MARK.length();
        if (start > -1) {
            int end = message.indexOf(JIBX_LINE_INDICATION_END_MARK, start);

            if (end > -1) {
                String lineNrStr = message.substring(start, end);
                if (NumberUtils.isNumber(lineNrStr)) {
                    int lineNr = Integer.parseInt(lineNrStr);

                    List lines = null;
                    try {
                        lines = IOUtils.readLines(in);
                    } catch (IOException e) {
                        throw new BindException("Getting the original line failed", e);
                    }
                    if (lines != null) {
                        line = (String) (lines.get(lineNr - 1));
                    }
                }
            }
        }
    }
    if (line != null)
        line = StringUtils.trimToEmpty(line);
    return line;
}

From source file:dbconverter.dao.util.Utils.java

/**
 * Method will take a File that contains SQL data and extract the data into
 * a String object that can be passed to a ResultSet object
 *
 * @param queryFileName//from   w  ww .  j ava2s.co m
 * @return String object from a SQL file
 */
public String readQueryFile(String queryFileName) {
    assert queryFileName != null : "queryFileName cannont be null";
    StringBuilder queryBuilder = new StringBuilder();
    String query = null;
    InputStream input = null;

    try {
        input = new FileInputStream(queryFileName);
        List<String> queryLines = new ArrayList<>();
        queryLines.clear();
        queryLines.addAll(IOUtils.readLines(input));

        if (!queryLines.isEmpty()) {
            for (String queryLine : queryLines) {
                queryBuilder.append(queryLine).append("\n");
            }
        }

    } catch (FileNotFoundException ex) {
        //Logger.getLogger(OracleDAO.class.getName()).log(Level.SEVERE, null, ex);
        logger.error(queryFileName + " could not be found", ex);
    } catch (IOException ioe) {
        logger.error("There was a problem with the file " + queryFileName, ioe);
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException ex) {
                logger.error("There was a problem with the file " + queryFileName, ex);
            }
        }
    }

    //InputStream input = new URL(queryFileName).openStream();
    query = queryBuilder.toString();
    return query;
}

From source file:com.tw.go.plugin.material.artifactrepository.yum.exec.command.ProcessRunner.java

public ProcessOutput execute(String[] command, Map<String, String> envMap) {
    ProcessBuilder processBuilder = new ProcessBuilder(command);
    Process process = null;/*from   w  w w .  j  a v a 2  s  .co  m*/
    ProcessOutput processOutput = null;
    try {
        processBuilder.environment().putAll(envMap);
        process = processBuilder.start();
        int returnCode = process.waitFor();
        List outputStream = IOUtils.readLines(process.getInputStream());
        List errorStream = IOUtils.readLines(process.getErrorStream());
        processOutput = new ProcessOutput(returnCode, outputStream, errorStream);
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage());
    } finally {
        if (process != null) {
            closeQuietly(process.getInputStream());
            closeQuietly(process.getErrorStream());
            closeQuietly(process.getOutputStream());
            process.destroy();
        }
    }
    return processOutput;
}

From source file:lyonlancer5.pfsteel.util.ModUpdater.java

@Override
public void run() {
    InputStream in = null;//from w ww.  j  a  va  2 s  .co  m
    try {
        in = new URL(urlUpdateFile).openStream();
        LL5_PerfectSteel.pfsLogger.info("Checking for updates...");
    } catch (Exception e) {
        LL5_PerfectSteel.pfsLogger
                .info("The update checker encountered an error while checking for updates : " + e.toString());
        return;
    }

    try {
        updateParams = IOUtils.readLines(in);
        latestVersion = Integer.parseInt(updateParams.get(0));
        latestVersionName = updateParams.get(2);
        forumThread = updateParams.get(3);
    } catch (Exception e) {
        LL5_PerfectSteel.pfsLogger
                .info("The update checker encountered an error while checking for updates : " + e.toString());
        return;
    } finally {
        IOUtils.closeQuietly(in);
    }

    LL5_PerfectSteel.pfsLogger.info("Got version info from GitHub - " + latestVersionName);
    isLatestVersion = ModVersion.getBuildNumber() == latestVersion;

    if (!isLatestVersion) {
        if (ModVersion.getBuildNumber() > latestVersion) {
            LL5_PerfectSteel.pfsLogger.info(
                    "The build number specified in this version is greater than the one specified on the update!");
            LL5_PerfectSteel.pfsLogger.info("Are you running a custom version?");
        } else {
            LL5_PerfectSteel.pfsLogger.info("There is a new update available!");
        }
    } else {
        LL5_PerfectSteel.pfsLogger.info("No updates available");
    }

    hasChecked = true;
}

From source file:com.buddycloud.mediaserver.business.jdbc.schema.Schema.java

@SuppressWarnings("unchecked")
public void runScript(MetaDataSource dataSource, String sqlFile)
        throws IOException, FileNotFoundException, SQLException {
    List<String> readLines = IOUtils.readLines(new FileInputStream(sqlFile));

    Connection connection = dataSource.getConnection();
    StringBuilder statementStr = new StringBuilder();

    for (String line : readLines) {
        statementStr.append(line);/*from w  w  w  .  j ava  2s  .c o m*/
        if (line.endsWith(SQL_DELIMITER)) {
            Statement statement = connection.createStatement();
            statement.execute(statementStr.toString());
            statement.close();
            statementStr.setLength(0);
        }
    }

    connection.close();
}