List of usage examples for java.io ByteArrayInputStream read
public synchronized int read()
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] buf = { 65, 66, 67, 68, 69 }; ByteArrayInputStream bais = new ByteArrayInputStream(buf); int b = 0;//from w ww . jav a 2 s . c o m while ((b = bais.read()) != -1) { char c = (char) b; System.out.println("byte :" + b + "; char : " + c); } System.out.print(bais.read() + " Reached the end"); }
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 . ja va 2 s . com 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); // 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 . jav a 2 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:MainClass.java
public static void main(String args[]) throws IOException { String tmp = "abc"; byte b[] = tmp.getBytes(); ByteArrayInputStream in = new ByteArrayInputStream(b); for (int i = 0; i < 2; i++) { int c;/*from w ww . j a va 2 s .c o m*/ while ((c = in.read()) != -1) { if (i == 0) { System.out.print((char) c); } else { System.out.print(Character.toUpperCase((char) c)); } } System.out.println(); in.reset(); } }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] buf = { 65, 66, 67, 68, 69 }; ByteArrayInputStream bais = new ByteArrayInputStream(buf); int count = 0; while ((count = bais.available()) > 0) { char c = (char) bais.read(); System.out.print("available byte(s) : " + count); System.out.println(c);/*from ww w .java 2s . co m*/ } }
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);//from ww w . jav a2 s .c o m 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); // 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);//www. j ava2 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 Boolean readBoolean(ByteArrayInputStream bais) { int b = bais.read(); if (b == 0) { return Boolean.FALSE; } else {/*from w w w.j ava 2 s . c o m*/ return Boolean.TRUE; } }
From source file:Main.java
protected static int extractByteValue(ByteArrayInputStream bais) { assert (null != bais); int temp = bais.read(); assert (-1 != temp); return temp & 0xFF; }
From source file:Main.java
public static int getLength(ByteArrayInputStream bais) { int lowbyte = bais.read(); if ((lowbyte & 128) == 0) { // MSB = 0 return lowbyte; } else if ((lowbyte & 64) == 0) { // MSB = 10 lowbyte -= 128;/*from w ww .j av a 2s . com*/ int highbyte = bais.read(); return lowbyte + highbyte * 64; } else if ((lowbyte & 32) == 0) { // MSB = 110 lowbyte -= 128 + 64; int midbyte = bais.read(); int highbyte = bais.read(); return lowbyte + midbyte * 32 + highbyte * 32 * 256; } else { throw new RuntimeException("Cannot parse length"); } }