Java tutorial
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.PushbackInputStream; public class Main { public static void main(String args[]) throws IOException { byte buf[] = "== = ".getBytes(); PushbackInputStream f = new PushbackInputStream(new ByteArrayInputStream(buf), 100); int c; 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; } } } }