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:com.jaeksoft.searchlib.crawler.file.process.fileInstances.swift.SwiftProtocol.java

final public static List<String> listObjects(HttpDownloader httpDownloader, SwiftToken swiftToken,
        String container) throws URISyntaxException, ClientProtocolException, IllegalStateException,
        IOException, SearchLibException {
    final List<Header> headerList = swiftToken.getAuthTokenHeader(null);
    final URI uri = swiftToken.getContainerURI(container);
    DownloadItem downloadItem = httpDownloader.get(uri, null, headerList, null);
    downloadItem.checkNoErrorList(200, 204);
    InputStream inputStream = null;
    try {/*  w w  w.ja v  a  2s. c  om*/
        inputStream = downloadItem.getContentInputStream();
        if (inputStream != null)
            return IOUtils.readLines(inputStream);
        return null;
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}

From source file:com.alibaba.jstorm.utils.LinuxResource.java

public static double getTotalMemUsage() {
    if (!OSInfo.isLinux()) {
        return 0.0;
    }//from  w w w .  jav a2  s  .c  o m
    try {
        Map<String, String> memInfo = new HashMap<>();
        List<String> lines = IOUtils.readLines(new FileInputStream(PROCFS_MEMINFO));
        for (String line : lines) {
            String key = line.split("\\s+")[0];
            String value = line.split("\\s+")[1];
            memInfo.put(key, value);
        }
        String total = memInfo.get("MemTotal:");
        String free = memInfo.get("MemFree:");
        String buffer = memInfo.get("Buffers:");
        String cache = memInfo.get("Cached:");
        return 1 - (Double.valueOf(free) + Double.valueOf(buffer) + Double.valueOf(cache))
                / Double.valueOf(total);
    } catch (Exception ignored) {
        LOG.warn("failed to get total memory usage.", ignored);
    }
    return 0.0;
}

From source file:edu.ucsd.crbs.cws.cluster.submission.TestJobCmdScriptCreatorImpl.java

private File checkWorkflowFailed(final String outputsDir, final String simple, final String detailed)
        throws Exception {

    File failedFile = new File(outputsDir + File.separator + "WORKFLOW.FAILED.txt");

    assertTrue(failedFile.exists());/*from   w  w  w  . j a  va 2  s .  c  om*/

    List<String> lines = IOUtils.readLines(new FileReader(failedFile));
    boolean simpleFound = false;
    boolean detailedFound = false;
    for (String line : lines) {
        if (line.startsWith("simple.error.message")) {
            assertTrue(line, line.equals("simple.error.message=" + simple));
            simpleFound = true;
        }
        if (line.startsWith("detailed.error.message")) {
            assertTrue(line, line.equals("detailed.error.message=" + detailed));
            detailedFound = true;
        }
    }
    assertTrue(simpleFound);
    assertTrue(detailedFound);
    return failedFile;
}

From source file:de.tudarmstadt.ukp.dkpro.tc.svmhmm.writer.SVMHMMDataWriterTest.java

@Test
public void testMetDataFeatures() throws Exception {
    String longText = "rO0ABXNyABNqYXZhLnV0aWwuQXJyYXlMaXN0eIHSHZnHYZ0DAAFJAARzaXpleHAAAAAedwQAAAAedAABT3EAfgACcQB%2BAAJxAH4AAnEAfgACcQB%2BAAJxAH4AAnEAfgACcQB%2BAAJxAH4AAnEAfgACcQB%2BAAJxAH4AAnEAfgACcQB%2BAAJxAH4AAnEAfgACcQB%2BAAJxAH4AAnEAfgACcQB%2BAAJxAH4AAnEAfgACcQB%2BAAJxAH4AAnEAfgACcQB%2BAAJxAH4AAnEAfgACcQB%2BAAJ4";

    featureStore = new SparseFeatureStore();
    Feature f1 = new Feature(OriginalTextHolderFeatureExtractor.ORIGINAL_TEXT, "multi line \n text");
    Feature f2 = new Feature(SVMHMMDataWriter.META_DATA_FEATURE_PREFIX + "someFeature", longText);

    Instance instance = new Instance(Arrays.asList(f1, f2), "outcome");
    featureStore.addInstance(instance);/*from   ww w.  j a  va  2s.  c om*/

    SVMHMMDataWriter svmhmmDataWriter = new SVMHMMDataWriter();
    System.out.println(featureStore.getNumberOfInstances());
    svmhmmDataWriter.write(temporaryFolder.getRoot(), featureStore, false, null, false);

    File featureVectorsFile = new File(temporaryFolder.getRoot(), "feature-vectors.txt");
    List<String> lines = IOUtils.readLines(new FileInputStream(featureVectorsFile));
    System.out.println(lines);

    assertEquals("outcome",
            SVMHMMUtils.extractOutcomeLabelsFromFeatureVectorFiles(featureVectorsFile).iterator().next());

    assertEquals(Integer.valueOf(0),
            SVMHMMUtils.extractOriginalSequenceIDs(featureVectorsFile).iterator().next());

    SortedMap<String, String> metaDataFeatures = SVMHMMUtils.extractMetaDataFeatures(featureVectorsFile).get(0);

    assertTrue(metaDataFeatures.containsKey(SVMHMMDataWriter.META_DATA_FEATURE_PREFIX + "someFeature"));
    assertEquals(longText, metaDataFeatures.get(SVMHMMDataWriter.META_DATA_FEATURE_PREFIX + "someFeature"));

}

From source file:ml.shifu.shifu.core.binning.EqualPopulationBinningTest.java

@Test
public void testReturn180d() throws IOException {
    EqualPopulationBinning binning = new EqualPopulationBinning(10);
    List<String> usageList = IOUtils
            .readLines(new FileInputStream("src/test/resources/example/binning-data/return_lt_180d_amt.txt"));

    for (String data : usageList) {
        binning.addData(data);/*from w w  w . j a v a2s  . c om*/
    }

    List<Double> binBoundary = binning.getDataBin();
    Assert.assertTrue(binBoundary.size() > 1);
}

From source file:com.github.frapontillo.pulse.crowd.remstopword.simple.SimpleStopWordRemover.java

/**
 * Return the dictionary specified by a file name, building it if it wasn't built sooner.
 * If the dictionary cannot be built (maybe because files were missing or because files were
 * empty), no error is thrown, and the returned dictionary will simply be empty, thus removing
 * no words at all.//from w  ww  . j  a v  a2 s .c om
 *
 * @param fileName The name of the file referencing the dictionary (should exist in the
 *                 classpath resources).
 *
 * @return A {@link HashSet<String>} containing all of the dictionary terms.
 */
private HashSet<String> getDictionaryByFileName(String fileName) {
    if (!dictionaries.containsKey(fileName)) {
        HashSet<String> newDictionary = new HashSet<>();

        try {
            List<String> lines = IOUtils.readLines(getClass().getClassLoader().getResourceAsStream(fileName));
            lines = lines.stream().map(String::toLowerCase).collect(Collectors.toList());
            newDictionary.addAll(lines);
        } catch (Exception ignored) {
        }

        dictionaries.put(fileName, newDictionary);
    }
    return dictionaries.get(fileName);
}

From source file:eu.europa.ejusticeportal.dss.controller.action.SealedPDFService.java

/**
 * Gets the password for the server seal p12 file
 * /*ww w.j a v  a 2  s  . c  om*/
 * @return the password
 */
private String getPassword() {
    String password = null;
    InputStream is = getInputStream(PASSWORD_FILE_PROPERTY);
    try {
        List<String> lines = IOUtils.readLines(is);
        if (lines.size() != 0) {
            String b64Password = lines.get(0);
            password = new String(Base64.decodeBase64(b64Password), "UTF-8");
        } else {
            throw new DssInitialisationException("The password is not in the file.");
        }
    } catch (Exception e) {
        throw new DssInitialisationException(
                "Error getting the password for the server seal - please set -D" + PASSWORD_FILE_PROPERTY, e);
    } finally {
        IOUtils.closeQuietly(is);
    }
    return password;
}

From source file:com.nridge.connector.common.con_com.transform.TFieldDelete.java

private void load(String aPathFileName) throws IOException {
    List<String> lineList;
    Logger appLogger = mAppMgr.getLogger(this, "load");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    try (FileReader fileReader = new FileReader(aPathFileName)) {
        lineList = IOUtils.readLines(fileReader);
    }//from  w w w  . j a  v  a  2s  . c o  m

    for (String patternString : lineList) {
        if (!StringUtils.startsWith(patternString, "#"))
            mPatternList.add(patternString);
    }

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);
}

From source file:com.flexdms.htmltemplate.HtmlTemplateMojo.java

protected void transformFile(String fileName, File base, Writer writer, String template, List<String> modules)
        throws FileNotFoundException, IOException {
    String name = FilenameUtils.normalizeNoEndSeparator(fileName, true);
    getLog().info("process " + name);

    List<String> lines = IOUtils.readLines(new FileReader(new File(base, fileName)));
    StringBuilder sb = new StringBuilder();
    if (process) {
        sb.append("\"\"");
    }// www . j  ava  2s  .  c  o m

    for (String line : lines) {
        if (process) {
            String newline = "+\"" + line.replace("\"", "\\\"") + "\"\n";
            sb.append(newline);
        } else {
            sb.append(line);
            sb.append("\n");
        }

    }

    String r1 = template.replace("@@@@name@@@@", name);
    String r2 = r1.replace("@@@@text@@@@", sb.toString());

    modules.add(name);

    writer.write("\n\n" + r2);

}

From source file:com.nridge.connector.common.con_com.crawl.CrawlFollow.java

/**
 * Parses a file identified by the path/file name parameter
 * and loads it into an internally managed follow URI list.
 *
 * @param aPathFileName Absolute file name (e.g. 'crawl_follow.txt').
 *
 * @throws IOException I/O related exception.
 *//*from   w w  w .j ava 2  s  .  c o m*/
public void load(String aPathFileName) throws IOException {
    List<String> lineList;
    Logger appLogger = mAppMgr.getLogger(this, "load");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    try (FileReader fileReader = new FileReader(aPathFileName)) {
        lineList = IOUtils.readLines(fileReader);
    }

    for (String followString : lineList) {
        if (!StringUtils.startsWith(followString, "#"))
            mFollowList.add(followString);
    }

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);
}