comparison src/main/java/org/monetdb/mcl/io/BufferedMCLReader.java @ 702:b4e968e5bd74

Some improvements.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 08 Dec 2022 19:13:46 +0100 (2022-12-08)
parents 940e266eeccd
children 21fd1eebbd0e
comparison
equal deleted inserted replaced
701:f89882b07614 702:b4e968e5bd74
13 import java.io.InputStream; 13 import java.io.InputStream;
14 import java.io.Reader; 14 import java.io.Reader;
15 import java.io.UnsupportedEncodingException; 15 import java.io.UnsupportedEncodingException;
16 16
17 /** 17 /**
18 * Read text from a character-input stream, buffering characters so as 18 * Read text from a character-input stream, buffering characters so as to
19 * to provide a means for efficient reading of characters, arrays and 19 * provide a means for efficient reading of characters, arrays and lines.
20 * lines. This class is based on the BufferedReader class, and provides
21 * extra functionality useful for MCL.
22 * 20 *
23 * The BufferedMCLReader is typically used as layer inbetween an 21 * The BufferedMCLReader is typically used as layer inbetween an
24 * InputStream and a specific interpreter of the data. 22 * InputStream and a specific interpreter of the data.
25 * <pre> 23 * <pre>
26 * / Response 24 * / Response
38 * 36 *
39 * @author Fabian Groffen 37 * @author Fabian Groffen
40 * @see org.monetdb.mcl.net.MapiSocket 38 * @see org.monetdb.mcl.net.MapiSocket
41 * @see org.monetdb.mcl.io.BufferedMCLWriter 39 * @see org.monetdb.mcl.io.BufferedMCLWriter
42 */ 40 */
43 public final class BufferedMCLReader /* extends BufferedReader */ { 41 public final class BufferedMCLReader {
44 42
45 private final BufferedReader inner; 43 private final BufferedReader inner;
46 private String current = null; 44 private String current = null;
47 private LineType lineType = LineType.UNKNOWN; 45 private LineType lineType = LineType.UNKNOWN;
48 46
110 /** 108 /**
111 * Discard the remainder of the response but collect any further error messages. 109 * Discard the remainder of the response but collect any further error messages.
112 * 110 *
113 * @return a string containing error messages, or null if there aren't any 111 * @return a string containing error messages, or null if there aren't any
114 * @throws IOException if an IO exception occurs while talking to the server 112 * @throws IOException if an IO exception occurs while talking to the server
115 *
116 * TODO(Wouter): should probably not have to be synchronized.
117 */ 113 */
118 114 final public String discardRemainder() throws IOException {
119
120 final public synchronized String discardRemainder() throws IOException {
121 return discard(null); 115 return discard(null);
122 } 116 }
123 117
124 final public synchronized String discardRemainder(String error) throws IOException { 118 /**
119 * Discard the remainder of the response but collect any further error messages.
120 *
121 * @return a string containing error messages, or null if there aren't any
122 * @throws IOException if an IO exception occurs while talking to the server
123 */
124 final public String discardRemainder(String error) throws IOException {
125 final StringBuilder sb; 125 final StringBuilder sb;
126 126
127 if (error != null) { 127 if (error != null) {
128 sb = makeErrorBuffer(); 128 sb = makeErrorBuffer();
129 sb.append(error); 129 sb.append(error);
131 sb = null; 131 sb = null;
132 } 132 }
133 return discard(sb); 133 return discard(sb);
134 } 134 }
135 135
136 /**
137 * Discard the remainder of the response but collect any further error messages.
138 *
139 * @return a string containing error messages, or null if there aren't any
140 * @throws IOException if an IO exception occurs while talking to the server
141 *
142 * TODO(Wouter): should probably not have to be synchronized.
143 */
136 final synchronized String discard(StringBuilder errmsgs) throws IOException { 144 final synchronized String discard(StringBuilder errmsgs) throws IOException {
137 while (lineType != LineType.PROMPT) { 145 while (lineType != LineType.PROMPT) {
138 advance(); 146 advance();
139 if (getLine() == null) 147 if (getLine() == null)
140 throw new IOException("Connection to server lost!"); 148 throw new IOException("Connection to server lost!");