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:de.unidue.inf.is.ezdl.dlcore.utils.PersonNameMatcherRuleBase.java

private void initFromFile() throws IOException {
    InputStream is = this.getClass().getResourceAsStream("/names.equiv");
    if (is == null) {
        throw new IOException();
    }// w ww .ja va 2 s . c  o  m

    List<String> lines = IOUtils.readLines(is);
    initFromLines(lines);
}

From source file:com.conversantmedia.mapreduce.example.WordCountWithBlacklistMapper.java

@Override
public void setup(Context context) throws IOException {
    blacklistedWords = new HashSet<>();
    if (blacklist != null) {
        InputStreamReader reader = null;
        try {/*  w  w w. ja  v a2  s.  com*/
            reader = new FileReader(blacklist.toUri().getPath());
            for (String line : IOUtils.readLines(reader)) {
                blacklistedWords.add(line);
            }
        } finally {
            IOUtils.closeQuietly(reader);
        }
    }
}

From source file:com.galenframework.parser.IndentationStructureParser.java

public List<StructNode> parse(InputStream stream, String source) throws IOException {
    Stack<IndentationNode> nodeStack = new Stack<IndentationNode>();

    StructNode rootNode = new StructNode();
    nodeStack.push(new IndentationNode(-1, rootNode, null));

    List<String> lines = IOUtils.readLines(stream);

    int lineNumber = 0;
    for (String line : lines) {
        lineNumber++;/*from  w ww . ja v a  2s  . c  o m*/
        if (isProcessable(line)) {
            processLine(nodeStack, line, lineNumber, source);
        }
    }

    return rootNode.getChildNodes();
}

From source file:mitm.common.util.MetaReaderTest.java

@SuppressWarnings("unchecked")
@Test//from   ww  w  . j a  v  a 2  s .c o  m
public void testMetaReader() throws IOException {
    File file1 = new File(base, "other/ends-with-lf.txt");
    File file2 = new File(base, "other/ends-with-text.txt");

    Collection<Reader> readers = new LinkedList<Reader>();

    readers.add(new FileReader(file1));
    readers.add(new FileReader(file2));

    Reader metaReader = new MetaReader(readers);

    List<String> lines = IOUtils.readLines(metaReader);

    assertEquals(15, lines.size());
    assertEquals("123", lines.get(14));

    metaReader.close();
}

From source file:com.junoyoon.BullsUtil.java

/**
 * Run command and/*from ww  w  .jav a  2s. c  om*/
 * 
 * @param cmd
 * @return
 * @throws IOException
 */
public static String getCmdOutput(List<String> cmd) throws IOException {
    ProcessBuilder builder = new ProcessBuilder();
    builder.command().addAll(cmd);
    builder.redirectErrorStream(true);
    StringBuilder result = new StringBuilder(1024);
    Process proc = builder.start();
    boolean firstLine = true;
    for (Object eachLineObject : IOUtils.readLines(proc.getInputStream())) {
        String eachLine = (String) eachLineObject;
        if (firstLine) {
            eachLine = eachLine.replace("charset=us-ascii", "charset=" + Constant.DEFAULT_ENCODING);
            firstLine = false;
        }
        result.append(eachLine).append("\n");
    }
    return result.toString();
}

From source file:com.edduarte.argus.stopper.FileStopper.java

private boolean load(String language) {
    File stopwordsFile = new File(Constants.STOPWORDS_DIR, language + ".txt");
    if (stopwordsFile.exists()) {
        try (InputStream is = new FileInputStream(stopwordsFile); Parser parser = new SimpleParser()) {

            Set<MutableString> stopwordsAux = new HashSet<>();
            List<String> lines = IOUtils.readLines(is);
            lines.forEach(line -> {//ww w . ja  v  a 2 s.com
                line = line.trim().toLowerCase();
                if (!line.isEmpty()) {
                    int indexOfPipe = line.indexOf('|');

                    MutableString stopwordLine;
                    if (indexOfPipe == -1) {
                        // there are no pipes in this line
                        // -> add the whole line as a stopword
                        stopwordLine = new MutableString(line);

                    } else if (indexOfPipe > 0) {
                        // there is a pipe in this line and it's not the first char
                        // -> add everything from index 0 to the pipe's index
                        String word = line.substring(0, indexOfPipe).trim();
                        stopwordLine = new MutableString(word);
                    } else {
                        return;
                    }

                    Set<MutableString> stopwordsAtLine = parser.parse(stopwordLine).parallelStream()
                            .map(sw -> sw.text).collect(Collectors.toSet());
                    stopwordsAux.addAll(stopwordsAtLine);
                }
            });

            stopwords = ImmutableSet.copyOf(stopwordsAux);
            return true;

        } catch (IOException e) {
            logger.error("There was a problem loading the stopword file.", e);
            stopwords = Collections.emptySet();
        }
    }

    return false;
}

From source file:edu.cornell.mannlib.vitro.webapp.rdfservice.impl.ModelChangeImpl.java

private String streamToString(InputStream stream) {
    if (!stream.markSupported()) {
        return String.valueOf(stream);
    }//from  w w  w .  ja  v a2 s.com
    try {
        stream.mark(Integer.MAX_VALUE);
        List<String> lines = IOUtils.readLines(stream);
        stream.reset();
        return String.valueOf(lines);
    } catch (IOException e) {
        return "Failed to read input stream: " + e;
    }
}

From source file:cz.pichlik.goodsentiment.server.handler.EventAggregatorTest.java

@Test
public void resultCSVHasHeader() throws Exception {
    File resultFile = aggregateSingle();
    try (FileReader fr = new FileReader(resultFile)) {
        List<String> result = IOUtils.readLines(fr);
        assertThat("Missing the CSV header", result,
                hasItem("id,sentimentCode,orgUnit,latitude,longitude,city,gender,yearsInCompany,timestamp"));
    }/* w  w w  . j  a  v a2 s . c  o  m*/
}

From source file:ee.ria.xroad.proxy.testsuite.testcases.ServerProxyConnectionAborted2.java

@Override
public AbstractHandler getServerProxyHandler() {
    return new AbstractHandler() {
        @Override// w w  w.ja va 2 s  .c  o  m
        public void handle(String target, Request baseRequest, HttpServletRequest request,
                HttpServletResponse response) throws IOException {
            // Read all of the request.
            IOUtils.readLines(request.getInputStream());

            response.setContentType("text/xml");
            response.setContentLength(1000);
            response.getOutputStream().close();
            response.flushBuffer();
            baseRequest.setHandled(true);
        }
    };
}

From source file:com.amalto.core.storage.hibernate.StorageTableResolver.java

public StorageTableResolver(Set<FieldMetadata> indexedFields, int maxLength) {
    this.indexedFields = indexedFields;
    this.maxLength = maxLength;
    // Loads reserved SQL keywords.
    synchronized (MappingGenerator.class) {
        if (reservedKeyWords == null) {
            reservedKeyWords = new TreeSet<String>();
            InputStream reservedKeyWordsList = this.getClass().getResourceAsStream(RESERVED_SQL_KEYWORDS);
            try {
                if (reservedKeyWordsList == null) {
                    throw new IllegalStateException("File '" + RESERVED_SQL_KEYWORDS + "' was not found.");
                }/*  w w w .ja  v  a2 s.  c o  m*/
                List list = IOUtils.readLines(reservedKeyWordsList);
                for (Object o : list) {
                    reservedKeyWords.add(String.valueOf(o));
                }
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Loaded " + reservedKeyWords.size() + " reserved SQL key words.");
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                try {
                    if (reservedKeyWordsList != null) {
                        reservedKeyWordsList.close();
                    }
                } catch (IOException e) {
                    LOGGER.error("Error occurred when closing reserved keyword list.", e);
                }
            }
        }
    }
}