Example usage for java.io CharArrayWriter write

List of usage examples for java.io CharArrayWriter write

Introduction

In this page you can find the example usage for java.io CharArrayWriter write.

Prototype

public void write(int c) 

Source Link

Document

Writes a character to the buffer.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {

    String str = "from java2s.com!";

    CharArrayWriter chw = new CharArrayWriter();

    chw.write(str);

    System.out.println(chw.toString());

}

From source file:Main.java

public static void main(String[] args) throws Exception {

    String str = "from java2s.com!";

    CharArrayWriter chw = new CharArrayWriter(100);

    chw.write(str);

    System.out.println(chw.toString());

}

From source file:Main.java

public static void main(String[] args) {
    CharArrayWriter chw = new CharArrayWriter();

    for (int i = 65; i < 70; i++) {
        chw.write(i);

    }/*from w  w  w . ja  v a 2  s  . co m*/
    String str = chw.toString();
    System.out.println(str);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    CharArrayWriter chw = new CharArrayWriter();

    String str = "from java2s.com!";

    chw.write(str);

    // get array of character from the writer
    char[] ch = chw.toCharArray();

    // for each character in character array
    for (char c : ch) {

        // print character
        System.out.println(c);//  ww w  . j ava2  s . c o  m
    }

}

From source file:Main.java

public static void main(String[] args) throws Exception {

    char[] ch = { 'A', 'B', 'C', 'D', 'E' };

    CharArrayWriter chw = new CharArrayWriter();

    // write character buffer to the writer
    chw.write(ch);

    // get buffered content as string
    String str = chw.toString();/*from  ww  w .ja  v a  2s.  c o m*/

    // print the string
    System.out.print(str);

}

From source file:Main.java

public static void main(String args[]) throws IOException {
    CharArrayWriter outStream = new CharArrayWriter();
    String s = "This is a test.";
    for (int i = 0; i < s.length(); ++i)
        outStream.write(s.charAt(i));
    System.out.println("outstream: " + outStream);
    System.out.println("size: " + outStream.size());
    CharArrayReader inStream;// w  w w .  j a v  a2  s. c  om
    inStream = new CharArrayReader(outStream.toCharArray());
    int ch = 0;
    StringBuffer sb = new StringBuffer("");
    while ((ch = inStream.read()) != -1)
        sb.append((char) ch);
    s = sb.toString();
    System.out.println(s.length() + " characters were read");
    System.out.println("They are: " + s);
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    String str = "from java2s.com!";

    CharArrayWriter chw = new CharArrayWriter();

    // create destination character array writer
    CharArrayWriter chwd = new CharArrayWriter();

    chw.write(str);

    chw.writeTo(chwd);/* w w w . j  a  v a 2s.  com*/

    // print the destination buffer content as string
    System.out.println(chwd.toString());

}

From source file:Main.java

public static void main(String[] args) throws Exception {

    String str = "from java2s.com!";

    CharArrayWriter chw = new CharArrayWriter();

    // create destination character array writer
    CharArrayWriter chwd = new CharArrayWriter();

    chw.write(str);

    chw.writeTo(chwd);/*from   w  ww.j  a v a 2s.  c o m*/

    // print the destination buffer content as string
    System.out.println(chwd.toString());
    System.out.println(chwd.size());

}

From source file:CharArrayWriterDemo.java

public static void main(String args[]) throws IOException {
    CharArrayWriter f = new CharArrayWriter();
    String s = "This should end up in the array";
    char buf[] = new char[s.length()];
    s.getChars(0, s.length(), buf, 0);/*from www  .ja  v a 2s .  c o m*/
    f.write(buf);
    System.out.println(f.toString());

    char c[] = f.toCharArray();
    for (int i = 0; i < c.length; i++) {
        System.out.print(c[i]);
    }

    FileWriter f2 = new FileWriter("test.txt");
    f.writeTo(f2);
    f2.close();
    f.reset();
    for (int i = 0; i < 3; i++)
        f.write('X');
}

From source file:com.jigsforjava.string.StringUtils.java

/**
 * Converts a camel case string into a lower-case, delimiter-separated
 * string. For example, a call of toSeparatedString("ACamelCaseString, '_')
 * returns a_camel_case_string./*from   www  . j  a va  2s  .  c  o  m*/
 * 
 * @param camelCaseString
 *            a String in camel case to delimit.
 * @param delimiter
 *            the character used to separate the string.
 * @return a String where capitals in the original are prefixed with the
 *         given delimiter.
 */
public static String toSeparatedString(String camelCaseString, char delimiter) {
    CharArrayWriter result = new CharArrayWriter();
    char[] chars = camelCaseString.toCharArray();

    for (int i = 0; i < chars.length; ++i) {
        if (chars[i] != delimiter && Character.isUpperCase(chars[i]) && i > 0) {
            if ((i < chars.length - 1) && (!Character.isUpperCase(chars[i + 1]) && chars[i + 1] != delimiter)
                    && chars[i - 1] != delimiter)
                result.write(delimiter);
            else if (!Character.isUpperCase(chars[i - 1]) && chars[i - 1] != delimiter)
                result.write(delimiter);
        }

        result.write(chars[i]);
    }

    return result.toString().toLowerCase();
}