PushbackInputStream
- 데이터의 읽기복구(unread)기능을 제공
-> 방금 읽은 바이트를 읽기 전의 바이트 입력 스트림으로 되돌리기가 가능
======================================================================================
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.PushbackInputStream;
public class PushbackInputStreamTest {
public static void main(String[] args) throws IOException{
String s = "Java.";
System.out.println(s);
byte[] buffer = s.getBytes();
ByteArrayInputStream in = new ByteArrayInputStream(buffer);
PushbackInputStream f = new PushbackInputStream(in);
int c;
int count = 0;
while( (c = f.read()) != -1){
count++;
switch (c) {
case 'a':
if( (c = f.read()) == 'v'){
System.out.print("o");
// System.out.println("o" + "/ count : " + count + "/ c : " + c + "/ v == true");
}else{
System.out.print("b");
// System.out.println("b" + "/ count : " + count + "/ c : " + c + "/ v == false");
f.unread(c);
}
break;
default:
System.out.print( (char)c);
// System.out.println( (char)c + "/ count : " + count + "/ c : " + c + "/ default");
break;
}
}
}
}
'프로그래밍 정리 > 자바' 카테고리의 다른 글
InputStreamReader와 OutputStreamWriter (0) | 2013.06.01 |
---|---|
ByteArrayInputStream와 ByteArrayOutputStream (0) | 2013.06.01 |
flush() (0) | 2013.06.01 |
SequenceInputStream (0) | 2013.06.01 |
BufferedInputStream와 BufferedOutputStream (0) | 2013.06.01 |