List of usage examples for java.io ByteArrayInputStream ByteArrayInputStream
public ByteArrayInputStream(byte buf[])
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 {/*from www . j a va 2 s .co m*/ 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:Main.java
public static void main(String[] args) throws IOException { byte[] buf = { 1, 2, 3, 4, 5 }; InputStream is = new ByteArrayInputStream(buf); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { System.out.println(dis.readBoolean()); }//w w w. j a va 2 s .c o m }
From source file:MainClass.java
public static void main(String[] args) throws IOException { try {//ww w. ja v a2s. c om DataInputStream in3 = new DataInputStream(new ByteArrayInputStream("a dbcde".getBytes())); while (true) System.out.print((char) in3.readByte()); } catch (EOFException e) { System.err.println("End of stream"); } }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] buf = { 65, 66, 67, 68, 69 }; // create new byte array input stream ByteArrayInputStream bais = new ByteArrayInputStream(buf); int value = 0; // read till the end of the stream while ((value = bais.read()) != -1) { // skip single byte bais.skip(1);// ww w. j a v a 2 s. c om System.out.println(value); } }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] buf = { 65, 66, 67, 68, 69 }; // create new byte array input stream ByteArrayInputStream bais = new ByteArrayInputStream(buf); // print bytes System.out.println(bais.read()); System.out.println(bais.read()); System.out.println(bais.read()); System.out.println(bais.read()); System.out.println(bais.read()); System.out.println("Reset() invocation"); // reset() invocation bais.reset();/*from w w w .j av a2s.c o m*/ System.out.println(bais.read()); System.out.println(bais.read()); }
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;// w w w .ja va 2s .com 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)); int c;//from w w w . ja v a 2 s.c om 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 = { 65, 66, 67, 68, 69 }; // create new byte array input stream ByteArrayInputStream bais = new ByteArrayInputStream(buf); // print bytes System.out.println(bais.read()); System.out.println(bais.read()); System.out.println(bais.read()); System.out.println("Mark() invocation"); // mark() invocation; bais.mark(0);/*from www. j a v a 2 s .c o m*/ System.out.println(bais.read()); System.out.println(bais.read()); System.out.println("Reset() invocation"); // reset() invocation bais.reset(); System.out.println(bais.read()); System.out.println(bais.read()); }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] buf = { 65, 66, 67, 68, 69 }; // create new byte array input stream ByteArrayInputStream bais = new ByteArrayInputStream(buf); // test support for mark() and reset() methods invocation boolean isMarkSupported = bais.markSupported(); System.out.println("Is mark supported : " + isMarkSupported); System.out.println("Following is the proof:"); // print bytes System.out.println(bais.read()); System.out.println(bais.read()); System.out.println(bais.read()); System.out.println("Mark() invocation"); // mark() invocation; bais.mark(0);/*from w w w . j a va2 s . c om*/ System.out.println(bais.read()); System.out.println(bais.read()); System.out.println("Reset() invocation"); // reset() invocation bais.reset(); System.out.println(bais.read()); System.out.println(bais.read()); }
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 w ww .j a v a 2 s.com*/ 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; } } }