List of usage examples for java.io PushbackInputStream read
public int read() throws IOException
From source file:PushbackInputStreamDemo.java
public static void main(String args[]) throws IOException { String s = "if (a == 4) a = 0;\n"; byte buf[] = s.getBytes(); ByteArrayInputStream in = new ByteArrayInputStream(buf); PushbackInputStream f = new PushbackInputStream(in); int c;/* www. jav a 2 s .c o m*/ while ((c = f.read()) != -1) { switch (c) { case '=': if ((c = f.read()) == '=') System.out.print(".eq."); else { System.out.print("<-"); f.unread(c); } break; default: System.out.print((char) c); break; } } }
From source file:Main.java
public static void main(String args[]) throws IOException { byte buf[] = "== = ".getBytes(); PushbackInputStream f = new PushbackInputStream(new ByteArrayInputStream(buf)); int c;//from w w w .ja v a 2s . c o m while ((c = f.read()) != -1) { switch (c) { case '=': c = f.read(); if (c == '=') System.out.print(".eq."); else { System.out.print("="); f.unread(c); } break; default: System.out.print((char) c); break; } } }
From source file:Main.java
public static void main(String args[]) throws IOException { byte buf[] = "== = ".getBytes(); PushbackInputStream f = new PushbackInputStream(new ByteArrayInputStream(buf), 100); int c;//from ww w .j a v a 2s. co m while ((c = f.read()) != -1) { switch (c) { case '=': c = f.read(); if (c == '=') System.out.print(".eq."); else { System.out.print("="); f.unread(c); } break; default: System.out.print((char) c); break; } } }
From source file:Main.java
public static void main(String[] args) { byte[] arrByte = new byte[1024]; byte[] byteArray = new byte[] { 'j', 'a', 'v', 'a', '2', 's', '.', 'c', 'o', 'm' }; InputStream is = new ByteArrayInputStream(byteArray); PushbackInputStream pis = new PushbackInputStream(is); try {/* ww w. ja va 2 s. co m*/ for (int i = 0; i < byteArray.length; i++) { arrByte[i] = (byte) pis.read(); System.out.println((char) arrByte[i]); } pis.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { byte[] arrByte = new byte[1024]; byte[] byteArray = new byte[] { 'j', 'a', 'v', 'a', '2', 's', '.', 'c', 'o', 'm' }; InputStream is = new ByteArrayInputStream(byteArray); PushbackInputStream pis = new PushbackInputStream(is); try {// www. jav a 2 s . com for (int i = 0; i < byteArray.length; i++) { arrByte[i] = (byte) pis.read(); System.out.println((char) arrByte[i]); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { byte[] arrByte = new byte[1024]; byte[] byteArray = new byte[] { 'j', 'a', 'v', 'a', '2', 's', '.', 'c', 'o', 'm' }; InputStream is = new ByteArrayInputStream(byteArray); PushbackInputStream pis = new PushbackInputStream(is); try {/*from w w w . j a va 2 s . c om*/ for (int i = 0; i < byteArray.length; i++) { arrByte[i] = (byte) pis.read(); System.out.println((char) arrByte[i]); } pis.reset(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { byte[] arrByte = new byte[1024]; byte[] byteArray = new byte[] { 'j', 'a', 'v', 'a', '2', 's', '.', 'c', 'o', 'm' }; InputStream is = new ByteArrayInputStream(byteArray); PushbackInputStream pis = new PushbackInputStream(is); try {/* w w w. j a v a 2s . c o m*/ for (int i = 0; i < byteArray.length; i++) { arrByte[i] = (byte) pis.read(); System.out.println((char) arrByte[i]); } pis.mark(5); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { byte[] arrByte = new byte[1024]; byte[] byteArray = new byte[] { 'j', 'a', 'v', 'a', '2', 's', '.', 'c', 'o', 'm' }; InputStream is = new ByteArrayInputStream(byteArray); PushbackInputStream pis = new PushbackInputStream(is, 10); try {/*from w w w . j a v a2 s . c o m*/ for (int i = 0; i < byteArray.length; i++) { arrByte[i] = (byte) pis.read(); System.out.println((char) arrByte[i]); } byte[] b = { 'W', 'o', 'r', 'l', 'd' }; pis.unread(b); for (int i = 0; i < byteArray.length; i++) { arrByte[i] = (byte) pis.read(); System.out.println((char) arrByte[i]); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { byte[] arrByte = new byte[1024]; byte[] byteArray = new byte[] { 'j', 'a', 'v', 'a', '2', 's', '.', 'c', 'o', 'm' }; InputStream is = new ByteArrayInputStream(byteArray); PushbackInputStream pis = new PushbackInputStream(is, 10); try {//from ww w .j a va2s.co m for (int i = 0; i < byteArray.length; i++) { arrByte[i] = (byte) pis.read(); System.out.println((char) arrByte[i]); } byte[] b = { 'W', 'o', 'r', 'l', 'd' }; pis.unread(b, 2, 3); for (int i = 0; i < 3; i++) { arrByte[i] = (byte) pis.read(); System.out.println((char) arrByte[i]); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { byte[] arrByte = new byte[1024]; byte[] byteArray = new byte[] { 'j', 'a', 'v', 'a', '2', 's', '.', 'c', 'o', 'm' }; InputStream is = new ByteArrayInputStream(byteArray); PushbackInputStream pis = new PushbackInputStream(is); try {/* w ww .j a v a 2 s . c o m*/ pis.skip(1); for (int i = 0; i < byteArray.length - 1; i++) { arrByte[i] = (byte) pis.read(); System.out.println((char) arrByte[i]); } } catch (Exception ex) { ex.printStackTrace(); } }