- LinkedList<String> splitted = new LinkedList<String>();
- LinkedList<Outputable> commands = new LinkedList<Outputable>();
- Scanner sc = new Scanner(r);
- Pattern p1 = Pattern.compile("([^<]|<[^?])*<\\?");
- Pattern p2 = Pattern.compile("[^?]*\\?>");
- while (true) {
- String s1 = sc.findWithinHorizon(p1, 0);
- if (s1 == null) {
- break;
+ try {
+ LinkedList<String> splitted = new LinkedList<String>();
+ LinkedList<Outputable> commands = new LinkedList<Outputable>();
+ StringBuffer buf = new StringBuffer();
+ int ch = r.read();
+ outer : while (true) {
+ while (!endsWith(buf, "<?")) {
+ if (ch == -1) {
+ break outer;
+ }
+ buf.append((char) ch);
+ ch = r.read();
+ }
+ buf.delete(buf.length() - 2, buf.length());
+ splitted.add(buf.toString());
+ buf.delete(0, buf.length());
+ while (!endsWith(buf, "?>")) {
+ buf.append((char) ch);
+ ch = r.read();
+ if (ch == -1) {
+ throw new EOFException();
+ }
+ }
+ buf.delete(buf.length() - 2, buf.length());
+ commands.add(parseCommand(buf.toString()));
+ buf.delete(0, buf.length());