List of usage examples for java.io CharArrayReader read
public int read() throws IOException
From source file:Main.java
public static void main(String[] args) throws Exception { char[] ch = { 'A', 'B', 'C', 'D', 'E' }; CharArrayReader car = new CharArrayReader(ch); int value = 0; while ((value = car.read()) != -1) { System.out.print((char) value); }//from w ww . j av a 2 s. co m car.reset(); while ((value = car.read()) != -1) { System.out.print((char) value); } }
From source file:Main.java
public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String tmp = br.readLine();//from ww w . j ava 2 s .c o m int length = tmp.length(); char c[] = new char[length]; tmp.getChars(0, length, c, 0); CharArrayReader input1 = new CharArrayReader(c); int i; System.out.print("input1 is:"); while ((i = input1.read()) != -1) { System.out.print((char) i); } }
From source file:Main.java
public static void main(String[] args) throws Exception { char[] ch = { 'H', 'E', 'L', 'L', 'O' }; CharArrayReader car = new CharArrayReader(ch); car.close();/* w w w. ja v a 2 s .co m*/ // read the character array stream System.out.println(car.read()); }
From source file:Main.java
public static void main(String[] args) throws Exception { char[] ch = { 'H', 'E', 'L', 'L', 'O' }; CharArrayReader car = new CharArrayReader(ch); int value = 0; // read till the end of the file while ((value = car.read()) != -1) { char c = (char) value; // print the character System.out.print(c + " : "); // print the integer System.out.println(value); }// w w w . j a v a 2 s .com }
From source file:Main.java
public static void main(String[] args) throws Exception { char[] ch = { 'A', 'B', 'C', 'D', 'E' }; CharArrayReader car = new CharArrayReader(ch); // read and print the characters from the stream System.out.println(car.read()); System.out.println(car.read()); // mark() is invoked at this position car.mark(0);/*from ww w . j a va2 s. co m*/ System.out.println("Mark() is invoked"); System.out.println(car.read()); System.out.println(car.read()); // reset() is invoked at this position car.reset(); System.out.println("Reset() is invoked"); System.out.println(car.read()); System.out.println(car.read()); System.out.println(car.read()); }
From source file:Main.java
public static void main(String[] args) throws Exception { char[] ch = { 'A', 'B', 'C', 'D', 'E' }; CharArrayReader car = new CharArrayReader(ch); int value = 0; // read till the end of the stream while ((value = car.read()) != -1) { // convert integer to char char c = (char) value; // print characters System.out.print(c + "; "); // skip single character long l = car.skip(1); System.out.println("Characters Skipped : " + l); }//from ww w . j a v a 2s .com }
From source file:Main.java
public static void main(String args[]) throws IOException { String tmp = "abcdefghijklmnopqrstuvwxyz"; int length = tmp.length(); char c[] = new char[length]; tmp.getChars(0, length, c, 0);/*from w w w. j ava 2s.c om*/ CharArrayReader input1 = new CharArrayReader(c); CharArrayReader input2 = new CharArrayReader(c, 0, 5); int i; while ((i = input1.read()) != -1) { System.out.print((char) i); } while ((i = input2.read()) != -1) { System.out.print((char) i); } }
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));//from w ww. j ava 2s . co m System.out.println("outstream: " + outStream); System.out.println("size: " + outStream.size()); CharArrayReader inStream; 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 { char[] ch = { 'A', 'B', 'C', 'D', 'E' }; CharArrayReader car = new CharArrayReader(ch); // verifies if the stream support mark() method boolean bool = car.markSupported(); System.out.println("Is mark supported : " + bool); System.out.println("Proof:"); // read and print the characters from the stream System.out.println(car.read()); System.out.println(car.read()); // mark() is invoked at this position car.mark(0);//from ww w .j a v a2s. c o m System.out.println("Mark() is invoked"); System.out.println(car.read()); System.out.println(car.read()); // reset() is invoked at this position car.reset(); System.out.println("Reset() is invoked"); System.out.println(car.read()); System.out.println(car.read()); System.out.println(car.read()); }