Example usage for java.io BufferedReader ready

List of usage examples for java.io BufferedReader ready

Introduction

In this page you can find the example usage for java.io BufferedReader ready.

Prototype

public boolean ready() throws IOException 

Source Link

Document

Tells whether this stream is ready to be read.

Usage

From source file:org.talend.components.api.component.runtime.DependenciesReader.java

/**
 * reads a stream following the maven-dependency-plugin plugin :list format
 * /*  www.j  av a  2  s .  c o  m*/
 * <pre>
* {@code
        
The following files have been resolved:
org.apache.maven:maven-core:jar:3.3.3:compile
org.springframework:spring-beans:jar:4.2.0.RELEASE:test
org.talend.components:components-common:jar:0.4.0.BUILD-SNAPSHOT:compile
log4j:log4j:jar:1.2.17:test
org.eclipse.aether:aether-impl:jar:1.0.0.v20140518:compile
   * }
 * </pre>
 * 
 * and return a list of mvn url strings following the <a href="https://ops4j1.jira.com/wiki/display/paxurl/Mvn+Protocol"
 * >pax-urm mvn</a> protocol
 * .<br>
 * this will ignore test dependencies.
 * 
 * 
 * 
 * @param depStream of the dependencies file
 * @return a list of maven url strings
 * @throws IOException if read fails.
 */
public Set<String> parseDependencies(InputStream depStream) throws IOException {
    Set<String> mvnUris = new HashSet<>();
    BufferedReader reader = new BufferedReader(new InputStreamReader(depStream, "UTF-8"));
    // java 8 version
    // reader.lines().filter(line -> StringUtils.countMatches(line, ":") > 3).//
    // filter(line -> !line.endsWith("test")).//
    // forEach(line -> mvnUris.add(parseMvnUri(line)));
    while (reader.ready()) {
        String line = reader.readLine();
        if ((org.apache.commons.lang3.StringUtils.countMatches(line, ":") > 3) && !line.endsWith("test")) {
            mvnUris.add(parseMvnUri(line));
        } // else not an expected dependencies so ignor it.
    }
    return mvnUris;
}

From source file:org.jboss.jdf.stack.test.StacksTest.java

@Test
public void testIdEqualsYamlLink() throws IOException {
    log.info("Testing if Ids are equals YAML links");
    BufferedReader br = new BufferedReader(new FileReader(stacksFile));
    try {//from  w  w w .  j a  va2 s  .co  m
        String id = null;
        while (br.ready()) {
            String line = br.readLine();
            if (line.contains("&")) {
                int pos = line.indexOf('&') + 1;
                id = line.substring(pos, line.length()).trim();
            }
            if (id != null && line.contains("id:")) {
                int pos = line.lastIndexOf("id: ") + 3;
                String value = line.substring(pos, line.length()).trim();
                Assert.assertEquals("Id and Value should have the same value", id, value);
            }
        }

    } finally {
        if (br != null) {
            br.close();
        }
    }
}

From source file:edu.cornell.mannlib.vedit.tags.DynamicFieldsTag.java

public void parseMarkup() throws JspException {
    try {/*ww w.  j ava  2 s .  c  o m*/

        int preStart = -1;
        int templateStart = -1;
        int postStart = -1;

        InputStream fis = new FileInputStream(pageContext.getServletContext().getRealPath(new String())
                + PATH_SEP + MARKUP_FILE_PATH + usePage);
        InputStream bis = new BufferedInputStream(fis);
        BufferedReader in = new BufferedReader(new InputStreamReader(bis));
        List<String> lines = new ArrayList<String>();
        lines.add(""); // 0th line
        int lineIndex = 0;
        while (in.ready()) {
            ++lineIndex;
            String currentLine = in.readLine();
            if (currentLine != null && currentLine.indexOf("<!--") == 0 && currentLine.indexOf("@pre") > 0) {
                preStart = lineIndex;
            } else if (currentLine != null && currentLine.indexOf("<!--") == 0
                    && currentLine.indexOf("@template") > 0) {
                templateStart = lineIndex;
            } else if (currentLine != null && currentLine.indexOf("<!--") == 0
                    && currentLine.indexOf("@post") > 0) {
                postStart = lineIndex;
            }
            lines.add(currentLine);
        }
        in.close();

        StringBuffer preMarkupB = new StringBuffer();
        StringBuffer postMarkupB = new StringBuffer();
        StringBuffer templateMarkupB = new StringBuffer();

        if (templateStart > preStart && preStart > 0) {
            for (int i = preStart + 1; i < templateStart; i++) {
                preMarkupB.append(lines.get(i)).append("\n");
            }
        } else {
            System.out.println("DynamicFieldsTag could not find @pre markup in " + MARKUP_FILE_PATH + usePage);
            throw new JspException("DynamicFieldsTag could not parse @pre markup section");
        }
        preMarkup = preMarkupB.toString();

        if (postStart > templateStart && templateStart > 0) {
            for (int i = templateStart + 1; i < postStart; i++) {
                templateMarkupB.append(lines.get(i)).append("\n");
            }
        } else {
            System.out.println(
                    "DynamicFieldsTag could not find @template markup in " + MARKUP_FILE_PATH + usePage);
            throw new JspException("DynamicFieldsTag could not parse @template markup section");
        }
        templateMarkup = templateMarkupB.toString();

        if (postStart > 0) {
            for (int i = postStart + 1; i < lines.size(); i++) {
                postMarkupB.append(lines.get(i)).append("\n");
            }
        } else {
            System.out.println("DynamicFieldsTag could not find @post markup in " + MARKUP_FILE_PATH + usePage);
            throw new JspException("DynamicFieldsTag could not parse @post markup section");
        }
        postMarkup = postMarkupB.toString();

    } catch (FileNotFoundException e) {
        System.out.println("DynamicFieldsTag could not find markup file at "
                + pageContext.getServletContext().getRealPath(new String()) + "\\" + MARKUP_FILE_PATH
                + usePage);
    } catch (IOException ioe) {
        System.out.println("DynamicFieldsTag encountered IOException reading "
                + pageContext.getServletContext().getRealPath(new String()) + "\\" + MARKUP_FILE_PATH
                + usePage);
    }

}

From source file:org.alloy.metal.xml.merge.MergeContext.java

private void removeSkippedMergeComponents(Properties props) {
    InputStream inputStream = this.getClass().getClassLoader()
            .getResourceAsStream("/broadleaf-commmerce/skipMergeComponents.txt");

    if (inputStream != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("mergeClassOverrides file found.");
        }//from  www .  j  av  a2  s  .c o m

        final InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        final BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

        try {
            while (bufferedReader.ready()) {
                String line = bufferedReader.readLine();
                if (LOG.isDebugEnabled()) {
                    LOG.debug("mergeComponentOverrides - overridding " + line);
                }
                removeSkipMergeComponents(props, line);
            }
        } catch (IOException e) {
            LOG.error("Error reading resource - /broadleaf-commmerce/skipMergeComponents.txt", e);
        } finally {
            try {
                bufferedReader.close();
            } catch (IOException ioe) {
                LOG.error("Error closing resource - /broadleaf-commmerce/skipMergeComponents.txt", ioe);
            }
        }
    }
}

From source file:de.gesundkrank.wikipedia.hadoop.parser.Parser.java

public WikiRevisionWritable readNextRevision(BufferedReader in) throws IOException {
    resetMarkers();//from   www . jav  a2 s.  com

    revision = new WikiRevisionWritable(currentPage);

    while (in.ready()) {
        String line = in.readLine();

        boolean isPageStart = line.trim().startsWith(PAGE_START);

        if (currentPage == null && !isPageStart) {
            continue;
        }

        if (isPageStart) {
            readNextPage(in);
            revision.setPage(currentPage);
        }

        if (readRevisionId(line) || readTimeStamp(line) || readContributor(line, in) || readComment(line)
                || readMinor(line) || readText(line, in)) {
            continue;
        }

        Matcher revisionEndMatcher = REVISION_END_PATTERN.matcher(line);
        if (revisionEndMatcher.matches()) {
            break;
        }
    }

    return revision;
}

From source file:org.blocks4j.reconf.infra.http.layer.SimpleHttpResponse.java

private void consumeBody() {
    if (response.getEntity() == null) {
        body = StringUtils.EMPTY;/*w ww  .ja  va 2  s  . co m*/
    }

    HttpEntity entity = response.getEntity();
    String encoding = getContentEncoding(entity);
    String charset = getContentCharSet(entity);

    try {
        if ("gzip".equalsIgnoreCase(encoding)) {
            GzipDecompressingEntity gzip = new GzipDecompressingEntity(entity);
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            gzip.writeTo(output);
            body = output.toString(charset);

        } else {
            BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent(), charset));
            StringBuilder result = new StringBuilder();
            String line;

            while ((line = reader.readLine()) != null) {
                result.append(line);
                if (reader.ready()) {
                    result.append(LineSeparator.value());
                }
            }
            body = result.toString();
        }
    } catch (Exception e) {
        exception = e;

    } finally {
        try {
            EntityUtils.consume(entity);
        } catch (Exception e) {
            exception = e;
        }
    }
}

From source file:net.geoprism.localization.LocaleManager.java

private Collection<Locale> loadDatepickers() {
    try {// w w  w  .ja v  a  2 s .  com
        // Get the list of known CLDR locale
        Set<Locale> locales = new HashSet<Locale>();

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(this.getClass().getResourceAsStream("/datepickerLocales.txt")));

        try {
            while (reader.ready()) {
                String locale = reader.readLine();

                locales.add(LocaleManager.getLocaleForName(locale));
            }

            return locales;

        } finally {
            reader.close();
        }
    } catch (Exception e) {
        throw new ProgrammingErrorException(e);
    }
}

From source file:org.n52.ses.common.environment.SESMiniServlet.java

private void provideLandingPage(HttpServletRequest req, HttpServletResponse resp, ConfigurationRegistry conf)
        throws IOException, UnsupportedEncodingException {
    /*//  w  w  w.ja va 2 s .  c om
     * return landing page
     */
    if (this.landingPage != null) {
        resp.setContentType("text/html");
        synchronized (this) {
            printResponse(req, resp, this.landingPage);
        }

        return;
    }

    InputStreamReader isr = new InputStreamReader(getClass().getResourceAsStream("/landing_page.html"));
    BufferedReader br = new BufferedReader(isr);
    StringBuilder sb = new StringBuilder();

    while (br.ready()) {
        sb.append(br.readLine());
    }
    String html = sb.toString();

    String reqUrl = URLDecoder.decode(req.getRequestURL().toString(),
            (req.getCharacterEncoding() == null ? Charset.defaultCharset().name()
                    : req.getCharacterEncoding()));
    html = html.replace("[SES_URL]",
            reqUrl.substring(0, reqUrl.indexOf(req.getContextPath())) + req.getContextPath());

    /*
     * check if we are init yet
     */
    String sesPortTypeUrl, subMgrUrl, prmUrl = "";
    if (conf != null) {
        String defaulturi = conf.getEnvironment().getDefaultURI().substring(0,
                conf.getEnvironment().getDefaultURI().lastIndexOf("/services"));
        sesPortTypeUrl = defaulturi + "/services/" + SESNotificationProducer.CONTEXT_PATH;
        subMgrUrl = defaulturi + "/services/" + SESSubscriptionManager.CONTEXT_PATH;
        prmUrl = defaulturi + "/services/" + RegisterPublisher.RESOURCE_TYPE;

        conf.setSubscriptionManagerWsdl(subMgrUrl + "?wsdl");

        html = html.replace("<p id=\"ses-status\"><p>",
                "<p style=\"color:#0f0\">The service is active and available.</p>");

        html = html.replace("[GET_CAPS]",
                StringEscapeUtils.escapeHtml4(StartupInitServlet.getGetCapabilitiesRequest(sesPortTypeUrl)));
        /*
         * replace the url
         */
        synchronized (this) {
            if (this.landingPage == null) {
                this.landingPage = html.replace("[SES_PORT_TYPE_URL]", sesPortTypeUrl);
                this.landingPage = this.landingPage.replace("[SUB_MGR_URL]", subMgrUrl);
                this.landingPage = this.landingPage.replace("[PRM_URL]", prmUrl);

                resp.setContentType("text/html");
                printResponse(req, resp, this.landingPage);
            }

        }

    } else {
        /*
         * we do not have the config, warn the user
         */
        html = html.replace("<p id=\"ses-status\"><p>",
                "<p style=\"color:#f00\">The service is currently not available due to unfinished or failed initialization.</p>");

        resp.setContentType("text/html");
        printResponse(req, resp, html);
    }
}

From source file:org.opennms.systemreport.AbstractSystemReportPlugin.java

protected Map<String, String> splitMultilineString(final String regex, final String text) {
    final Map<String, String> map = new HashMap<String, String>();

    if (text != null) {
        final StringReader sr = new StringReader(text);
        final BufferedReader br = new BufferedReader(sr);
        try {//from w ww .  j av a  2s.c  o  m
            while (br.ready()) {
                final String line = br.readLine();
                if (line == null)
                    break;
                final String[] entry = line.split(regex, 2);
                if (entry.length == 2) {
                    map.put(entry[0], entry[1]);
                }
            }
        } catch (final IOException e) {
            LOG.debug("an error occurred parsing the text", e);
        } finally {
            IOUtils.closeQuietly(br);
            IOUtils.closeQuietly(sr);
        }
    }

    return map;
}

From source file:com.noshufou.android.su.util.Util.java

public static VersionInfo getSuVersionInfo() {
    VersionInfo info = new VersionInfo();
    Process process = null;/*from w  ww.  j a  v a2s  .c  o m*/
    String inLine = null;

    try {
        process = Runtime.getRuntime().exec("sh");
        DataOutputStream os = new DataOutputStream(process.getOutputStream());
        BufferedReader is = new BufferedReader(
                new InputStreamReader(new DataInputStream(process.getInputStream())), 64);
        os.writeBytes("su -v\n");

        // We have to hold up the thread to make sure that we're ready to read
        // the stream, using increments of 5ms makes it return as quick as
        // possible, and limiting to 1000ms makes sure that it doesn't hang for
        // too long if there's a problem.
        for (int i = 0; i < 400; i++) {
            if (is.ready()) {
                break;
            }
            try {
                Thread.sleep(5);
            } catch (InterruptedException e) {
                Log.w(TAG, "Sleep timer got interrupted...");
            }
        }
        if (is.ready()) {
            inLine = is.readLine();
            if (inLine != null) {
                info.version = inLine;
            }
        } else {
            // If 'su -v' isn't supported, neither is 'su -V'. return legacy info
            os.writeBytes("exit\n");
            info.version = "legacy";
            info.versionCode = 0;
            return info;
        }

        os.writeBytes("su -v\n");

        // We have to hold up the thread to make sure that we're ready to read
        // the stream, using increments of 5ms makes it return as quick as
        // possible, and limiting to 1000ms makes sure that it doesn't hang for
        // too long if there's a problem.
        for (int i = 0; i < 400; i++) {
            if (is.ready()) {
                break;
            }
            try {
                Thread.sleep(5);
            } catch (InterruptedException e) {
                Log.w(TAG, "Sleep timer got interrupted...");
            }
        }
        if (is.ready()) {
            inLine = is.readLine();
            if (inLine != null && Integer.parseInt(inLine.substring(0, 1)) > 2) {
                inLine = null;
                os.writeBytes("su -V\n");
                inLine = is.readLine();
                if (inLine != null) {
                    info.versionCode = Integer.parseInt(inLine);
                }
            } else {
                info.versionCode = 0;
            }
        } else {
            os.writeBytes("exit\n");
        }
    } catch (IOException e) {
        Log.e(TAG, "Problems reading current version.", e);
    } finally {
        if (process != null) {
            process.destroy();
        }
    }
    return info;
}