diff src/main/java/org/monetdb/merovingian/Control.java @ 700:940e266eeccd

Refactor BufferedMCLReader It used to inherit from BufferedReader but there is no reason for that. Also, it used to have a method readLine() which - returned the line read - stored the linetype In the new setup we have a method advance() which reads a line and stores both it and its type. This makes the code more regular and makes it possible to peek ahead without consuming.
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Thu, 08 Dec 2022 15:59:17 +0100 (2022-12-08)
parents e2fd07352866
children aeb268156580
line wrap: on
line diff
--- a/src/main/java/org/monetdb/merovingian/Control.java
+++ b/src/main/java/org/monetdb/merovingian/Control.java
@@ -218,9 +218,9 @@ public class Control {
 
 		mout.writeLine(database + " " + command + "\n");
 		ArrayList<String> l = new ArrayList<String>();
-		String tmpLine = min.readLine();
-		LineType linetype = min.getLineType();
-		switch (linetype) {
+		min.advance();
+		String tmpLine = min.getLine();
+		switch (min.getLineType()) {
 		case ERROR:
 			throw new MerovingianException(tmpLine.substring(6));
 		case RESULT:
@@ -231,18 +231,16 @@ public class Control {
 			throw new MerovingianException("unexpected line: " + tmpLine);
 		}
 
-		boolean hasPrompt = false;
-		while (!hasPrompt) {
-			tmpLine = min.readLine();
-			linetype = min.getLineType();
 
-			switch (linetype) {
-			case PROMPT:
-				hasPrompt = true;
-				break;
+		lineloop:
+		while (true) {
+			min.advance();
+			switch (min.getLineType()) {
+				case PROMPT:
+				break lineloop;
 			case RESULT:
 				l.add(tmpLine.substring(1));
-				break;
+				continue lineloop;
 			default:
 				throw new MerovingianException("unexpected line: " + tmpLine);
 			}