-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsingPushBackInputStream.java
More file actions
34 lines (31 loc) · 1.2 KB
/
UsingPushBackInputStream.java
File metadata and controls
34 lines (31 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*:-PushbackInputStream is used on an input stream to allow a byte to be read and then returned to the stream .
:-It is helpful for parser designing .*/
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.PushbackInputStream;
class UsingPushBackInputStream{
public static void main(String ar[])throws IOException {
String s = "if(a == 4)a = 0";
byte buf[] = s.getBytes();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(buf);
PushbackInputStream pushbackInputStream = new PushbackInputStream(byteArrayInputStream);
int no;
while ((no = pushbackInputStream.read())!= -1){
switch (no){
case'=':
if ((no = pushbackInputStream.read())== '='){
// System.out.print(no);
System.out.print("comparison");
}
else
{
System.out.print("assignment");
pushbackInputStream.unread(no);
}
break;
default:
System.out.print((char)no);
}
}
}
}