Example usage for java.io StringReader read

List of usage examples for java.io StringReader read

Introduction

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

Prototype

public int read(java.nio.CharBuffer target) throws IOException 

Source Link

Document

Attempts to read characters into the specified character buffer.

Usage

From source file:Main.java

public static void main(String[] argv) throws IOException {
    StringReader stringReader = new StringReader("java2s.com");

    System.out.println(stringReader.ready());

    char[] charArray = new char[10];
    stringReader.read(charArray);
    System.out.println(Arrays.toString(charArray));

    stringReader.close();// w  ww.  j a v a2  s.co m
}

From source file:it.geosolutions.geoserver.jms.impl.handlers.DocumentFile.java

/**
 * //from   w ww. ja v  a 2s  . co  m
 * @param file
 * @param xml
 * @throws JDOMException
 * @throws IOException
 */
protected static void writer(File file, String xml) throws JDOMException, IOException {

    FileWriter writer = null;
    StringReader reader = null;
    try {
        writer = new FileWriter(file);
        reader = new StringReader(xml);

        char[] cbuf = new char[2048];
        int size = 0;
        while (reader.ready() && (size = reader.read(cbuf)) != -1) {
            writer.write(cbuf, 0, size);
        }

    } finally {
        writer.flush();
        IOUtils.closeQuietly(writer);
        IOUtils.closeQuietly(reader);
    }
}

From source file:architecture.common.license.io.LicenseWriter.java

public void write(Writer writer, int columns) throws IOException {
    String xml = document.asXML();
    String base64 = new String(Base64.encodeBase64(xml.getBytes(ApplicationConstants.DEFAULT_CHAR_ENCODING)));
    if (columns > 0)
        base64 = addLineBreaks(base64, columns);
    StringReader reader = new StringReader(base64);
    char buffer[] = new char[32768];
    int len;/*from   w  w w  .j a  v  a  2 s . c  om*/
    while ((len = reader.read(buffer)) != -1)
        writer.write(buffer, 0, len);

    writer.flush();
}