List of usage examples for java.io PushbackInputStream PushbackInputStream
public PushbackInputStream(InputStream in)
PushbackInputStream
with a 1-byte pushback buffer, and saves its argument, the input stream in
, for later use. From source file:Main.java
public static void main(String[] args) { String srcFile = "test.txt"; try (PushbackInputStream pis = new PushbackInputStream(new FileInputStream(srcFile))) { byte byteData; while ((byteData = (byte) pis.read()) != -1) { System.out.print((char) byteData); pis.unread(byteData);//from ww w .j a va 2 s.c o m // Reread the byte we unread byteData = (byte) pis.read(); System.out.print((char) byteData); } } catch (Exception e2) { e2.printStackTrace(); } }
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;/* w ww . ja v a 2 s . 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) { 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); System.out.println(pis.markSupported()); }
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 ww. j a v a2 s. c om 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 {/*from w w w . ja va2 s . co m*/ 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 {//ww w.j av a 2s.c om 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 v a2 s . co 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); try {// ww w . j a v a 2 s . co 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(); } }
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' }; try {/* w w w . j a v a 2 s . com*/ InputStream is = new ByteArrayInputStream(byteArray); PushbackInputStream pis = new PushbackInputStream(is); System.out.println(pis.available()); 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: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;/*from www. ja v 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; } } }