comparison src/main/java/org/monetdb/mcl/net/MapiSocket.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 6beecac8aa1b
children bdeabbd46ec6
comparison
equal deleted inserted replaced
699:0ff364f569a1 700:940e266eeccd
285 } catch (UnsupportedEncodingException e) { 285 } catch (UnsupportedEncodingException e) {
286 throw new MCLException(e.toString()); 286 throw new MCLException(e.toString());
287 } 287 }
288 } 288 }
289 289
290 final String c = reader.readLine(); 290 reader.advance();
291 reader.waitForPrompt(); 291 final String c = reader.getLine();
292 reader.discardRemainder();
292 writer.writeLine(getChallengeResponse(c, user, pass, language, database, hash)); 293 writer.writeLine(getChallengeResponse(c, user, pass, language, database, hash));
293 294
294 // read monetdb mserver response till prompt 295 // read monetdb mserver response till prompt
295 final ArrayList<String> redirects = new ArrayList<String>(); 296 final ArrayList<String> redirects = new ArrayList<String>();
296 final List<String> warns = new ArrayList<String>(); 297 final List<String> warns = new ArrayList<String>();
297 String err = "", tmp; 298 String err = "", tmp;
298 LineType lineType;
299 do { 299 do {
300 tmp = reader.readLine(); 300 reader.advance();
301 tmp = reader.getLine();
301 if (tmp == null) 302 if (tmp == null)
302 throw new IOException("Read from " + 303 throw new IOException("Read from " +
303 con.getInetAddress().getHostName() + ":" + 304 con.getInetAddress().getHostName() + ":" +
304 con.getPort() + ": End of stream reached"); 305 con.getPort() + ": End of stream reached");
305 lineType = reader.getLineType(); 306 if (reader.getLineType() == LineType.ERROR) {
306 if (lineType == LineType.ERROR) {
307 err += "\n" + tmp.substring(7); 307 err += "\n" + tmp.substring(7);
308 } else if (lineType == LineType.INFO) { 308 } else if (reader.getLineType() == LineType.INFO) {
309 warns.add(tmp.substring(1)); 309 warns.add(tmp.substring(1));
310 } else if (lineType == LineType.REDIRECT) { 310 } else if (reader.getLineType() == LineType.REDIRECT) {
311 redirects.add(tmp.substring(1)); 311 redirects.add(tmp.substring(1));
312 } 312 }
313 } while (lineType != LineType.PROMPT); 313 } while (reader.getLineType() != LineType.PROMPT);
314 314
315 if (err.length() > 0) { 315 if (err.length() > 0) {
316 close(); 316 close();
317 throw new MCLException(err); 317 throw new MCLException(err);
318 } 318 }