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:au.org.ala.delta.directives.ItemDescriptionsTest.java

private String getConforResoure(String name) throws Exception {
    InputStream is = ItemDescriptionsTest.class.getResourceAsStream(String.format("/confor/%s", name));
    return StringUtils.join(IOUtils.readLines(is), "\n");
}

From source file:de.tudarmstadt.lt.utilities.annotators.StopwordTokenFilter.java

@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
    super.initialize(context);
    _stopwords = new HashSet<String>();
    LOG.debug("Stopword file: {}.", _stopwordsfile);
    if (_stopwordsfile != null) {
        LOG.info("Reading stopword file: {}.)", new File(_stopwordsfile.getFile()).getAbsolutePath());
        // if (!(_stopwordsfile.exists() && _stopwordsfile.isFile())) {
        // // TODO: maintain default stopword list in classpath
        // }/*from w ww . j av a  2  s  .c om*/
        try {
            for (String line : IOUtils.readLines(new FileReader(_stopwordsfile.getFile())))
                _stopwords.add(line.trim().toLowerCase());
        } catch (Throwable t) {
            for (int i = 0; t != null; i++) {
                LOG.error(String.format("Failed to read stopword file: %s (%d-%s: %s).)", _stopwordsfile, i,
                        t.getClass().getName(), t.getMessage()), t);
                t = t.getCause();
            }
            _stopwords = Collections.emptySet();
        }
    }
}

From source file:com.haulmont.yarg.formatters.impl.doc.connector.WinProcessManager.java

@Override
@SuppressWarnings("unchecked")
public List<Long> findPid(String host, int port) {
    try {/*  w  w  w.  j  a  va 2s  . c  o  m*/
        if ("localhost".equalsIgnoreCase(host))
            host = LOCAL_HOST;
        Process process = Runtime.getRuntime().exec(String.format(FIND_PID_COMMAND, port));
        List r = IOUtils.readLines(process.getInputStream());
        for (Object output : r) {
            NetStatInfo info = new NetStatInfo((String) output);
            if (info.localPort == port && ObjectUtils.equals(host, info.localAddress))
                return Collections.singletonList(info.pid);
        }
    } catch (IOException e) {
        log.warn(String.format("Unable to find PID for OO process on host:port  %s:%s", host, port), e);
    }
    log.warn(String.format("Unable to find PID for OO process on host:port %s:%s", host, port));
    return Collections.singletonList(PID_UNKNOWN);
}

From source file:com.msopentech.odatajclient.engine.communication.ODataClientErrorException.java

/**
 * Constructor./*from w w w  .  ja v a  2s .c  o m*/
 *
 * @param statusLine request status info.
 * @param error OData error to be wrapped.
 */
public ODataClientErrorException(final StatusLine statusLine, final ODataError error) {
    super((StringUtils.isBlank(error.getCode()) ? StringUtils.EMPTY : "(" + error.getCode() + ") ")
            + error.getMessageValue() + " [" + statusLine.toString() + "]");

    this.statusLine = statusLine;
    this.error = error;

    if (this.error.getInnerErrorType() != null && this.error.getInnerErrorMessage() != null) {
        final RuntimeException cause = new RuntimeException(
                this.error.getInnerErrorType() + ": " + this.error.getInnerErrorMessage());

        if (this.error.getInnerErrorStacktrace() != null) {
            List<String> stLines;
            try {
                stLines = IOUtils.readLines(new StringReader(this.error.getInnerErrorStacktrace()));
            } catch (IOException e) {
                stLines = Collections.<String>emptyList();
            }
            StackTraceElement[] stElements = new StackTraceElement[stLines.size()];
            for (int i = 0; i < stLines.size(); i++) {
                final String stLine = stLines.get(i).substring(stLines.get(i).indexOf("at ") + 3);
                final int lastDotPos = stLine.lastIndexOf('.');
                stElements[i] = new StackTraceElement(stLine.substring(0, lastDotPos),
                        stLine.substring(lastDotPos + 1), null, 0);
            }
            cause.setStackTrace(stElements);
        }

        initCause(cause);
    }
}

From source file:com.splunk.shuttl.rest.ShuttlServerRestTest.java

private List<String> getLinesFromResponse(HttpResponse response) throws IOException {
    return IOUtils.readLines(response.getEntity().getContent());
}

From source file:com.backelite.sonarqube.objectivec.issues.oclint.OCLintRulesDefinition.java

private void loadRules(NewRepository repository) throws IOException {

    Reader reader = new BufferedReader(
            new InputStreamReader(getClass().getResourceAsStream(RULES_FILE), CharEncoding.UTF_8));

    final List<String> listLines = IOUtils.readLines(reader);

    String previousLine = null;//www  .java 2 s  .  c  o  m
    Map<String, String> rule = new HashMap<String, String>();
    boolean inDescription = false;
    for (String line : listLines) {

        if (isLineIgnored(line)) {
            inDescription = false;

        } else if (line.matches("[\\-]{4,}.*")) {
            LOGGER.debug("Rule found : {}", previousLine);

            // Remove the rule name from the description of the previous
            // rule
            if (rule.get("description") != null) {
                String description = rule.get("description").toString();
                final int index = description.lastIndexOf(previousLine);
                if (index > 0) {
                    rule.put("description", description.substring(0, index));
                }

            }

            rule.clear();

            rule.put("name", StringUtils.capitalize(previousLine));
            rule.put("key", previousLine);

        } else if (line.matches("Summary:.*")) {
            inDescription = true;
            rule.put("description", line.substring(line.indexOf(':') + 1));
        } else if (line.matches("Category:.*")) {
            inDescription = true;

            // Create rule when last filed found
            RulesDefinition.NewRule newRule = repository.createRule(rule.get("key").toString());
            newRule.setName(rule.get("name").toString());
            newRule.setSeverity(rule.get("severity").toString());
            newRule.setHtmlDescription(rule.get("description").toString());

        } else if (line.matches("Severity:.*")) {
            inDescription = false;
            final String severity = line.substring("Severity: ".length());
            rule.put("severity", OCLintRuleSeverity.valueOfInt(Integer.valueOf(severity)).name());
        } else {
            if (inDescription) {
                line = ruleDescriptionLink(line);
                String description = (String) rule.get("description");
                rule.put("description", description + "<br>" + line);
            }
        }

        previousLine = line;
    }

}

From source file:com.github.DataLoader.java

public static Set<Watcher> loadPredictings() throws IOException {
    final Set<Watcher> ret = new HashSet<Watcher>();

    for (final Object o : IOUtils
            .readLines(DataLoader.class.getClassLoader().getResourceAsStream("data/test.txt"))) {
        final String line = (String) o;

        ret.add(new Watcher(line.trim()));
    }/*from ww  w . ja v  a 2  s .  c  o m*/

    return ret;
}

From source file:hudson.plugins.sauce_ondemand.SauceOnDemandReportPublisher.java

@Override
public SauceOnDemandReportFactory getTestData(AbstractBuild<?, ?> build, Launcher launcher,
        BuildListener buildListener, TestResult testResult) throws IOException, InterruptedException {

    buildListener.getLogger().println("Scanning for Sauce OnDemand test data...");
    List<String> lines = IOUtils.readLines(build.getLogReader());
    String[] array = lines.toArray(new String[lines.size()]);
    List<String[]> sessionIDs = new ArrayList<String[]>();
    List<CaseResult> caseResults = new ArrayList<CaseResult>();
    for (SuiteResult sr : testResult.getSuites()) {
        for (CaseResult cr : sr.getCases()) {
            caseResults.add(cr);//from  w w  w . j av a 2  s  .co m
            sessionIDs.addAll(SauceOnDemandReportFactory.findSessionIDs(cr, cr.getStdout(), cr.getStderr()));
        }
    }
    if (sessionIDs.isEmpty()) {
        sessionIDs.addAll(SauceOnDemandReportFactory.findSessionIDsForCaseResults(caseResults, array));
    }

    SauceOnDemandBuildAction buildAction = getBuildAction(build);
    if (buildAction == null) {
        logger.log(Level.WARNING, "Unable to retrieve Sauce Build Action for build: " + build.toString());
        buildListener.getLogger().println("Unable to retrieve the Sauce Build Action, attempting to continue");
    } else {
        SauceREST sauceREST = new JenkinsSauceREST(buildAction.getUsername(), buildAction.getAccessKey());
        for (String[] id : sessionIDs) {
            try {
                String json = sauceREST.getJobInfo(id[0]);
                JSONObject jsonObject = new JSONObject(json);
                Map<String, Object> updates = new HashMap<String, Object>();
                //only store passed/name values if they haven't already been set
                if (jsonObject.get("passed").equals(JSONObject.NULL) && id.length == 3) {
                    updates.put("passed", id[2]);
                }
                if (jsonObject.get("name").equals(JSONObject.NULL)) {
                    updates.put("name", id[1]);
                }
                if (jsonObject.get("build").equals(JSONObject.NULL)) {
                    String buildNumber = SauceOnDemandBuildWrapper.sanitiseBuildNumber(build.toString());
                    if (build instanceof MavenBuild) {
                        //try the parent
                        buildNumber = SauceOnDemandBuildWrapper
                                .sanitiseBuildNumber(((MavenBuild) build).getParentBuild().toString());
                    }
                    updates.put("build", buildNumber);
                }
                if (!updates.isEmpty()) {
                    sauceREST.updateJobInfo(id[0], updates);
                }
            } catch (JSONException e) {
                buildListener.error("Error while updating job " + id[0] + " message: " + e.getMessage());
            }
        }
    }
    buildListener.getLogger().println("Finished scanning for Sauce OnDemand test data...");
    if (sessionIDs.isEmpty()) {
        buildListener.getLogger().println(
                "The Sauce OnDemand plugin is configured, but no session IDs were found in the test output.");
        return null;
    } else {
        return SauceOnDemandReportFactory.INSTANCE;
    }
}

From source file:com.firewallid.crawling.FacebookIDSearch.java

public void uploadKeywords(JavaSparkContext jsc) throws IOException {
    int partitions = conf.getInt(PARTITIONS, 48);

    /* load training data */
    List<String> resource = IOUtils
            .readLines(getClass().getClassLoader().getResourceAsStream(conf.get(KEYWORDS)));

    Broadcast<List<String>> broadcastRes = jsc.broadcast(resource);

    JavaRDD<String> doc = jsc.parallelize(broadcastRes.value()).persist(StorageLevel.MEMORY_AND_DISK_SER_2())
            .repartition(partitions);//from   w  ww  .j  av a 2s . c  o  m

    save(doc);
}

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

@Override
public AbstractHandler getServerProxyHandler() {
    return new AbstractHandler() {
        @Override/* www  . jav  a 2  s  .c om*/
        public void handle(String target, Request baseRequest, HttpServletRequest request,
                HttpServletResponse response) throws IOException {
            // Read all of the request.
            IOUtils.readLines(request.getInputStream());

            response.setContentType("multipart/mixed");
            response.setContentLength(1000);
            response.setHeader(HEADER_HASH_ALGO_ID, DEFAULT_DIGEST_ALGORITHM_ID);
            baseRequest.setHandled(true);
        }
    };
}