Mercurial > hg > monetdb-java
annotate src/main/java/org/monetdb/mcl/io/BufferedMCLReader.java @ 975:5e320086a01c default tip
Some docker images are not available as dev-builds
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 01 May 2025 17:13:53 +0200 (7 hours ago) |
parents | d416e9b6b3d0 |
children |
rev | line source |
---|---|
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1 /* |
833
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
750
diff
changeset
|
2 * SPDX-License-Identifier: MPL-2.0 |
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
750
diff
changeset
|
3 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
4 * This Source Code Form is subject to the terms of the Mozilla Public |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
7 * |
937
d416e9b6b3d0
Update Copyright year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
867
diff
changeset
|
8 * Copyright 2024, 2025 MonetDB Foundation; |
833
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
750
diff
changeset
|
9 * Copyright August 2008 - 2023 MonetDB B.V.; |
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
750
diff
changeset
|
10 * Copyright 1997 - July 2008 CWI. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
11 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
12 |
391
f523727db392
Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
13 package org.monetdb.mcl.io; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
14 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
15 import java.io.BufferedReader; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
16 import java.io.IOException; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
17 import java.io.InputStream; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
18 import java.io.Reader; |
750
02ad91fb3438
UTF-8 is a standard character set, which is always available in Java Runtime. Use it and avoid looking it up every time.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
716
diff
changeset
|
19 import java.nio.charset.Charset; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
20 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
21 /** |
706
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
22 * Helper class to read and classify the lines of a query response. |
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
23 * |
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
24 * This class wraps and buffers the Reader on which the responses come in. |
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
25 * Use {@link #getLine()} to get the current line, {@link #getLineType()} |
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
26 * to get its {@link LineType} and {@link #advance()} to proceed to the |
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
27 * next line. |
180
fdf4c888d5b7
Small code and layout improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
28 * |
708
5022a57f9d97
Resolve javadoc errors.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
706
diff
changeset
|
29 * Initially, the line type is set to LineType.UNKNOWN and the line |
706
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
30 * is set to null. When the end of the result set has been reached the line type |
708
5022a57f9d97
Resolve javadoc errors.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
706
diff
changeset
|
31 * will remain LineType.PROMPT and the line will again be null. |
706
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
32 * |
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
33 * To start reading the next response, call {@link #resetLineType()}. This |
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
34 * is usually done automatically by the accompanying {@link BufferedMCLWriter} |
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
35 * whenever a new request is sent to the server. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
36 * |
194
1296dbcc4958
Resolved javadoc many errors and warnings, such as:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
180
diff
changeset
|
37 * @author Fabian Groffen |
391
f523727db392
Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
38 * @see org.monetdb.mcl.net.MapiSocket |
f523727db392
Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
39 * @see org.monetdb.mcl.io.BufferedMCLWriter |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
40 */ |
702
b4e968e5bd74
Some improvements.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
41 public final class BufferedMCLReader { |
180
fdf4c888d5b7
Small code and layout improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
42 |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
43 private final BufferedReader inner; |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
44 private String current = null; |
553
50b15ee1cb5e
Process suggestions from Martin
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
45 private LineType lineType = LineType.UNKNOWN; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
46 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
47 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
48 * Create a buffering character-input stream that uses a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
49 * default-sized input buffer. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
50 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
51 * @param in A Reader |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
52 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
280
diff
changeset
|
53 public BufferedMCLReader(final Reader in) { |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
54 inner = new BufferedReader(in); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
55 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
56 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
57 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
58 * Create a buffering character-input stream that uses a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
59 * default-sized input buffer, from an InputStream. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
60 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
61 * @param in An InputStream |
750
02ad91fb3438
UTF-8 is a standard character set, which is always available in Java Runtime. Use it and avoid looking it up every time.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
716
diff
changeset
|
62 * @param cs A Charset |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
63 */ |
750
02ad91fb3438
UTF-8 is a standard character set, which is always available in Java Runtime. Use it and avoid looking it up every time.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
716
diff
changeset
|
64 public BufferedMCLReader(final InputStream in, final Charset cs) { |
02ad91fb3438
UTF-8 is a standard character set, which is always available in Java Runtime. Use it and avoid looking it up every time.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
716
diff
changeset
|
65 this(new java.io.InputStreamReader(in, cs)); |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
66 } |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
67 |
706
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
68 /** |
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
69 * Proceed to the next line of the response. |
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
70 * |
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
71 * Set line type to PROMPT and line to null if the end of the response |
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
72 * has been reached. |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
73 * @throws IOException if exception occurred during reading |
706
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
74 */ |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
75 public void advance() throws IOException { |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
76 if (lineType == LineType.PROMPT) |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
77 return; |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
78 |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
79 current = inner.readLine(); |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
80 lineType = LineType.classify(current); |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
81 if (lineType == LineType.ERROR && current != null && !current.matches("^![0-9A-Z]{5}!.+")) { |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
82 current = "!22000!" + current.substring(1); |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
83 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
84 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
85 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
86 /** |
706
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
87 * Reset the linetype to UNKNOWN. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
88 */ |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
89 public void resetLineType() { |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
90 lineType = LineType.UNKNOWN; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
91 } |
391
f523727db392
Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
92 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
93 /** |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
94 * Return the current line, or null if we're at the end or before the beginning. |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
95 * @return the current line or null |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
96 */ |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
97 public String getLine() { |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
98 return current; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
99 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
100 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
101 /** |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
750
diff
changeset
|
102 * Return a substring of the current line, or null if we're at the end or before the beginning. |
847
4d80fd66541d
formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
793
diff
changeset
|
103 * |
867
5a59910e8f87
Resolve some javadoc errors and warnings
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
104 * @param start beginIndex |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
750
diff
changeset
|
105 * @return the current line or null |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
750
diff
changeset
|
106 */ |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
750
diff
changeset
|
107 public String getLine(int start) { |
849
37a5240e80ef
Handle null case
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
108 String line = getLine(); |
37a5240e80ef
Handle null case
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
109 if (line != null) |
37a5240e80ef
Handle null case
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
110 line = line.substring(start); |
37a5240e80ef
Handle null case
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
111 return line; |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
750
diff
changeset
|
112 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
750
diff
changeset
|
113 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
750
diff
changeset
|
114 /** |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
115 * getLineType returns the type of the current line. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
116 * |
640
0f5d924751e7
Add comments for LineType '=' and correct the return type information for javadoc.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
610
diff
changeset
|
117 * @return Linetype representing the kind of line this is, one of the |
0f5d924751e7
Add comments for LineType '=' and correct the return type information for javadoc.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
610
diff
changeset
|
118 * following enums: UNKNOWN, HEADER, ERROR, RESULT, |
0f5d924751e7
Add comments for LineType '=' and correct the return type information for javadoc.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
610
diff
changeset
|
119 * PROMPT, MORE, FILETRANSFER, SOHEADER, REDIRECT, INFO |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
120 */ |
497
aed7f32e029a
Refactor LineType to be an enum
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
406
diff
changeset
|
121 public LineType getLineType() { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
122 return lineType; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
123 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
124 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
125 /** |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
126 * Discard the remainder of the response but collect any further error messages. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
127 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
128 * @return a string containing error messages, or null if there aren't any |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
129 * @throws IOException if an IO exception occurs while talking to the server |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
130 */ |
702
b4e968e5bd74
Some improvements.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
131 final public String discardRemainder() throws IOException { |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
132 return discard(null); |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
133 } |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
134 |
702
b4e968e5bd74
Some improvements.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
135 /** |
b4e968e5bd74
Some improvements.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
136 * Discard the remainder of the response but collect any further error messages. |
b4e968e5bd74
Some improvements.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
137 * |
706
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
138 * @param error A string containing earlier error messages to include in the error report. |
702
b4e968e5bd74
Some improvements.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
139 * @return a string containing error messages, or null if there aren't any |
b4e968e5bd74
Some improvements.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
140 * @throws IOException if an IO exception occurs while talking to the server |
b4e968e5bd74
Some improvements.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
141 */ |
b4e968e5bd74
Some improvements.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
142 final public String discardRemainder(String error) throws IOException { |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
143 final StringBuilder sb; |
280
72efb3e34436
Improve setLineType()
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
144 |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
145 if (error != null) { |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
146 sb = makeErrorBuffer(); |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
147 sb.append(error); |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
148 } else { |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
149 sb = null; |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
150 } |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
151 return discard(sb); |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
152 } |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
153 |
702
b4e968e5bd74
Some improvements.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
154 /** |
b4e968e5bd74
Some improvements.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
155 * Discard the remainder of the response but collect any further error messages. |
b4e968e5bd74
Some improvements.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
156 * |
708
5022a57f9d97
Resolve javadoc errors.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
706
diff
changeset
|
157 * @param errmsgs An optional StringBuilder object containing earlier error messages to include in the error report. |
702
b4e968e5bd74
Some improvements.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
158 * @return a string containing error messages, or null if there aren't any |
b4e968e5bd74
Some improvements.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
159 * @throws IOException if an IO exception occurs while talking to the server |
b4e968e5bd74
Some improvements.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
160 * |
b4e968e5bd74
Some improvements.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
161 * TODO(Wouter): should probably not have to be synchronized. |
b4e968e5bd74
Some improvements.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
162 */ |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
163 final synchronized String discard(StringBuilder errmsgs) throws IOException { |
553
50b15ee1cb5e
Process suggestions from Martin
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
542
diff
changeset
|
164 while (lineType != LineType.PROMPT) { |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
165 advance(); |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
166 if (getLine() == null) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
167 throw new IOException("Connection to server lost!"); |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
168 if (getLineType() == LineType.ERROR) { |
654
755c05380872
Optimise waitForPrompt() by delaying the creation of a new StringBuilder object till it is really needed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
640
diff
changeset
|
169 if (errmsgs == null) |
755c05380872
Optimise waitForPrompt() by delaying the creation of a new StringBuilder object till it is really needed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
640
diff
changeset
|
170 errmsgs = new StringBuilder(128); |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
171 errmsgs.append('\n').append(getLine().substring(1)); |
654
755c05380872
Optimise waitForPrompt() by delaying the creation of a new StringBuilder object till it is really needed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
640
diff
changeset
|
172 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
173 } |
654
755c05380872
Optimise waitForPrompt() by delaying the creation of a new StringBuilder object till it is really needed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
640
diff
changeset
|
174 if (errmsgs == null) |
755c05380872
Optimise waitForPrompt() by delaying the creation of a new StringBuilder object till it is really needed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
640
diff
changeset
|
175 return null; |
655
2ded26c5a679
Revert an unwanted change which causes errors being reported on the testweb.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
654
diff
changeset
|
176 return errmsgs.toString().trim(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
177 } |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
178 |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
179 private final StringBuilder makeErrorBuffer() { |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
180 return new StringBuilder(128); |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
181 } |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
182 |
706
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
183 /** |
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
184 * Close the wrapped Reader. |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
708
diff
changeset
|
185 * @throws IOException if an IO exception occurs while talking to the server |
706
21fd1eebbd0e
Some more Javadoc improvements.
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
702
diff
changeset
|
186 */ |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
187 public void close() throws IOException { |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
188 inner.close(); |
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
655
diff
changeset
|
189 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
190 } |