Example usage for java.io BufferedReader read

List of usage examples for java.io BufferedReader read

Introduction

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

Prototype

public int read() throws IOException 

Source Link

Document

Reads a single character.

Usage

From source file:com.sun.faces.generate.HtmlTaglibGenerator.java

/**
 * <p>Load the copyright text for the top of each Java source file and TLD file.</p>
 *
 * @param path Pathname of the copyright file
 *///  w  w  w .  j a  va2  s  .  c  om
private static void copyright(String path) throws Exception {

    if (log.isDebugEnabled()) {
        log.debug("Loading copyright text from '" + path + "'");
    }
    StringBuffer sb = new StringBuffer();
    BufferedReader reader = new BufferedReader(new FileReader(path));
    int ch;
    while ((ch = reader.read()) >= 0) {
        sb.append((char) ch);
    }
    reader.close();
    if (log.isDebugEnabled()) {
        log.debug("  Copyright text contains " + sb.length() + " characters");
    }
    copyright = sb.toString();
}

From source file:com.sun.faces.generate.HtmlTaglibGenerator.java

/**
 * <p>Load any additional tag definitions from the specified 
 * file.  This file might include tags such as "column" which
 * have no renderer, but need to be generated into the 
 * TLD file.</p>/*from  w w  w.j av  a 2s . co m*/
 *
 * @param path Pathname of the tag definition file
 */
private static void loadOptionalTags(String path) throws Exception {

    if (log.isDebugEnabled()) {
        log.debug("Loading optional tag text from '" + path + "'");
    }
    StringBuffer sb = new StringBuffer();
    BufferedReader reader = new BufferedReader(new FileReader(path));
    int ch;
    while ((ch = reader.read()) >= 0) {
        sb.append((char) ch);
    }
    reader.close();
    if (log.isDebugEnabled()) {
        log.debug("  Optional tag text contains " + sb.length() + " characters");
    }
    tagDef = sb.toString();
}

From source file:ch.unifr.pai.twice.widgets.mpProxyScreenShot.server.ReadOnlyPresentation.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String url = req.getParameter("url"); //e.g.: http://www.sbb.ch

    Object uuidObj = req.getSession().getAttribute(Constants.uuidCookie);
    String uuid = uuidObj != null ? uuidObj.toString() : null;
    BufferedReader reader = req.getReader();
    ByteArrayOutputStream byteArrOS = new ByteArrayOutputStream();
    int b;/*from w w  w .j  a va 2  s.c  o  m*/
    while ((b = reader.read()) != -1) {
        byteArrOS.write(b);
    }
    byteArrOS.flush();
    byteArrOS.close();
    reader.close();
    String html = new String(byteArrOS.toByteArray(), "UTF-8");
    if (!html.isEmpty() && url != null && !url.isEmpty())
        uuidToScreenshot.put(uuid, new Screenshot(html, url, req.getParameter("height"),
                req.getParameter("width"), req.getParameter("top"), req.getParameter("left")));
}

From source file:main.java.gov.wa.wsdot.candidate.evaluation.App.java

/**
 * Reads in WSDOT highway camera data from Traveler Information API URL
 * using the StringBuilder Class./*w w w  .  j  a  va2s . com*/
 * 
 * @return JSON string read from Traveler Information API.
 * @throws Exception
 */
private String getAllCameras() throws Exception {

    StringBuilder sb = new StringBuilder();

    URL url = new URL(URL);
    URLConnection connection = url.openConnection();
    BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    int cp;
    while ((cp = in.read()) != -1) {
        sb.append((char) cp);
    }
    in.close();

    return sb.toString();

}

From source file:eu.project.ttc.resources.CharacterFootprintTermFilter.java

@Override
public void load(DataResource aData) throws ResourceInitializationException {
    LOGGER.debug("Loading resource character footprint resource at: " + aData.getUri());
    InputStream inputStream = null;
    try {/*from w  ww.j a  v  a  2  s . c  o  m*/
        inputStream = aData.getInputStream();
        List<Character> chars = new LinkedList<Character>();
        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
        int c;
        while ((c = br.read()) != -1) {
            if (!Character.isWhitespace((char) c))
                chars.add((char) c);
        }
        this.allowedChars = new char[chars.size()];
        for (int i = 0; i < chars.size(); i++)
            this.allowedChars[i] = chars.get(i);
        br.close();
    } catch (IOException e) {
        LOGGER.error("Could not load resource character footprint resource due to an exception.");
        LOGGER.warn("Continuing with the TrueFilter (always accept terms)");
        this.allowedChars = null;
    } catch (Exception e) {
        LOGGER.warn("PB loading " + aData.getUri() + ". Continuing with the TrueFilter (always accept terms)");
        this.allowedChars = null;
        return;
    } finally {
        if (inputStream != null)
            try {
                inputStream.close();
            } catch (IOException e) {
                LOGGER.error("Could not close input stream.");
            }
    }
}

From source file:org.nuxeo.ecm.platform.publisher.remoting.invoker.DefaultRemotePublicationInvoker.java

protected String doHttpCall(String methodName, String marshaledData) throws IOException {

    HttpClient httpClient = new DefaultHttpClient();

    String BAHeaderContent = userName + ":" + password;
    BAHeaderContent = Base64.encodeBase64String(BAHeaderContent.getBytes());
    String BAHeader = "basic " + BAHeaderContent;

    String targetUrl = baseURL + methodName;

    HttpPost httpPost = new HttpPost(targetUrl);

    HttpEntity entity = new StringEntity(marshaledData, "UTF-8");

    httpPost.setEntity(entity);//from ww  w . j  a v a 2 s . co  m

    httpPost.setHeader("content-type", "nuxeo/remotepub");
    httpPost.setHeader("authorization", BAHeader);

    HttpResponse response = httpClient.execute(httpPost);

    HttpEntity responseEntity = response.getEntity();
    if (responseEntity == null) {
        return null;
    }
    InputStreamReader isr = new InputStreamReader(responseEntity.getContent(), "UTF-8");

    BufferedReader br = new BufferedReader(isr);

    StringBuilder sb = new StringBuilder();

    int ch;
    while ((ch = br.read()) > -1) {
        sb.append((char) ch);
    }
    br.close();

    String result = sb.toString();

    return result;
}

From source file:AppletFinder.java

public String[] findApplets(URL u) {
    BufferedReader inrdr = null;
    Vector v = new Vector();
    char thisChar = 0;

    try {/*from  w  w  w .  j av  a2 s. co  m*/
        inrdr = new BufferedReader(new InputStreamReader(u.openStream()));
        int i;
        while ((i = inrdr.read()) != -1) {
            thisChar = (char) i;
            if (thisChar == '<') {
                String tag = readTag(inrdr);
                // System.out.println("TAG: " + tag);
                if (tag.toUpperCase().startsWith("<APPLET"))
                    v.addElement(tag);
            }
        }
        inrdr.close();
    } catch (IOException e) {
        System.err.println("Error reading from main URL: " + e);
    }
    String applets[] = new String[v.size()];
    v.copyInto(applets);
    return applets;
}

From source file:cn.kane.osgi.controller.test.DataPreparor.java

private String parseSqlIn(Resource resource) throws IOException {
    InputStream is = null;/*from  ww w .jav a  2 s . c o  m*/
    try {
        is = resource.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));

        StringWriter sw = new StringWriter();
        BufferedWriter writer = new BufferedWriter(sw);

        for (int c = reader.read(); c != -1; c = reader.read()) {
            writer.write(c);
        }
        writer.flush();
        return sw.toString();

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

From source file:functionalTests.annotations.AptTest.java

private Result getResults(BufferedReader stderr) {

    Result ret = new Result();

    try {/*from  w w  w. j a v a2  s.c  o  m*/
        if (stderr.read() == -1) {
            // apt finished succesfully
            return ret;
        }

        for (String line = stderr.readLine(); line != null; line = stderr.readLine()) {
            System.err.println(line);
            if (Pattern.matches("\\d* error(s?)", line)) {
                ret.errors = extractNumber(line);
            }
            if (Pattern.matches("\\d* warning(s?)", line)) {
                ret.warnings = extractNumber(line);
            }
        }

        return ret;
    } catch (IOException e) {
        // return what we have up until now
        return ret;
    }

}

From source file:com.mnxfst.stream.pipeline.element.script.ScriptEvaluatorPipelineElement.java

/**
 * Load scrtip from url/* w  w  w. j a  v a 2s .  c om*/
 * @param url
 * @return
 */
protected String loadScript(final String url) throws IOException {
    StringBuffer scriptContent = new StringBuffer();
    URL initScriptUrl = new URL(url);
    BufferedReader reader = new BufferedReader(new InputStreamReader(initScriptUrl.openStream()));
    int c = -1;
    while ((c = reader.read()) != -1) {
        scriptContent.append((char) c);
    }
    return scriptContent.toString();
}