[IT]/컴퓨터
[JAVA][예제] InputBufferTest 예제 - Beginning Java Networking
jamesku
2012. 10. 2. 13:00
Beginning Java Networking
Chad Darby, www.wrox.com
// InputBufferTest.java import java.io.IOException; import java.io.ByteArrayInputStream; import java.io.BufferedInputStream; public class InputBufferTest { public InputBufferTest() { } public static void main(String args[]) { try { byte[] b = new byte[] { (byte)-8, (byte)-4, (byte)-2, (byte)0, (byte)2, (byte)4 }; ByteArrayInputStream byteIn = new ByteArrayInputStream(b); BufferedInputStream bis = new BufferedInputStream(byteIn); int readByte = bis.read(); System.out.println("Reading the first byte: " + ((readByte <= 127) ? readByte :(readByte - 256))); bis.mark(16); readByte = bis.read(); System.out.println("Reading the second byte: " + ((readByte <= 127) ? readByte :(readByte - 256))); readByte = bis.read(); System.out.println("Reading the third byte: " + ((readByte <= 127) ? readByte :(readByte - 256))); readByte = bis.read(); System.out.println("Reading the fourth byte: " + ((readByte <= 127) ? readByte :(readByte - 256))); bis.reset(); readByte = bis.read(); System.out.println("Reading the second byte again: " + ((readByte <= 127) ? readByte :(readByte - 256))); } catch (IOException ioe) { ioe.printStackTrace(); } } }