Mercurial > hg > monetdb-java
comparison 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 |
comparison
equal
deleted
inserted
replaced
699:0ff364f569a1 | 700:940e266eeccd |
---|---|
216 } | 216 } |
217 } | 217 } |
218 | 218 |
219 mout.writeLine(database + " " + command + "\n"); | 219 mout.writeLine(database + " " + command + "\n"); |
220 ArrayList<String> l = new ArrayList<String>(); | 220 ArrayList<String> l = new ArrayList<String>(); |
221 String tmpLine = min.readLine(); | 221 min.advance(); |
222 LineType linetype = min.getLineType(); | 222 String tmpLine = min.getLine(); |
223 switch (linetype) { | 223 switch (min.getLineType()) { |
224 case ERROR: | 224 case ERROR: |
225 throw new MerovingianException(tmpLine.substring(6)); | 225 throw new MerovingianException(tmpLine.substring(6)); |
226 case RESULT: | 226 case RESULT: |
227 if (!tmpLine.substring(1).equals(RESPONSE_OK)) | 227 if (!tmpLine.substring(1).equals(RESPONSE_OK)) |
228 throw new MerovingianException(tmpLine); | 228 throw new MerovingianException(tmpLine); |
229 break; | 229 break; |
230 default: | 230 default: |
231 throw new MerovingianException("unexpected line: " + tmpLine); | 231 throw new MerovingianException("unexpected line: " + tmpLine); |
232 } | 232 } |
233 | 233 |
234 boolean hasPrompt = false; | 234 |
235 while (!hasPrompt) { | 235 lineloop: |
236 tmpLine = min.readLine(); | 236 while (true) { |
237 linetype = min.getLineType(); | 237 min.advance(); |
238 | 238 switch (min.getLineType()) { |
239 switch (linetype) { | 239 case PROMPT: |
240 case PROMPT: | 240 break lineloop; |
241 hasPrompt = true; | |
242 break; | |
243 case RESULT: | 241 case RESULT: |
244 l.add(tmpLine.substring(1)); | 242 l.add(tmpLine.substring(1)); |
245 break; | 243 continue lineloop; |
246 default: | 244 default: |
247 throw new MerovingianException("unexpected line: " + tmpLine); | 245 throw new MerovingianException("unexpected line: " + tmpLine); |
248 } | 246 } |
249 } | 247 } |
250 | 248 |