comparison src/main/java/org/monetdb/mcl/io/BufferedMCLReader.java @ 706:21fd1eebbd0e

Some more Javadoc improvements.
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Fri, 09 Dec 2022 13:09:28 +0100 (2022-12-09)
parents b4e968e5bd74
children 5022a57f9d97
comparison
equal deleted inserted replaced
705:ba226d5d3996 706:21fd1eebbd0e
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 to 18 * Helper class to read and classify the lines of a query response.
19 * provide a means for efficient reading of characters, arrays and lines.
20 * 19 *
21 * The BufferedMCLReader is typically used as layer inbetween an 20 * This class wraps and buffers the Reader on which the responses come in.
22 * InputStream and a specific interpreter of the data. 21 * Use {@link #getLine()} to get the current line, {@link #getLineType()}
23 * <pre> 22 * to get its {@link LineType} and {@link #advance()} to proceed to the
24 * / Response 23 * next line.
25 * BufferedMCLReader ---o &lt;- Tuple 24 *
26 * \ DataBlock 25 * Initially, the line type is set to {@link LineType.UNKNOWN} and the line
27 * </pre> 26 * is set to null. When the end of the result set has been reached the line type
28 * Because the BufferedMCLReader provides an efficient way to access the 27 * will remain {@link LineType.PROMPT} and the line will again be null.
29 * data from the stream in a linewise fashion, whereby each line is 28 *
30 * identified as a certain type, consumers can easily decide how to 29 * To start reading the next response, call {@link #resetLineType()}. This
31 * parse each retrieved line. The line parsers from 30 * is usually done automatically by the accompanying {@link BufferedMCLWriter}
32 * org.monetdb.mcl.parser are well suited to work with the lines 31 * whenever a new request is sent to the server.
33 * outputted by the BufferedMCLReader.
34 * This class is client-oriented, as it doesn't take into account the
35 * messages as the server receives them.
36 * 32 *
37 * @author Fabian Groffen 33 * @author Fabian Groffen
38 * @see org.monetdb.mcl.net.MapiSocket 34 * @see org.monetdb.mcl.net.MapiSocket
39 * @see org.monetdb.mcl.io.BufferedMCLWriter 35 * @see org.monetdb.mcl.io.BufferedMCLWriter
40 */ 36 */
66 throws UnsupportedEncodingException 62 throws UnsupportedEncodingException
67 { 63 {
68 this(new java.io.InputStreamReader(in, enc)); 64 this(new java.io.InputStreamReader(in, enc));
69 } 65 }
70 66
67 /**
68 * Proceed to the next line of the response.
69 *
70 * Set line type to PROMPT and line to null if the end of the response
71 * has been reached.
72 * @throws IOException
73 */
71 public void advance() throws IOException { 74 public void advance() throws IOException {
72 if (lineType == LineType.PROMPT) 75 if (lineType == LineType.PROMPT)
73 return; 76 return;
74 77
75 current = inner.readLine(); 78 current = inner.readLine();
78 current = "!22000!" + current.substring(1); 81 current = "!22000!" + current.substring(1);
79 } 82 }
80 } 83 }
81 84
82 /** 85 /**
83 * Resets the linetype to UNKNOWN. 86 * Reset the linetype to UNKNOWN.
84 */ 87 */
85 public void resetLineType() { 88 public void resetLineType() {
86 lineType = LineType.UNKNOWN; 89 lineType = LineType.UNKNOWN;
87 } 90 }
88 91
116 } 119 }
117 120
118 /** 121 /**
119 * Discard the remainder of the response but collect any further error messages. 122 * Discard the remainder of the response but collect any further error messages.
120 * 123 *
124 * @param error A string containing earlier error messages to include in the error report.
121 * @return a string containing error messages, or null if there aren't any 125 * @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 126 * @throws IOException if an IO exception occurs while talking to the server
123 */ 127 */
124 final public String discardRemainder(String error) throws IOException { 128 final public String discardRemainder(String error) throws IOException {
125 final StringBuilder sb; 129 final StringBuilder sb;
134 } 138 }
135 139
136 /** 140 /**
137 * Discard the remainder of the response but collect any further error messages. 141 * Discard the remainder of the response but collect any further error messages.
138 * 142 *
143 * @param error A StringBuilder containing earlier error messages to include in the error report.
139 * @return a string containing error messages, or null if there aren't any 144 * @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 145 * @throws IOException if an IO exception occurs while talking to the server
141 * 146 *
142 * TODO(Wouter): should probably not have to be synchronized. 147 * TODO(Wouter): should probably not have to be synchronized.
143 */ 148 */
159 164
160 private final StringBuilder makeErrorBuffer() { 165 private final StringBuilder makeErrorBuffer() {
161 return new StringBuilder(128); 166 return new StringBuilder(128);
162 } 167 }
163 168
169 /**
170 * Close the wrapped Reader.
171 * @throws IOException
172 */
164 public void close() throws IOException { 173 public void close() throws IOException {
165 inner.close(); 174 inner.close();
166 } 175 }
167 } 176 }