Mercurial > hg > monetdb-java
annotate src/main/java/org/monetdb/mcl/net/MapiSocket.java @ 943:ff075ed5ce81
Spell check.
author | Sjoerd Mullender <sjoerd@acm.org> |
---|---|
date | Thu, 09 Jan 2025 10:56:14 +0100 (3 months 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:
816
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:
816
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:
905
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:
816
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:
816
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:
368
diff
changeset
|
13 package org.monetdb.mcl.net; |
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.BufferedInputStream; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
16 import java.io.BufferedOutputStream; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
17 import java.io.FileWriter; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
18 import java.io.FilterInputStream; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
19 import java.io.FilterOutputStream; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
20 import java.io.IOException; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
21 import java.io.InputStream; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
22 import java.io.OutputStream; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
23 import java.io.Writer; |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
24 import java.net.*; |
555
90c346571eb4
Use StandardCharsets.UTF_8 where possible
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
554
diff
changeset
|
25 import java.nio.charset.StandardCharsets; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
26 import java.security.MessageDigest; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
27 import java.security.NoSuchAlgorithmException; |
811
ede3a59ff4f2
Add MapiSocket.connect(url, properties) method
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
803
diff
changeset
|
28 import java.util.*; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
29 |
840
a2b1ae53565e
Improve error messages
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
839
diff
changeset
|
30 import javax.net.ssl.SSLException; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
31 |
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:
368
diff
changeset
|
32 import org.monetdb.mcl.MCLException; |
f523727db392
Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
368
diff
changeset
|
33 import org.monetdb.mcl.io.BufferedMCLReader; |
f523727db392
Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
368
diff
changeset
|
34 import org.monetdb.mcl.io.BufferedMCLWriter; |
497
aed7f32e029a
Refactor LineType to be an enum
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
495
diff
changeset
|
35 import org.monetdb.mcl.io.LineType; |
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:
368
diff
changeset
|
36 import org.monetdb.mcl.parser.MCLParseException; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
37 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
38 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
39 * A Socket for communicating with the MonetDB database in MAPI block |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
40 * mode. |
53
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
41 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
42 * The MapiSocket implements the protocol specifics of the MAPI block |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
43 * mode protocol, and interfaces it as a socket that delivers a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
44 * BufferedReader and a BufferedWriter. Because logging in is an |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
45 * integral part of the MAPI protocol, the MapiSocket performs the login |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
46 * procedure. Like the Socket class, various options can be set before |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
47 * calling the connect() method to influence the login process. Only |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
48 * after a successful call to connect() the BufferedReader and |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
49 * BufferedWriter can be retrieved. |
194
1296dbcc4958
Resolved javadoc many errors and warnings, such as:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
180
diff
changeset
|
50 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
51 * For each line read, it is determined what type of line it is |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
52 * according to the MonetDB MAPI protocol. This results in a line to be |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
53 * PROMPT, HEADER, RESULT, ERROR or UNKNOWN. Use the getLineType() |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
54 * method on the BufferedMCLReader to retrieve the type of the last |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
55 * line read. |
53
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
56 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
57 * For debugging purposes a socket level debugging is implemented where |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
58 * each and every interaction to and from the MonetDB server is logged |
194
1296dbcc4958
Resolved javadoc many errors and warnings, such as:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
180
diff
changeset
|
59 * to a file on disk. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
60 * Incoming messages are prefixed by "RX" (received by the driver), |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
61 * outgoing messages by "TX" (transmitted by the driver). Special |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
62 * decoded non-human readable messages are prefixed with "RD" and "TD" |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
63 * instead. Following this two char prefix, a timestamp follows as the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
64 * number of milliseconds since the UNIX epoch. The rest of the line is |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
65 * a String representation of the data sent or received. |
53
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
66 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
67 * The general use of this Socket must be seen only in the full context |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
68 * of a MAPI connection to a server. It has the same ingredients as a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
69 * normal Socket, allowing for seamless plugging. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
70 * <pre> |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
71 * Socket \ / InputStream ----> (BufferedMCL)Reader |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
72 * > o < |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
73 * MapiSocket / \ OutputStream ----> (BufferedMCL)Writer |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
74 * </pre> |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
75 * The MapiSocket allows to retrieve Streams for communicating. They |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
76 * are interfaced, so they can be chained in any way. While the Socket |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
77 * transparently deals with how data is sent over the wire, the actual |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
78 * data read needs to be interpreted, for which a Reader/Writer |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
79 * interface is most sufficient. In particular the BufferedMCL* |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
80 * implementations of those interfaces supply some extra functionality |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
81 * geared towards the format of the data. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
82 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
83 * @author Fabian Groffen |
867
5a59910e8f87
Resolve some javadoc errors and warnings
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
84 * @version 4.4 |
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:
368
diff
changeset
|
85 * @see org.monetdb.mcl.io.BufferedMCLReader |
f523727db392
Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
368
diff
changeset
|
86 * @see org.monetdb.mcl.io.BufferedMCLWriter |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
87 */ |
768
a80c21fe7bb2
Removed deprecated nl.cwi.monetdb.*.* classes and package.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
756
diff
changeset
|
88 public final class MapiSocket { |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
89 /* an even number of NUL bytes used during the handshake */ |
847
4d80fd66541d
formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
846
diff
changeset
|
90 private static final byte[] NUL_BYTES = new byte[]{ 0, 0, 0, 0, 0, 0, 0, 0 }; |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
91 |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
92 /* A mapping between hash algorithm names as used in the MAPI |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
93 * protocol, and the names by which the Java runtime knows them. |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
94 */ |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
95 private static final String[][] KNOWN_ALGORITHMS = new String[][] { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
96 {"SHA512", "SHA-512"}, |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
97 {"SHA384", "SHA-384"}, |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
98 {"SHA256", "SHA-256"}, |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
99 // should we deprecate this by now? |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
100 {"SHA1", "SHA-1"}, |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
101 }; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
102 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
103 // MUST be lowercase! |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
104 private static final char[] HEXDIGITS = "0123456789abcdef".toCharArray(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
105 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
106 /** Connection parameters */ |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
107 private Target target; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
108 /** The TCP Socket to mserver */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
109 private Socket con; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
110 /** Stream from the Socket for reading */ |
501
eaad79c3235f
Make the fake prompts at block ends optional
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
498
diff
changeset
|
111 private BlockInputStream fromMonet; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
112 /** Stream from the Socket for writing */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
113 private OutputStream toMonet; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
114 /** MCLReader on the InputStream */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
115 private BufferedMCLReader reader; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
116 /** MCLWriter on the OutputStream */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
117 private BufferedMCLWriter writer; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
118 /** protocol version of the connection */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
119 private int version; |
905
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
904
diff
changeset
|
120 private boolean supportsClientInfo; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
121 |
836
aad275e042b2
Heed followRedirect
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
835
diff
changeset
|
122 /** Whether we should follow redirects. |
aad275e042b2
Heed followRedirect
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
835
diff
changeset
|
123 * Not sure why this needs to be separate |
aad275e042b2
Heed followRedirect
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
835
diff
changeset
|
124 * from 'ttl' but someone someday explicitly documented setTtl |
aad275e042b2
Heed followRedirect
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
835
diff
changeset
|
125 * with 'to disable completely, use followRedirects' so |
aad275e042b2
Heed followRedirect
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
835
diff
changeset
|
126 * apparently there is a use case. |
aad275e042b2
Heed followRedirect
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
835
diff
changeset
|
127 */ |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
128 private boolean followRedirects = true; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
129 /** How many redirections do we follow until we're fed up with it? */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
130 private int ttl = 10; |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
131 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
132 /** The Writer for the debug log-file */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
133 private Writer log; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
134 |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
135 /** The blocksize (hardcoded in compliance with MonetDB common/stream/stream.h) */ |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
136 public final static int BLOCK = 8190; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
137 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
138 /** A short in two bytes for holding the block size in bytes */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
139 private final byte[] blklen = new byte[2]; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
140 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
141 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
142 * Constructs a new MapiSocket. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
143 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
144 public MapiSocket() { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
145 target = new Target(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
146 con = null; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
147 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
148 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
149 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
150 * Sets the database to connect to. If database is null, a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
151 * connection is made to the default database of the server. This |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
152 * is also the default. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
153 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
154 * @param db the database |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
155 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
156 public void setDatabase(final String db) { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
157 target.setDatabase(db); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
158 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
159 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
160 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
161 * Sets the language to use for this connection. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
162 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
163 * @param lang the language |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
164 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
165 public void setLanguage(final String lang) { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
166 target.setLanguage(lang); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
167 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
168 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
169 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
170 * Sets the hash method to use. Note that this method is intended |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
171 * for debugging purposes. Setting a hash method can yield in |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
172 * connection failures. Multiple hash methods can be given by |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
173 * separating the hashes by commas. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
174 * DON'T USE THIS METHOD if you don't know what you're doing. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
175 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
176 * @param hash the hash method to use |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
177 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
178 public void setHash(final String hash) { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
179 target.setHash(hash); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
180 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
181 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
182 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
183 * Sets whether MCL redirections should be followed or not. If set |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
184 * to false, an MCLException will be thrown when a redirect is |
943 | 185 * encountered during connect. The default behavior is to |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
186 * automatically follow redirects. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
187 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
188 * @param r whether to follow redirects (true) or not (false) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
189 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
190 public void setFollowRedirects(final boolean r) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
191 this.followRedirects = r; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
192 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
193 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
194 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
195 * Sets the number of redirects that are followed when |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
196 * followRedirects is true. In order to avoid going into an endless |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
197 * loop due to some evil server, or another error, a maximum number |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
198 * of redirects that may be followed can be set here. Note that to |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
199 * disable the following of redirects you should use |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
200 * setFollowRedirects. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
201 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
202 * @see #setFollowRedirects(boolean r) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
203 * @param t the number of redirects before an exception is thrown |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
204 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
205 public void setTTL(final int t) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
206 this.ttl = t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
207 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
208 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
209 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
210 * Set the SO_TIMEOUT on the underlying Socket. When for some |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
211 * reason the connection to the database hangs, this setting can be |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
212 * useful to break out of this indefinite wait. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
213 * This option must be enabled prior to entering the blocking |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
214 * operation to have effect. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
215 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
216 * @param s The specified timeout, in milliseconds. A timeout |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
217 * of zero will disable timeout (i.e., timeout of infinity). |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
218 * @throws SocketException Issue with the socket |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
219 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
220 public void setSoTimeout(final int s) throws SocketException { |
53
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
221 if (s < 0) { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
222 throw new IllegalArgumentException("timeout can't be negative"); |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
223 } |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
224 target.setSoTimeout(s); |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
225 // limit time to wait on blocking operations |
53
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
226 if (con != null) { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
227 con.setSoTimeout(s); |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
228 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
229 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
230 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
231 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
232 * Gets the SO_TIMEOUT from the underlying Socket. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
233 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
234 * @return the currently in use timeout in milliseconds |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
235 * @throws SocketException Issue with the socket |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
236 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
237 public int getSoTimeout() throws SocketException { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
238 return target.getSoTimeout(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
239 } |
75
db46b4ab2b9f
Correct the condition for when the log can be closed: only when log instanceof FileWriter
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
53
diff
changeset
|
240 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
241 /** |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
242 * Enables/disables debug mode with logging to file |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
243 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
244 * @param debug Value to set |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
245 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
246 public void setDebug(final boolean debug) { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
247 target.setDebug(debug); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
248 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
249 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
250 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
251 * Connects to the given host and port, logging in as the given |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
252 * user. If followRedirect is false, a RedirectionException is |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
253 * thrown when a redirect is encountered. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
254 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
255 * @param host the hostname, or null for the loopback address |
225
5ddb1f20d5d5
Socket may also throw an UnknownHostException. Add it to MapiSocket.connect() and catch it in MonetConnection(Properties props).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
256 * @param port the port number (must be between 0 and 65535, inclusive) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
257 * @param user the username |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
258 * @param pass the password |
53
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
259 * @return A List with informational (warning) messages. If this |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
260 * list is empty; then there are no warnings. |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
261 * @throws IOException if an I/O error occurs when creating the socket |
225
5ddb1f20d5d5
Socket may also throw an UnknownHostException. Add it to MapiSocket.connect() and catch it in MonetConnection(Properties props).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
262 * @throws SocketException - if there is an error in the underlying protocol, such as a TCP error. |
5ddb1f20d5d5
Socket may also throw an UnknownHostException. Add it to MapiSocket.connect() and catch it in MonetConnection(Properties props).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
263 * @throws UnknownHostException if the IP address of the host could not be determined |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
264 * @throws MCLParseException if bogus data is received |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
265 * @throws MCLException if an MCL related error occurs |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
266 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
267 public List<String> connect(final String host, final int port, final String user, final String pass) |
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
268 throws IOException, SocketException, UnknownHostException, MCLParseException, MCLException |
180
fdf4c888d5b7
Small code and layout improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
269 { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
270 target.setHost(host); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
271 target.setPort(port); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
272 target.setUser(user); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
273 target.setPassword(pass); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
274 return connect(target, null); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
275 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
276 |
811
ede3a59ff4f2
Add MapiSocket.connect(url, properties) method
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
803
diff
changeset
|
277 public List<String> connect(String url, Properties props) throws URISyntaxException, ValidationError, MCLException, MCLParseException, IOException { |
ede3a59ff4f2
Add MapiSocket.connect(url, properties) method
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
803
diff
changeset
|
278 return connect(new Target(url, props), null); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
279 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
280 |
721
b78d8167a997
Remove finalize() method as it is deprecated and marked for removal in a future JDK. See also: https://openjdk.org/jeps/421
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
716
diff
changeset
|
281 /** |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
282 * Connect according to the settings in the 'target' parameter. |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
283 * If followRedirect is false, a RedirectionException is |
721
b78d8167a997
Remove finalize() method as it is deprecated and marked for removal in a future JDK. See also: https://openjdk.org/jeps/421
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
716
diff
changeset
|
284 * thrown when a redirect is encountered. |
b78d8167a997
Remove finalize() method as it is deprecated and marked for removal in a future JDK. See also: https://openjdk.org/jeps/421
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
716
diff
changeset
|
285 * |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
286 * Some settings, such as the initial reply size, can already be configured |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
287 * during the handshake, saving a command round-trip later on. |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
288 * To do so, create and pass a subclass of {@link MapiSocket.OptionsCallback}. |
847
4d80fd66541d
formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
846
diff
changeset
|
289 * |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
290 * @param target the connection settings |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
291 * @param callback will be called if the server allows options to be set during the |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
292 * initial handshake |
721
b78d8167a997
Remove finalize() method as it is deprecated and marked for removal in a future JDK. See also: https://openjdk.org/jeps/421
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
716
diff
changeset
|
293 * @return A List with informational (warning) messages. If this |
b78d8167a997
Remove finalize() method as it is deprecated and marked for removal in a future JDK. See also: https://openjdk.org/jeps/421
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
716
diff
changeset
|
294 * list is empty; then there are no warnings. |
b78d8167a997
Remove finalize() method as it is deprecated and marked for removal in a future JDK. See also: https://openjdk.org/jeps/421
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
716
diff
changeset
|
295 * @throws IOException if an I/O error occurs when creating the socket |
b78d8167a997
Remove finalize() method as it is deprecated and marked for removal in a future JDK. See also: https://openjdk.org/jeps/421
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
716
diff
changeset
|
296 * @throws SocketException - if there is an error in the underlying protocol, such as a TCP error. |
b78d8167a997
Remove finalize() method as it is deprecated and marked for removal in a future JDK. See also: https://openjdk.org/jeps/421
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
716
diff
changeset
|
297 * @throws UnknownHostException if the IP address of the host could not be determined |
b78d8167a997
Remove finalize() method as it is deprecated and marked for removal in a future JDK. See also: https://openjdk.org/jeps/421
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
716
diff
changeset
|
298 * @throws MCLParseException if bogus data is received |
b78d8167a997
Remove finalize() method as it is deprecated and marked for removal in a future JDK. See also: https://openjdk.org/jeps/421
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
716
diff
changeset
|
299 * @throws MCLException if an MCL related error occurs |
b78d8167a997
Remove finalize() method as it is deprecated and marked for removal in a future JDK. See also: https://openjdk.org/jeps/421
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
716
diff
changeset
|
300 */ |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
301 public List<String> connect(Target target, OptionsCallback callback) throws MCLException, MCLParseException, IOException { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
302 // get rid of any earlier connection state, including the existing target |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
303 close(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
304 this.target = target; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
305 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
306 Target.Validated validated; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
307 try { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
308 validated = target.validate(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
309 } catch (ValidationError e) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
310 throw new MCLException(e.getMessage()); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
311 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
312 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
313 if (validated.connectScan()) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
314 return scanUnixSockets(callback); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
315 } |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
316 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
317 ArrayList<String> warnings = new ArrayList<>(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
318 int attempts = 0; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
319 do { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
320 boolean ok = false; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
321 try { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
322 boolean done = tryConnect(callback, warnings); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
323 ok = true; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
324 if (done) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
325 return warnings; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
326 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
327 } finally { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
328 if (!ok) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
329 close(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
330 } |
836
aad275e042b2
Heed followRedirect
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
835
diff
changeset
|
331 } while (followRedirects && attempts++ < this.ttl); |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
332 throw new MCLException("max redirect count exceeded"); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
333 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
334 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
335 private List<String> scanUnixSockets(OptionsCallback callback) throws MCLException, MCLParseException, IOException { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
336 // Because we do not support Unix Domain sockets, we just go back to connect(). |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
337 // target.connectScan() will now return false; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
338 target.setHost("localhost"); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
339 return connect(target, callback); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
340 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
341 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
342 private boolean tryConnect(OptionsCallback callback, ArrayList<String> warningBuffer) throws MCLException, IOException { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
343 try { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
344 // We need a valid target |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
345 Target.Validated validated = target.validate(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
346 // con will be non-null if the previous attempt ended in a redirect to mapi:monetdb://proxy |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
347 if (con == null) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
348 connectSocket(validated); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
349 return handshake(validated, callback, warningBuffer); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
350 } catch (IOException | MCLException e) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
351 close(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
352 throw e; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
353 } catch (ValidationError e) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
354 close(); |
846
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
355 throw new MCLException(e.getMessage()); |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
356 } |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
357 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
358 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
359 private void connectSocket(Target.Validated validated) throws MCLException, IOException { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
360 // This method performs steps 2-6 of the procedure outlined in the URL spec |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
361 String tcpHost = validated.connectTcp(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
362 if (tcpHost.isEmpty()) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
363 throw new MCLException("Unix domain sockets are not supported, only TCP"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
364 } |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
365 int port = validated.connectPort(); |
840
a2b1ae53565e
Improve error messages
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
839
diff
changeset
|
366 Socket sock = null; |
a2b1ae53565e
Improve error messages
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
839
diff
changeset
|
367 try { |
a2b1ae53565e
Improve error messages
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
839
diff
changeset
|
368 sock = new Socket(tcpHost, port); |
a2b1ae53565e
Improve error messages
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
839
diff
changeset
|
369 sock.setSoTimeout(validated.getSoTimeout()); |
a2b1ae53565e
Improve error messages
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
839
diff
changeset
|
370 sock.setTcpNoDelay(true); |
a2b1ae53565e
Improve error messages
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
839
diff
changeset
|
371 sock.setKeepAlive(true); |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
372 |
840
a2b1ae53565e
Improve error messages
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
839
diff
changeset
|
373 sock = wrapTLS(sock, validated); |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
374 |
840
a2b1ae53565e
Improve error messages
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
839
diff
changeset
|
375 fromMonet = new BlockInputStream(sock.getInputStream()); |
a2b1ae53565e
Improve error messages
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
839
diff
changeset
|
376 toMonet = new BlockOutputStream(sock.getOutputStream()); |
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:
737
diff
changeset
|
377 reader = new BufferedMCLReader(fromMonet, StandardCharsets.UTF_8); |
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:
737
diff
changeset
|
378 writer = new BufferedMCLWriter(toMonet, StandardCharsets.UTF_8); |
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:
737
diff
changeset
|
379 writer.registerReader(reader); |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
698
diff
changeset
|
380 reader.advance(); |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
381 |
840
a2b1ae53565e
Improve error messages
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
839
diff
changeset
|
382 // Only assign to sock when everything went ok so far |
a2b1ae53565e
Improve error messages
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
839
diff
changeset
|
383 con = sock; |
850
9f200daffa35
Ensure sock is closed on errors
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
848
diff
changeset
|
384 sock = null; |
840
a2b1ae53565e
Improve error messages
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
839
diff
changeset
|
385 } catch (SSLException e) { |
a2b1ae53565e
Improve error messages
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
839
diff
changeset
|
386 throw new MCLException("SSL error: " + e.getMessage(), e); |
a2b1ae53565e
Improve error messages
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
839
diff
changeset
|
387 } catch (IOException e) { |
a2b1ae53565e
Improve error messages
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
839
diff
changeset
|
388 throw new MCLException("Could not connect to " + tcpHost + ":" + port + ": " + e.getMessage(), e); |
850
9f200daffa35
Ensure sock is closed on errors
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
848
diff
changeset
|
389 } finally { |
9f200daffa35
Ensure sock is closed on errors
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
848
diff
changeset
|
390 if (sock != null) |
9f200daffa35
Ensure sock is closed on errors
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
848
diff
changeset
|
391 try { |
9f200daffa35
Ensure sock is closed on errors
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
848
diff
changeset
|
392 sock.close(); |
9f200daffa35
Ensure sock is closed on errors
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
848
diff
changeset
|
393 } catch (IOException e) { |
9f200daffa35
Ensure sock is closed on errors
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
848
diff
changeset
|
394 // ignore |
9f200daffa35
Ensure sock is closed on errors
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
848
diff
changeset
|
395 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
396 } |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
397 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
398 |
800
09f463444dde
TLS support in its most basic form
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
799
diff
changeset
|
399 private Socket wrapTLS(Socket sock, Target.Validated validated) throws IOException { |
846
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
400 if (validated.getTls()) |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
401 return SecureSocket.wrap(validated, sock); |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
402 else { |
848
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
403 // Send an even number of NUL bytes to avoid a deadlock if |
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
404 // we're accidentally connecting to a TLS-protected server. |
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
405 // The cause of the deadlock is that we speak MAPI and we wait |
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
406 // for the server to send a MAPI challenge. |
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
407 // However, if the server is trying to set up TLS, it will be |
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
408 // waiting for us to send a TLS 'Client Hello' packet. |
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
409 // Hence, deadlock. |
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
410 // NUL NUL is a no-op in MAPI and will hopefully force an error |
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
411 // in the TLS server. This does not always work, some |
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
412 // TLS implementations abort on the first NUL, some need more NULs |
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
413 // than we are prepared to send here. 8 seems to be a good number. |
803
1671f2eb130b
Send NUL bytes on non-TLS connect
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
801
diff
changeset
|
414 sock.getOutputStream().write(NUL_BYTES); |
1671f2eb130b
Send NUL bytes on non-TLS connect
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
801
diff
changeset
|
415 } |
846
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
416 return sock; |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
417 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
418 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
419 private boolean handshake(Target.Validated validated, OptionsCallback callback, ArrayList<String> warnings) throws IOException, MCLException { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
420 String challenge = reader.getLine(); |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
698
diff
changeset
|
421 reader.advance(); |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
422 if (reader.getLineType() != LineType.PROMPT) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
423 throw new MCLException("Garbage after server challenge: " + reader.getLine()); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
424 String response = challengeResponse(validated, challenge, callback); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
425 writer.writeLine(response); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
426 reader.advance(); |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
427 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
428 // Process the response lines. |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
429 String redirect = null; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
430 StringBuilder errors = new StringBuilder(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
431 while (reader.getLineType() != LineType.PROMPT) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
432 switch (reader.getLineType()) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
433 case REDIRECT: |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
434 if (redirect == null) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
435 redirect = reader.getLine(1); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
436 break; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
437 case ERROR: |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
438 if (errors.length() > 0) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
439 errors.append("\n"); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
440 errors.append(reader.getLine(7)); // 7 not 1! |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
441 break; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
442 case INFO: |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
443 warnings.add(reader.getLine(1)); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
444 break; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
445 default: |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
446 // ignore??!! |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
447 break; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
448 } |
700
940e266eeccd
Refactor BufferedMCLReader
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
698
diff
changeset
|
449 reader.advance(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
450 } |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
451 if (errors.length() > 0) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
452 throw new MCLException(errors.toString()); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
453 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
454 if (redirect == null) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
455 return true; // we're happy |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
456 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
457 // process redirect |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
458 try { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
459 MonetUrlParser.parse(target, redirect); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
460 } catch (URISyntaxException | ValidationError e) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
461 throw new MCLException("While processing redirect " + redirect + ": " + e.getMessage(), e); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
462 } |
846
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
463 if (redirect.startsWith("mapi:merovingian://proxy")) { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
464 // The reader is stuck at LineType.PROMPT but actually the |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
465 // next challenge is already there. |
846
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
466 reader.resetLineType(); |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
467 reader.advance(); |
846
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
468 } else { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
469 close(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
470 } |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
471 |
846
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
472 return false; // we need another go |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
473 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
474 |
847
4d80fd66541d
formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
846
diff
changeset
|
475 private String challengeResponse(Target.Validated validated, final String challengeLine, OptionsCallback callback) throws MCLException { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
476 // The challengeLine looks like this: |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
477 // |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
478 // 45IYyVyRnbgEnK92ad:merovingian:9:RIPEMD160,SHA512,SHA384,SHA256,SHA224,SHA1:LIT:SHA512: |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
479 // WgHIibSyH:mserver:9:RIPEMD160,SHA512,SHA384,SHA256,SHA224,SHA1:LIT:SHA512:sql=6:BINARY=1: |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
480 // 0 1 2 3 4 5 6 7 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
481 |
847
4d80fd66541d
formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
846
diff
changeset
|
482 String[] parts = challengeLine.split(":"); |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
483 if (parts.length < 3) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
484 throw new MCLException("Invalid challenge: expect at least 3 fields"); |
838
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
485 String saltPart = parts[0]; |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
486 String serverTypePart = parts[1]; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
487 String versionPart = parts[2]; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
488 int version; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
489 if (versionPart.equals("9")) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
490 version = 9; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
491 else |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
492 throw new MCLException("Protocol versions other than 9 are note supported: " + versionPart); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
493 if (parts.length < 6) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
494 throw new MCLException("Protocol version " + version + " requires at least 6 fields, found " + parts.length + ": " + challengeLine); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
495 String serverHashesPart = parts[3]; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
496 // String endianPart = parts[4]; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
497 String passwordHashPart = parts[5]; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
498 String optionsPart = parts.length > 6 ? parts[6] : null; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
499 // String binaryPart = parts.length > 7 ? parts[7] : null; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
500 |
905
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
904
diff
changeset
|
501 if (parts.length > 9) |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
904
diff
changeset
|
502 supportsClientInfo = true; |
903
778959b2e0a4
Send ClientInfo on startup
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
867
diff
changeset
|
503 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
504 String userResponse; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
505 String password = target.getPassword(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
506 if (serverTypePart.equals("merovingian") && !target.getLanguage().equals("control")) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
507 userResponse = "merovingian"; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
508 password = "merovingian"; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
509 } else { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
510 userResponse = target.getUser(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
511 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
512 String optionsResponse = handleOptions(callback, optionsPart); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
513 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
514 // Response looks like this: |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
515 // |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
516 // LIT:monetdb:{RIPEMD160}f2236256e5a9b20a5ecab4396e36c14f66c3e3c5:sql:demo |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
517 // :FILETRANS:auto_commit=1,reply_size=1000,size_header=0,columnar_protocol=0,time_zone=3600: |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
518 StringBuilder response = new StringBuilder(80); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
519 response.append("BIG:"); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
520 response.append(userResponse).append(":"); |
838
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
521 hashPassword(response, saltPart, password, passwordHashPart, validated.getHash(), serverHashesPart); |
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
522 response.append(":"); |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
523 response.append(validated.getLanguage()).append(":"); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
524 response.append(validated.getDatabase()).append(":"); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
525 response.append("FILETRANS:"); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
526 response.append(optionsResponse).append(":"); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
527 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
528 return response.toString(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
529 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
530 |
839
33fadeb034a7
fix comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
838
diff
changeset
|
531 private String hashPassword(StringBuilder responseBuffer, String salt, String password, String passwordAlgo, String configuredHashes, String serverSupportedAlgos) throws MCLException { |
838
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
532 // First determine which hash algorithms we can choose from for the challenge response. |
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
533 // This defaults to whatever the server offers but may be restricted by the user. |
847
4d80fd66541d
formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
846
diff
changeset
|
534 Set<String> algoSet = new HashSet<>(Arrays.asList(serverSupportedAlgos.split(","))); |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
535 if (!configuredHashes.isEmpty()) { |
838
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
536 String[] allowedList = configuredHashes.toUpperCase().split("[, ]"); |
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
537 Set<String> allowedSet = new HashSet<>(Arrays.asList(allowedList)); |
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
538 algoSet.retainAll(allowedSet); |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
539 if (algoSet.isEmpty()) { |
838
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
540 throw new MCLException("None of the hash algorithms in <" + configuredHashes + "> are supported, server only supports <" + serverSupportedAlgos + ">"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
541 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
542 } |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
543 |
838
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
544 int maxHashDigits = 512 / 4; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
545 |
838
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
546 // We'll collect the result in the responseBuffer. |
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
547 // It will start with '{' HASHNAME '}' followed by hexdigits |
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
548 |
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
549 // This is where we accumulate what will eventually be hashed into the hexdigits above. |
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
550 // It consists of the hexadecimal pre-hash of the password, |
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
551 // followed by the salt from the server |
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
552 StringBuilder intermediate = new StringBuilder(maxHashDigits + salt.length()); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
553 |
838
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
554 MessageDigest passwordDigest = pickBestAlgorithm(Collections.singleton(passwordAlgo), null); |
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
555 // Here's the password.. |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
556 hexhash(intermediate, passwordDigest, password); |
838
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
557 // .. and here's the salt |
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
558 intermediate.append(salt); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
559 |
848
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
560 responseBuffer.append('{'); |
838
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
561 MessageDigest responseDigest = pickBestAlgorithm(algoSet, responseBuffer); |
848
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
562 // the call above has appended the HASHNAME, now add '}' |
838
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
563 responseBuffer.append('}'); |
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
564 // pickBestAlgorithm has appended HASHNAME, buffer now contains '{' HASHNAME '}' |
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
565 hexhash(responseBuffer, responseDigest, intermediate.toString()); |
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
566 // response buffer now contains '{' HASHNAME '}' HEX_DIGITS_OF_INTERMEDIATE_BUFFER |
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
567 |
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
568 return responseBuffer.toString(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
569 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
570 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
571 /** |
838
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
572 * Pick the most preferred digest algorithm and return a MessageDigest instance for that. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
573 * |
847
4d80fd66541d
formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
846
diff
changeset
|
574 * @param algos the MAPI names of permitted algorithms |
848
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
575 * @param appendMapiName if not null, append MAPI name of chose algorithm to this buffer |
838
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
576 * @return instance of the chosen digester |
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
577 * @throws MCLException if none of the options is supported |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
578 */ |
838
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
579 private MessageDigest pickBestAlgorithm(Set<String> algos, StringBuilder appendMapiName) throws MCLException { |
847
4d80fd66541d
formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
846
diff
changeset
|
580 for (String[] choice : KNOWN_ALGORITHMS) { |
846
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
581 String mapiName = choice[0]; |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
582 String algoName = choice[1]; |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
583 MessageDigest digest; |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
584 if (!algos.contains(mapiName)) |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
585 continue; |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
586 try { |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
587 digest = MessageDigest.getInstance(algoName); |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
588 } catch (NoSuchAlgorithmException e) { |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
589 continue; |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
590 } |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
591 // we found a match |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
592 if (appendMapiName != null) { |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
593 appendMapiName.append(mapiName); |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
594 } |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
595 return digest; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
596 } |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
597 String algoNames = String.join(",", algos); |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
598 throw new MCLException("No supported hash algorithm: " + algoNames); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
599 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
600 |
838
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
601 /** |
848
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
602 * Hash the text into the MessageDigest and append the hexadecimal form of the |
838
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
603 * resulting digest to buffer. |
847
4d80fd66541d
formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
846
diff
changeset
|
604 * |
838
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
605 * @param buffer where the hex digits are appended |
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
606 * @param digest where the hex digits come from after the text has been digested |
847
4d80fd66541d
formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
846
diff
changeset
|
607 * @param text text to digest |
838
3a477cf520f6
Debug and clarify pasword hashing code
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
836
diff
changeset
|
608 */ |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
609 private void hexhash(StringBuilder buffer, MessageDigest digest, String text) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
610 byte[] bytes = text.getBytes(StandardCharsets.UTF_8); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
611 digest.update(bytes); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
612 byte[] output = digest.digest(); |
847
4d80fd66541d
formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
846
diff
changeset
|
613 for (byte b : output) { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
614 int hi = (b & 0xF0) >> 4; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
615 int lo = b & 0x0F; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
616 buffer.append(HEXDIGITS[hi]); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
617 buffer.append(HEXDIGITS[lo]); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
618 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
619 } |
75
db46b4ab2b9f
Correct the condition for when the log can be closed: only when log instanceof FileWriter
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
53
diff
changeset
|
620 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
621 private String handleOptions(OptionsCallback callback, String optionsPart) throws MCLException { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
622 if (callback == null || optionsPart == null || optionsPart.isEmpty()) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
623 return ""; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
624 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
625 StringBuilder buffer = new StringBuilder(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
626 callback.setBuffer(buffer); |
847
4d80fd66541d
formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
846
diff
changeset
|
627 for (String optlevel : optionsPart.split(",")) { |
846
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
628 int eqindex = optlevel.indexOf('='); |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
629 if (eqindex < 0) |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
630 throw new MCLException("Invalid options part in server challenge: " + optionsPart); |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
631 String lang = optlevel.substring(0, eqindex); |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
632 int level; |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
633 try { |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
634 level = Integer.parseInt(optlevel.substring(eqindex + 1)); |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
635 } catch (NumberFormatException e) { |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
636 throw new MCLException("Invalid option level in server challenge: " + optlevel); |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
637 } |
f2689a3e9a95
convert space indents to tabs
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
843
diff
changeset
|
638 callback.addOptions(lang, level); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
639 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
640 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
641 return buffer.toString(); |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
642 } |
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
643 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
644 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
645 * Returns an InputStream that reads from this open connection on |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
646 * the MapiSocket. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
647 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
648 * @return an input stream that reads from this open connection |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
649 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
650 public InputStream getInputStream() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
651 return fromMonet; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
652 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
653 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
654 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
655 * Returns an output stream for this MapiSocket. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
656 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
657 * @return an output stream for writing bytes to this MapiSocket |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
658 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
659 public OutputStream getOutputStream() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
660 return toMonet; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
661 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
662 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
663 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
664 * Returns a Reader for this MapiSocket. The Reader is a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
665 * BufferedMCLReader which does protocol interpretation of the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
666 * BlockInputStream produced by this MapiSocket. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
667 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
668 * @return a BufferedMCLReader connected to this MapiSocket |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
669 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
670 public BufferedMCLReader getReader() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
671 return reader; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
672 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
673 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
674 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
675 * Returns a Writer for this MapiSocket. The Writer is a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
676 * BufferedMCLWriter which produces protocol compatible data blocks |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
677 * that the BlockOutputStream can properly translate into blocks. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
678 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
679 * @return a BufferedMCLWriter connected to this MapiSocket |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
680 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
681 public BufferedMCLWriter getWriter() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
682 return writer; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
683 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
684 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
685 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
686 * Returns the mapi protocol version used by this socket. The |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
687 * protocol version depends on the server being used. Users of the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
688 * MapiSocket should check this version to act appropriately. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
689 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
690 * @return the mapi protocol version |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
691 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
692 public int getProtocolVersion() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
693 return version; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
694 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
695 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
696 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
697 * Enables logging to a file what is read and written from and to |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
698 * the server. Logging can be enabled at any time. However, it is |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
699 * encouraged to start debugging before actually connecting the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
700 * socket. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
701 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
702 * @param filename the name of the file to write to |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
703 * @throws IOException if the file could not be opened for writing |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
704 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
705 public void debug(final String filename) throws IOException { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
706 debug(new FileWriter(filename)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
707 } |
75
db46b4ab2b9f
Correct the condition for when the log can be closed: only when log instanceof FileWriter
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
53
diff
changeset
|
708 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
709 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
710 * Enables logging to a stream what is read and written from and to |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
711 * the server. Logging can be enabled at any time. However, it is |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
712 * encouraged to start debugging before actually connecting the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
713 * socket. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
714 * |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
715 * @param out to write the log to a print stream |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
716 * @throws IOException if the file could not be opened for writing |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
717 */ |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
718 // disabled as it is not used by JDBC driver code |
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
719 // public void debug(PrintStream out) throws IOException { |
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
720 // debug(new PrintWriter(out)); |
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
721 // } |
75
db46b4ab2b9f
Correct the condition for when the log can be closed: only when log instanceof FileWriter
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
53
diff
changeset
|
722 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
723 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
724 * Enables logging to a stream what is read and written from and to |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
725 * the server. Logging can be enabled at any time. However, it is |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
726 * encouraged to start debugging before actually connecting the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
727 * socket. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
728 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
729 * @param out to write the log to |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
730 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
731 public void debug(final Writer out) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
732 log = out; |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
733 setDebug(true); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
734 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
735 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
736 /** |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
737 * Get the log Writer. |
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
738 * |
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
739 * @return the log writer |
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
740 */ |
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
741 public Writer getLogWriter() { |
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
742 return log; |
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
743 } |
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
744 |
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
745 /** |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
746 * Writes a logline tagged with a timestamp using the given type and message |
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
747 * and optionally flushes afterwards. |
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
748 * |
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
749 * Used for debugging purposes only and represents a message data that is |
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
750 * connected to reading (RD or RX) or writing (TD or TX) to the socket. |
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
751 * R=Receive, T=Transmit, D=Data, X=?? |
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
752 * |
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
753 * @param type message type: either RD, RX, TD or TX |
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
754 * @param message the message to log |
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
755 * @param flush whether we need to flush buffered data to the logfile. |
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
756 * @throws IOException if an IO error occurs while writing to the logfile |
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
757 */ |
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
758 private final void log(final String type, final String message, final boolean flush) throws IOException { |
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
759 log.write(type + System.currentTimeMillis() + ": " + message + "\n"); |
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
760 if (flush) |
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
761 log.flush(); |
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
762 } |
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
763 |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
764 /** |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
765 * For internal use |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
616
diff
changeset
|
766 * |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
616
diff
changeset
|
767 * @param b to enable/disable insert 'fake' newline and prompt |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
616
diff
changeset
|
768 * @return previous setting |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
769 */ |
511
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
770 public boolean setInsertFakePrompts(boolean b) { |
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
771 return fromMonet.setInsertFakePrompts(b); |
501
eaad79c3235f
Make the fake prompts at block ends optional
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
498
diff
changeset
|
772 } |
eaad79c3235f
Make the fake prompts at block ends optional
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
498
diff
changeset
|
773 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
774 public boolean isDebug() { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
775 return target.isDebug(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
776 } |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
777 |
905
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
904
diff
changeset
|
778 public boolean canClientInfo() { |
a52bc2dcdb8c
Implement ClientInfo API
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
904
diff
changeset
|
779 return supportsClientInfo; |
903
778959b2e0a4
Send ClientInfo on startup
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
867
diff
changeset
|
780 } |
778959b2e0a4
Send ClientInfo on startup
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
867
diff
changeset
|
781 |
867
5a59910e8f87
Resolve some javadoc errors and warnings
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
782 |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
783 /** |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
784 * Inner class that is used to write data on a normal stream as a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
785 * blocked stream. A call to the flush() method will write a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
786 * "final" block to the underlying stream. Non-final blocks are |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
787 * written as soon as one or more bytes would not fit in the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
788 * current block any more. This allows to write to a block to it's |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
789 * full size, and then flush it explicitly to have a final block |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
790 * being written to the stream. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
791 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
792 final class BlockOutputStream extends FilterOutputStream { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
793 private int writePos = 0; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
794 private int blocksize = 0; |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
795 private final byte[] block = new byte[BLOCK]; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
796 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
797 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
798 * Constructs this BlockOutputStream, backed by the given |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
799 * OutputStream. A BufferedOutputStream is internally used. |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
800 * @param out an OutputStream |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
801 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
802 public BlockOutputStream(final OutputStream out) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
803 // always use a buffered stream, even though we know how |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
804 // much bytes to write/read, since this is just faster for |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
805 // some reason |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
806 super(new BufferedOutputStream(out)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
807 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
808 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
809 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
810 public void flush() throws IOException { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
811 // write the block (as final) then flush. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
812 writeBlock(true); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
813 out.flush(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
814 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
815 // it's a bit nasty if an exception is thrown from the log, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
816 // but ignoring it can be nasty as well, so it is decided to |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
817 // let it go so there is feedback about something going wrong |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
818 // it's a bit nasty if an exception is thrown from the log, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
819 // but ignoring it can be nasty as well, so it is decided to |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
820 // let it go so there is feedback about something going wrong |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
821 if (isDebug()) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
822 log.flush(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
823 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
824 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
825 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
826 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
827 * writeBlock puts the data in the block on the stream. The |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
828 * boolean last controls whether the block is sent with an |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
829 * indicator to note it is the last block of a sequence or not. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
830 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
831 * @param last whether this is the last block |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
832 * @throws IOException if writing to the stream failed |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
833 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
834 public void writeBlock(final boolean last) throws IOException { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
835 if (last) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
836 // always fits, because of BLOCK's size |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
837 blocksize = (short)writePos; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
838 // this is the last block, so encode least |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
839 // significant bit in the first byte (little-endian) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
840 blklen[0] = (byte)(blocksize << 1 & 0xFF | 1); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
841 blklen[1] = (byte)(blocksize >> 7); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
842 } else { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
843 // always fits, because of BLOCK's size |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
844 blocksize = (short)BLOCK; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
845 // another block will follow, encode least |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
846 // significant bit in the first byte (little-endian) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
847 blklen[0] = (byte)(blocksize << 1 & 0xFF); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
848 blklen[1] = (byte)(blocksize >> 7); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
849 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
850 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
851 out.write(blklen); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
852 // write the actual block |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
853 out.write(block, 0, writePos); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
854 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
855 if (isDebug()) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
856 if (last) { |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
857 log("TD ", "write final block: " + writePos + " bytes", false); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
858 } else { |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
859 log("TD ", "write block: " + writePos + " bytes", false); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
860 } |
555
90c346571eb4
Use StandardCharsets.UTF_8 where possible
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
554
diff
changeset
|
861 log("TX ", new String(block, 0, writePos, StandardCharsets.UTF_8), true); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
862 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
863 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
864 writePos = 0; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
865 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
866 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
867 @Override |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
868 public void write(final int b) throws IOException { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
869 if (writePos == BLOCK) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
870 writeBlock(false); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
871 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
872 block[writePos++] = (byte)b; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
873 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
874 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
875 @Override |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
876 public void write(final byte[] b) throws IOException { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
877 write(b, 0, b.length); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
878 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
879 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
880 @Override |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
881 public void write(final byte[] b, int off, int len) throws IOException { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
882 while (len > 0) { |
556
87feb93330a6
Misc. changes suggested by analysis tool
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
555
diff
changeset
|
883 int t = BLOCK - writePos; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
884 if (len > t) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
885 System.arraycopy(b, off, block, writePos, t); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
886 off += t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
887 len -= t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
888 writePos += t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
889 writeBlock(false); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
890 } else { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
891 System.arraycopy(b, off, block, writePos, len); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
892 writePos += len; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
893 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
894 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
895 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
896 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
897 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
898 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
899 public void close() throws IOException { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
900 // we don't want the flush() method to be called (default of |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
901 // the FilterOutputStream), so we close manually here |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
902 out.close(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
903 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
904 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
905 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
906 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
907 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
908 * Inner class that is used to make the data on the blocked stream |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
909 * available as a normal stream. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
910 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
911 final class BlockInputStream extends FilterInputStream { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
912 private int readPos = 0; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
913 private int blockLen = 0; |
508
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
914 private boolean wasEndBlock = false; |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
915 private final byte[] block = new byte[BLOCK + 3]; // \n.\n |
511
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
916 private boolean insertFakePrompts = true; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
917 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
918 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
919 * Constructs this BlockInputStream, backed by the given |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
920 * InputStream. A BufferedInputStream is internally used. |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
921 * @param in an InputStream |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
922 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
923 public BlockInputStream(final InputStream in) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
924 // always use a buffered stream, even though we know how |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
925 // much bytes to write/read, since this is just faster for |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
926 // some reason |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
927 super(new BufferedInputStream(in)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
928 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
929 |
511
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
930 public boolean setInsertFakePrompts(boolean doFake) { |
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
931 boolean old = insertFakePrompts; |
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
932 insertFakePrompts = doFake; |
501
eaad79c3235f
Make the fake prompts at block ends optional
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
498
diff
changeset
|
933 return old; |
eaad79c3235f
Make the fake prompts at block ends optional
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
498
diff
changeset
|
934 } |
eaad79c3235f
Make the fake prompts at block ends optional
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
498
diff
changeset
|
935 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
936 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
937 public int available() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
938 return blockLen - readPos; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
939 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
940 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
941 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
942 public boolean markSupported() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
943 return false; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
944 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
945 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
946 @Override |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
947 public void mark(final int readlimit) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
948 throw new AssertionError("Not implemented!"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
949 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
950 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
951 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
952 public void reset() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
953 throw new AssertionError("Not implemented!"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
954 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
955 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
956 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
957 * Small wrapper to get a blocking variant of the read() method |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
958 * on the BufferedInputStream. We want to benefit from the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
959 * Buffered pre-fetching, but not dealing with half blocks. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
960 * Changing this class to be able to use the partially received |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
961 * data will greatly complicate matters, while a performance |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
962 * improvement is debatable given the relatively small size of |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
963 * our blocks. Maybe it does speed up on slower links, then |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
964 * consider this method a quick bug fix/workaround. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
965 * |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
966 * @param b a byte array to store read bytes |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
967 * @param len number of bytes to read |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
968 * @return false if reading the block failed due to EOF |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
969 * @throws IOException if an IO error occurs while reading |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
970 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
971 private boolean _read(final byte[] b, int len) throws IOException { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
972 int s; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
973 int off = 0; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
974 while (len > 0) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
975 s = in.read(b, off, len); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
976 if (s == -1) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
977 // if we have read something before, we should have been |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
978 // able to read the whole, so make this fatal |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
979 if (off > 0) { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
980 if (isDebug()) { |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
981 log("RD ", "the following incomplete block was received:", false); |
555
90c346571eb4
Use StandardCharsets.UTF_8 where possible
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
554
diff
changeset
|
982 log("RX ", new String(b, 0, off, StandardCharsets.UTF_8), true); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
983 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
984 throw new IOException("Read from " + |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
985 con.getInetAddress().getHostName() + ":" + |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
986 con.getPort() + ": Incomplete block read from stream"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
987 } |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
988 if (isDebug()) |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
989 log("RD ", "server closed the connection (EOF)", true); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
990 return false; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
991 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
992 len -= s; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
993 off += s; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
994 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
995 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
996 return true; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
997 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
998 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
999 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1000 * Reads the next block on the stream into the internal buffer, |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1001 * or writes the prompt in the buffer. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1002 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1003 * The blocked stream protocol consists of first a two byte |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1004 * integer indicating the length of the block, then the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1005 * block, followed by another length + block. The end of |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1006 * such sequence is put in the last bit of the length, and |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1007 * hence this length should be shifted to the right to |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1008 * obtain the real length value first. We simply fetch |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1009 * blocks here as soon as they are needed for the stream's |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1010 * read methods. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1011 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1012 * The user-flush, which is an implicit effect of the end of |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1013 * a block sequence, is communicated beyond the stream by |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1014 * inserting a prompt sequence on the stream after the last |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1015 * block. This method makes sure that a final block ends with a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1016 * newline, if it doesn't already, in order to facilitate a |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1017 * Reader that is possibly chained to this InputStream. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1018 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1019 * If the stream is not positioned correctly, hell will break |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1020 * loose. |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
1021 * |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
1022 * @return blockLen |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
1023 * @throws IOException if an IO error occurs while reading |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1024 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1025 private int readBlock() throws IOException { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1026 // read next two bytes (short) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1027 if (!_read(blklen, 2)) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1028 return(-1); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1029 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1030 // Get the short-value and store its value in blockLen. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1031 blockLen = (short)( |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1032 (blklen[0] & 0xFF) >> 1 | |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1033 (blklen[1] & 0xFF) << 7 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1034 ); |
508
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1035 wasEndBlock = (blklen[0] & 0x1) == 1; |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1036 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1037 readPos = 0; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1038 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1039 if (isDebug()) { |
508
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1040 if (wasEndBlock) { |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
1041 log("RD ", "read final block: " + blockLen + " bytes", false); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1042 } else { |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
1043 log("RD ", "read new block: " + blockLen + " bytes", false); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1044 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1045 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1046 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1047 // sanity check to avoid bad servers make us do an ugly |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1048 // stack trace |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1049 if (blockLen > block.length) |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
1050 throw new IOException("Server sent a block larger than BLOCKsize: " + |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1051 blockLen + " > " + block.length); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1052 if (!_read(block, blockLen)) |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
1053 return -1; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1054 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1055 if (isDebug()) |
555
90c346571eb4
Use StandardCharsets.UTF_8 where possible
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
554
diff
changeset
|
1056 log("RX ", new String(block, 0, blockLen, StandardCharsets.UTF_8), true); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1057 |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
1058 // if this is the last block, make it end with a newline and prompt |
508
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1059 if (wasEndBlock) { |
537
242debd7e866
Fix mistake in comment
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
1060 // insert 'fake' newline and prompt |
511
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
1061 if (insertFakePrompts) { |
507
1db3398b78f7
If we don't want a fake prompt we probably also don't want a fake newline
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
502
diff
changeset
|
1062 if (blockLen > 0 && block[blockLen - 1] != '\n') { |
1db3398b78f7
If we don't want a fake prompt we probably also don't want a fake newline
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
502
diff
changeset
|
1063 // to terminate the block in a Reader |
1db3398b78f7
If we don't want a fake prompt we probably also don't want a fake newline
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
502
diff
changeset
|
1064 block[blockLen++] = '\n'; |
1db3398b78f7
If we don't want a fake prompt we probably also don't want a fake newline
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
502
diff
changeset
|
1065 } |
501
eaad79c3235f
Make the fake prompts at block ends optional
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
498
diff
changeset
|
1066 for (byte b : LineType.PROMPT.bytes()) { |
eaad79c3235f
Make the fake prompts at block ends optional
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
498
diff
changeset
|
1067 block[blockLen++] = b; |
eaad79c3235f
Make the fake prompts at block ends optional
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
498
diff
changeset
|
1068 } |
eaad79c3235f
Make the fake prompts at block ends optional
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
498
diff
changeset
|
1069 block[blockLen++] = '\n'; |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1070 if (isDebug()) { |
511
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
1071 log("RD ", "inserting prompt", true); |
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
1072 } |
498
4cfe4991ee63
Use the prompt characters from mapi_prompt.h
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
497
diff
changeset
|
1073 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1074 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1075 |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
1076 return blockLen; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1077 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1078 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1079 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1080 public int read() throws IOException { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1081 if (available() == 0) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1082 if (readBlock() == -1) |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
1083 return -1; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1084 } |
75
db46b4ab2b9f
Correct the condition for when the log can be closed: only when log instanceof FileWriter
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
53
diff
changeset
|
1085 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1086 if (isDebug()) |
555
90c346571eb4
Use StandardCharsets.UTF_8 where possible
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
554
diff
changeset
|
1087 log("RX ", new String(block, readPos, 1, StandardCharsets.UTF_8), true); |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
1088 |
816
9188263368cc
InputStream.read must return the byte UNSIGNED!
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1089 return block[readPos++] & 0xFF; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1090 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1091 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1092 @Override |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
1093 public int read(final byte[] b) throws IOException { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1094 return read(b, 0, b.length); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1095 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1096 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1097 @Override |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
1098 public int read(final byte[] b, int off, int len) throws IOException { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1099 int t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1100 int size = 0; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1101 while (size < len) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1102 t = available(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1103 if (t == 0) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1104 if (size != 0) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1105 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1106 if (readBlock() == -1) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1107 if (size == 0) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1108 size = -1; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1109 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1110 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1111 t = available(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1112 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1113 if (len > t) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1114 System.arraycopy(block, readPos, b, off, t); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1115 off += t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1116 len -= t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1117 readPos += t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1118 size += t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1119 } else { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1120 System.arraycopy(block, readPos, b, off, len); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1121 readPos += len; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1122 size += len; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1123 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1124 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1125 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1126 return size; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1127 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1128 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1129 @Override |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
281
diff
changeset
|
1130 public long skip(final long n) throws IOException { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1131 long skip = n; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1132 while (skip > 0) { |
556
87feb93330a6
Misc. changes suggested by analysis tool
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
555
diff
changeset
|
1133 int t = available(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1134 if (skip > t) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1135 skip -= t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1136 readPos += t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1137 readBlock(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1138 } else { |
756
a39d3a45da56
Resolve warning: [lossy-conversions] implicit cast from long to int in compound assignment is possibly lossy
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
750
diff
changeset
|
1139 readPos += (int)skip; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1140 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1141 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1142 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1143 return n; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1144 } |
508
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1145 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1146 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1147 * For internal use |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
1148 * @return new Raw object |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1149 */ |
508
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1150 Raw getRaw() { |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1151 return new Raw(); |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1152 } |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1153 |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1154 /** An alternative I/O interface that exposes the block based nature of the MAPI protocol */ |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1155 final class Raw { |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1156 byte[] getBytes() { |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1157 return block; |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1158 } |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1159 |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1160 int getLength() { |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1161 return blockLen; |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1162 } |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1163 |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1164 int getPosition() { |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1165 return readPos; |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1166 } |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1167 |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1168 int consume(int delta) { |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1169 int pos = readPos; |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1170 readPos += delta; |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1171 return pos; |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1172 } |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1173 |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1174 int readBlock() throws IOException { |
511
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
1175 boolean wasFaking = setInsertFakePrompts(false); |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1176 try { |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1177 return BlockInputStream.this.readBlock(); |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1178 } finally { |
511
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
1179 setInsertFakePrompts(wasFaking); |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1180 } |
508
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1181 } |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1182 |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1183 boolean wasEndBlock() { |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1184 return wasEndBlock; |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1185 } |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1186 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1187 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1188 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1189 /** |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
1190 * Closes the streams and socket connected to the server if possible. |
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
1191 * If an error occurs at closing a resource, it is ignored so as many |
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
1192 * resources as possible are closed. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1193 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1194 public synchronized void close() { |
53
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1195 if (writer != null) { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1196 try { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1197 writer.close(); |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1198 writer = null; |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1199 } catch (IOException e) { /* ignore it */ } |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1200 } |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1201 if (reader != null) { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1202 try { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1203 reader.close(); |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1204 reader = null; |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1205 } catch (IOException e) { /* ignore it */ } |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1206 } |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1207 if (toMonet != null) { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1208 try { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1209 toMonet.close(); |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1210 toMonet = null; |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1211 } catch (IOException e) { /* ignore it */ } |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1212 } |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1213 if (fromMonet != null) { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1214 try { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1215 fromMonet.close(); |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1216 fromMonet = null; |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1217 } catch (IOException e) { /* ignore it */ } |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1218 } |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1219 if (con != null) { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1220 try { |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
1221 con.close(); // close the socket |
53
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1222 con = null; |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1223 } catch (IOException e) { /* ignore it */ } |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1224 } |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1225 if (isDebug() && log != null && log instanceof FileWriter) { |
53
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1226 try { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1227 log.close(); |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1228 log = null; |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1229 } catch (IOException e) { /* ignore it */ } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1230 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1231 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1232 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1233 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1234 * Return an UploadStream for use with for example COPY FROM filename ON CLIENT. |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1235 * |
552
7b320303b579
Doc comment improvements
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
547
diff
changeset
|
1236 * Building block for {@link org.monetdb.jdbc.MonetConnection.UploadHandler}. |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
616
diff
changeset
|
1237 * |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1238 * @param chunkSize chunk size for the upload stream |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
616
diff
changeset
|
1239 * @return UploadStream new upload stream with the given chunk size |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1240 */ |
521
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1241 public UploadStream uploadStream(int chunkSize) { |
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1242 return new UploadStream(chunkSize); |
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1243 } |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1244 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1245 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1246 * Return an UploadStream for use with for example COPY FROM filename ON CLIENT. |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1247 * |
552
7b320303b579
Doc comment improvements
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
547
diff
changeset
|
1248 * Building block for {@link org.monetdb.jdbc.MonetConnection.UploadHandler}. |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
616
diff
changeset
|
1249 * |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
616
diff
changeset
|
1250 * @return UploadStream new upload stream |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1251 */ |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1252 public UploadStream uploadStream() { |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1253 return new UploadStream(); |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1254 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1255 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1256 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1257 * Return a DownloadStream for use with for example COPY INTO filename ON CLIENT |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1258 * |
552
7b320303b579
Doc comment improvements
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
547
diff
changeset
|
1259 * Building block for {@link org.monetdb.jdbc.MonetConnection.DownloadHandler}. |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
616
diff
changeset
|
1260 * |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1261 * @param prependCr convert \n to \r\n |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
616
diff
changeset
|
1262 * @return DownloadStream new download stream |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1263 */ |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1264 public DownloadStream downloadStream(boolean prependCr) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1265 return new DownloadStream(fromMonet.getRaw(), toMonet, prependCr); |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1266 } |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1267 |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1268 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1269 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1270 * Stream of data sent to the server |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1271 * |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1272 * Building block for {@link org.monetdb.jdbc.MonetConnection.UploadHandler}. |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1273 * |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1274 * An UploadStream has a chunk size. Every chunk size bytes, the server gets |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1275 * the opportunity to abort the upload. |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1276 */ |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1277 public class UploadStream extends FilterOutputStream { |
521
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1278 public final static int DEFAULT_CHUNK_SIZE = 1024 * 1024; |
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1279 private final int chunkSize; |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1280 private boolean closed = false; |
533
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1281 private boolean serverCancelled = false; |
521
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1282 private int chunkLeft; |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1283 private byte[] promptBuffer; |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1284 private Runnable cancellationCallback = null; |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1285 |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
1286 /** |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
1287 * Create an UploadStream with the given chunk size |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
1288 * @param chunkSize chunk size for the upload stream |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
1289 */ |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1290 UploadStream(final int chunkSize) { |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1291 super(toMonet); |
521
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1292 if (chunkSize <= 0) { |
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1293 throw new IllegalArgumentException("chunk size must be positive"); |
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1294 } |
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1295 this.chunkSize = chunkSize; |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1296 assert LineType.MORE.bytes().length == LineType.FILETRANSFER.bytes().length; |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1297 int promptLen = LineType.MORE.bytes().length; |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1298 promptBuffer = new byte[promptLen + 1]; |
521
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1299 chunkLeft = this.chunkSize; |
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1300 } |
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1301 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1302 /** Create an UploadStream with the default chunk size */ |
521
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1303 UploadStream() { |
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1304 this(DEFAULT_CHUNK_SIZE); |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1305 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1306 |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1307 /** Set a callback to be invoked if the server cancels the upload |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
616
diff
changeset
|
1308 * |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
616
diff
changeset
|
1309 * @param cancellationCallback callback to call |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1310 */ |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1311 public void setCancellationCallback(final Runnable cancellationCallback) { |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1312 this.cancellationCallback = cancellationCallback; |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1313 } |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1314 |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1315 @Override |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1316 public void write(final int b) throws IOException { |
533
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1317 if (serverCancelled) { |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1318 // We have already thrown an exception and apparently that has been ignored. |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1319 // Probably because they're calling print methods instead of write. |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1320 // Throw another one, maybe they'll catch this one. |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1321 throw new IOException("Server aborted the upload"); |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1322 } |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1323 handleChunking(); |
612
1d44b8a577ca
write to out, not to super when implementing FilterOutputStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
1324 out.write(b); |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1325 wrote(1); |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1326 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1327 |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1328 @Override |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1329 public void write(final byte[] b) throws IOException { |
612
1d44b8a577ca
write to out, not to super when implementing FilterOutputStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
1330 this.write(b, 0, b.length); |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1331 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1332 |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1333 @Override |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1334 public void write(final byte[] b, int off, int len) throws IOException { |
533
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1335 if (serverCancelled) { |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1336 // We have already thrown an exception and apparently that has been ignored. |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1337 // Probably because they're calling print methods instead of write. |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1338 // Throw another one, maybe they'll catch this one. |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1339 throw new IOException("Server aborted the upload"); |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1340 } |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1341 while (len > 0) { |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1342 handleChunking(); |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1343 int toWrite = Integer.min(len, chunkLeft); |
612
1d44b8a577ca
write to out, not to super when implementing FilterOutputStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
1344 out.write(b, off, toWrite); |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1345 off += toWrite; |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1346 len -= toWrite; |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1347 wrote(toWrite); |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1348 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1349 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1350 |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1351 @Override |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1352 public void flush() throws IOException { |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1353 // suppress flushes |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1354 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1355 |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1356 @Override |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1357 public void close() throws IOException { |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1358 if (closed) { |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1359 return; |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1360 } |
533
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1361 closed = true; |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1362 |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1363 if (serverCancelled) |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1364 closeAfterServerCancelled(); |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1365 else |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1366 closeAfterSuccesfulUpload(); |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1367 } |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1368 |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1369 private void closeAfterSuccesfulUpload() throws IOException { |
521
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1370 if (chunkLeft != chunkSize) { |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1371 // flush pending data |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1372 flushAndReadPrompt(); |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1373 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1374 // send empty block |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1375 out.flush(); |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1376 final LineType acknowledgement = readPrompt(); |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1377 if (acknowledgement != LineType.FILETRANSFER) { |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1378 throw new IOException("Expected server to acknowledge end of file"); |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1379 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1380 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1381 |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1382 private void closeAfterServerCancelled() { |
533
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1383 // nothing to do here, we have already read the error prompt. |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1384 } |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1385 |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1386 private void wrote(final int i) { |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1387 chunkLeft -= i; |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1388 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1389 |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1390 private void handleChunking() throws IOException { |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1391 if (chunkLeft > 0) { |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1392 return; |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1393 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1394 flushAndReadPrompt(); |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1395 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1396 |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1397 private void flushAndReadPrompt() throws IOException { |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1398 out.flush(); |
521
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1399 chunkLeft = chunkSize; |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1400 final LineType lineType = readPrompt(); |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1401 switch (lineType) { |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1402 case MORE: |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1403 return; |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1404 case FILETRANSFER: |
533
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1405 // Note, if the caller is calling print methods instead of write, the IO exception gets hidden. |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1406 // This is unfortunate but there's nothing we can do about it. |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1407 serverCancelled = true; |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1408 if (cancellationCallback != null) { |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1409 cancellationCallback.run(); |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1410 } |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1411 throw new IOException("Server aborted the upload"); |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1412 default: |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1413 throw new IOException("Expected MORE/DONE from server, got " + lineType); |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1414 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1415 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1416 |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1417 private LineType readPrompt() throws IOException { |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1418 final int nread = fromMonet.read(promptBuffer); |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1419 if (nread != promptBuffer.length || promptBuffer[promptBuffer.length - 1] != '\n') { |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1420 throw new IOException("server return incomplete prompt"); |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1421 } |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1422 return LineType.classify(promptBuffer); |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1423 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1424 } |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1425 |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1426 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1427 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1428 * Stream of data received from the server |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1429 * |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1430 * Building block for {@link org.monetdb.jdbc.MonetConnection.DownloadHandler}. |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1431 */ |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1432 public static class DownloadStream extends InputStream { |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1433 private final BlockInputStream.Raw rawIn; |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1434 private final OutputStream out; |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1435 private final boolean prependCr; |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1436 private boolean endBlockSeen = false; |
547
8029d7368b5a
Make sure the download stream isn't closed twice
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
541
diff
changeset
|
1437 private boolean closed = false; |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1438 private boolean newlinePending = false; // used for crlf conversion |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1439 |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1440 DownloadStream(BlockInputStream.Raw rawIn, OutputStream out, boolean prependCr) { |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1441 this.rawIn = rawIn; |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1442 this.out = out; |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1443 this.prependCr = prependCr; |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1444 } |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1445 |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1446 void nextBlock() throws IOException { |
547
8029d7368b5a
Make sure the download stream isn't closed twice
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
541
diff
changeset
|
1447 if (endBlockSeen || closed) |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1448 return; |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1449 final int ret = rawIn.readBlock(); |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1450 if (ret < 0 || rawIn.wasEndBlock()) { |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1451 endBlockSeen = true; |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1452 } |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1453 } |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1454 |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1455 @Override |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1456 public void close() throws IOException { |
547
8029d7368b5a
Make sure the download stream isn't closed twice
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
541
diff
changeset
|
1457 if (closed) |
8029d7368b5a
Make sure the download stream isn't closed twice
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
541
diff
changeset
|
1458 return; |
8029d7368b5a
Make sure the download stream isn't closed twice
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
541
diff
changeset
|
1459 closed = true; |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1460 while (!endBlockSeen) { |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1461 nextBlock(); |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1462 } |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1463 // Send acknowledgement to server |
512
a4000e374a43
Fix silly mistake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
1464 out.write('\n'); |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1465 out.flush(); |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1466 // Do whatever super has to do |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1467 super.close(); |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1468 } |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1469 |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1470 @Override |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1471 public int read() throws IOException { |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1472 final byte[] buf = { 0 }; |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1473 final int nread = read(buf, 0, 1); |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1474 if (nread == 1) |
816
9188263368cc
InputStream.read must return the byte UNSIGNED!
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1475 return buf[0] & 0xFF; |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1476 else |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1477 return -1; |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1478 } |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1479 |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1480 @Override |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1481 public int read(final byte[] dest, int off, int len) throws IOException { |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1482 final int origOff = off; |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1483 int end = off + len; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1484 |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1485 while (off < end) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1486 // minimum of what's requested and what we have in stock |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1487 int chunk = Integer.min(end - off, rawIn.getLength() - rawIn.getPosition()); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1488 assert chunk >= 0; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1489 if (chunk == 0) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1490 // make progress by fetching more data |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1491 if (endBlockSeen) |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1492 break; |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1493 nextBlock(); |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1494 continue; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1495 } |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1496 // make progress copying some bytes |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1497 if (!prependCr) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1498 // no conversion needed, use arraycopy |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1499 System.arraycopy(rawIn.getBytes(), rawIn.getPosition(), dest, off, chunk); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1500 off += chunk; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1501 rawIn.consume(chunk); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1502 } else { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1503 int chunkEnd = off + chunk; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1504 if (newlinePending && off < chunkEnd) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1505 // we were in the middle of a line ending conversion |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1506 dest[off++] = '\n'; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1507 newlinePending = false; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1508 } |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1509 while (off < chunkEnd) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1510 byte b = rawIn.getBytes()[rawIn.consume(1)]; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1511 if (b != '\n') { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1512 dest[off++] = b; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1513 } else if (chunkEnd - off >= 2) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1514 dest[off++] = '\r'; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1515 dest[off++] = '\n'; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1516 } else { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1517 dest[off++] = '\r'; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1518 newlinePending = true; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1519 break; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1520 } |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1521 } |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1522 } |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1523 } |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1524 |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1525 if (off < end && newlinePending) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1526 dest[off++] = '\n'; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1527 newlinePending = false; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1528 } |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1529 |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1530 if (off == origOff && endBlockSeen) |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1531 return -1; |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1532 else |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1533 return off - origOff; |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1534 } |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1535 } |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1536 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1537 /** |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1538 * Callback used during the initial MAPI handshake. |
848
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
1539 * |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1540 * Newer MonetDB versions allow setting some options during the handshake. |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1541 * The options are language-specific and each has a 'level'. The server |
848
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
1542 * advertises up to which level options are supported for a given language. |
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
1543 * For each language/option combination, {@link #addOptions} will be invoked |
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
1544 * during the handshake. This method should call {@link #contribute} for each |
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
1545 * option it wants to set. |
ac56897d3452
comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
847
diff
changeset
|
1546 * |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1547 * At the time of writing, only the 'sql' language supports options, |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1548 * they are listed in enum mapi_handshake_options_levels in mapi.h. |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1549 */ |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1550 public static abstract class OptionsCallback { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1551 private StringBuilder buffer; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1552 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1553 /** |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1554 * Callback called for each language/level combination supported by the |
839
33fadeb034a7
fix comments
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
838
diff
changeset
|
1555 * server. May call {@link #contribute} for options with a level STRICTLY |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1556 * LOWER than the level passed as a parameter. |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1557 * @param lang language advertised by the server |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1558 * @param level one higher than the maximum supported option |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1559 */ |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1560 public abstract void addOptions(String lang, int level); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1561 |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1562 /** |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1563 * Pass option=value during the handshake |
867
5a59910e8f87
Resolve some javadoc errors and warnings
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
1564 * @param field name |
5a59910e8f87
Resolve some javadoc errors and warnings
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
1565 * @param value int value |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1566 */ |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1567 protected void contribute(String field, int value) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1568 if (buffer.length() > 0) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1569 buffer.append(','); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1570 buffer.append(field); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1571 buffer.append('='); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1572 buffer.append(value); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1573 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1574 |
867
5a59910e8f87
Resolve some javadoc errors and warnings
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
1575 /** |
5a59910e8f87
Resolve some javadoc errors and warnings
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
1576 * Set the buffer |
5a59910e8f87
Resolve some javadoc errors and warnings
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
1577 * @param buf a non null StringBuilder object |
5a59910e8f87
Resolve some javadoc errors and warnings
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
852
diff
changeset
|
1578 */ |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1579 void setBuffer(StringBuilder buf) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1580 buffer = buf; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1581 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1582 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1583 } |