Mercurial > hg > monetdb-java
annotate src/main/java/org/monetdb/mcl/net/MapiSocket.java @ 835:071be9a628e8 monetdbs
Suppress warning about unchecked conversion
author | Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com> |
---|---|
date | Fri, 15 Dec 2023 10:51:19 +0100 (16 months ago) |
parents | 5aa19bbed0d6 |
children | aad275e042b2 |
rev | line source |
---|---|
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1 /* |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2 * 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
|
3 * 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
|
4 * 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
|
5 * |
716
aeb268156580
Updated Copyright year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
709
diff
changeset
|
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2023 MonetDB B.V. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
7 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
8 |
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
|
9 package org.monetdb.mcl.net; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
10 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
11 import java.io.BufferedInputStream; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
12 import java.io.BufferedOutputStream; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
13 import java.io.FileWriter; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
14 import java.io.FilterInputStream; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
15 import java.io.FilterOutputStream; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
16 import java.io.IOException; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
17 import java.io.InputStream; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
18 import java.io.OutputStream; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
19 import java.io.Writer; |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
20 import java.net.*; |
555
90c346571eb4
Use StandardCharsets.UTF_8 where possible
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
554
diff
changeset
|
21 import java.nio.charset.StandardCharsets; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
22 import java.security.MessageDigest; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
23 import java.security.NoSuchAlgorithmException; |
811
ede3a59ff4f2
Add MapiSocket.connect(url, properties) method
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
803
diff
changeset
|
24 import java.util.*; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
25 |
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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 import org.monetdb.mcl.parser.MCLParseException; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
31 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
32 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
33 * 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
|
34 * mode. |
53
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
35 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
36 * 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
|
37 * 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
|
38 * 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
|
39 * 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
|
40 * 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
|
41 * 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
|
42 * 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
|
43 * 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
|
44 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
45 * 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
|
46 * 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
|
47 * 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
|
48 * 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
|
49 * line read. |
53
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
50 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
51 * 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
|
52 * 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
|
53 * to a file on disk. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
54 * 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
|
55 * 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
|
56 * 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
|
57 * 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
|
58 * 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
|
59 * 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
|
60 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
61 * 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
|
62 * 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
|
63 * normal Socket, allowing for seamless plugging. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
64 * <pre> |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
65 * Socket \ / InputStream ----> (BufferedMCL)Reader |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
66 * > o < |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
67 * MapiSocket / \ OutputStream ----> (BufferedMCL)Writer |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
68 * </pre> |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
69 * 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
|
70 * 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
|
71 * 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
|
72 * 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
|
73 * interface is most sufficient. In particular the BufferedMCL* |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
74 * implementations of those interfaces supply some extra functionality |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
75 * geared towards the format of the data. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
76 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
77 * @author Fabian Groffen |
768
a80c21fe7bb2
Removed deprecated nl.cwi.monetdb.*.* classes and package.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
756
diff
changeset
|
78 * @version 4.3 |
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
|
79 * @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
|
80 * @see org.monetdb.mcl.io.BufferedMCLWriter |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
81 */ |
768
a80c21fe7bb2
Removed deprecated nl.cwi.monetdb.*.* classes and package.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
756
diff
changeset
|
82 public final class MapiSocket { |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
83 /* an even number of NUL bytes used during the handshake */ |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
84 private static final byte[] NUL_BYTES = new byte[]{ 0, 0, 0, 0, 0, 0, 0, 0, }; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
85 |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
86 /* 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
|
87 * 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
|
88 */ |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
89 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
|
90 {"SHA512", "SHA-512"}, |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
91 {"SHA384", "SHA-384"}, |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
92 {"SHA256", "SHA-256"}, |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
93 // should we deprecate this by now? |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
94 {"SHA1", "SHA-1"}, |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
95 }; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
96 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
97 // MUST be lowercase! |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
98 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
|
99 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
100 /** Connection parameters */ |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
101 private Target target; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
102 /** The TCP Socket to mserver */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
103 private Socket con; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
104 /** 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
|
105 private BlockInputStream fromMonet; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
106 /** Stream from the Socket for writing */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
107 private OutputStream toMonet; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
108 /** MCLReader on the InputStream */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
109 private BufferedMCLReader reader; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
110 /** MCLWriter on the OutputStream */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
111 private BufferedMCLWriter writer; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
112 /** protocol version of the connection */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
113 private int version; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
114 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
115 /** Whether we should follow redirects */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
116 private boolean followRedirects = true; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
117 /** 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
|
118 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
|
119 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
120 /** The Writer for the debug log-file */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
121 private Writer log; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
122 |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
123 /** 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
|
124 public final static int BLOCK = 8190; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
125 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
126 /** 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
|
127 private final byte[] blklen = new byte[2]; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
128 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
129 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
130 * Constructs a new MapiSocket. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
131 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
132 public MapiSocket() { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
133 target = new Target(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
134 con = null; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
135 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
136 |
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 * 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
|
139 * 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
|
140 * is also the default. |
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 * @param db the database |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
143 */ |
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
|
144 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
|
145 target.setDatabase(db); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
146 } |
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 * Sets the language to use for this connection. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
150 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
151 * @param lang the language |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
152 */ |
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
|
153 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
|
154 target.setLanguage(lang); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
155 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
156 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
157 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
158 * 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
|
159 * 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
|
160 * 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
|
161 * separating the hashes by commas. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
162 * 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
|
163 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
164 * @param hash the hash method to use |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
165 */ |
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
|
166 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
|
167 target.setHash(hash); |
0
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 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
171 * 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
|
172 * to false, an MCLException will be thrown when a redirect is |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
173 * encountered during connect. The default bahaviour is to |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
174 * automatically follow redirects. |
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 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
|
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 setFollowRedirects(final boolean r) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
179 this.followRedirects = r; |
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 the number of redirects that are followed when |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
184 * 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
|
185 * 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
|
186 * 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
|
187 * disable the following of redirects you should use |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
188 * setFollowRedirects. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
189 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
190 * @see #setFollowRedirects(boolean r) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
191 * @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
|
192 */ |
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
|
193 public void setTTL(final int t) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
194 this.ttl = t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
195 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
196 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
197 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
198 * 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
|
199 * 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
|
200 * useful to break out of this indefinite wait. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
201 * 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
|
202 * operation to have effect. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
203 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
204 * @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
|
205 * 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
|
206 * @throws SocketException Issue with the socket |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
207 */ |
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
|
208 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
|
209 if (s < 0) { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
210 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
|
211 } |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
212 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
|
213 // 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
|
214 if (con != null) { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
215 con.setSoTimeout(s); |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
216 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
217 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
218 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
219 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
220 * Gets the SO_TIMEOUT from the underlying Socket. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
221 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
222 * @return the currently in use timeout in milliseconds |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
223 * @throws SocketException Issue with the socket |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
224 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
225 public int getSoTimeout() throws SocketException { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
226 return target.getSoTimeout(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
227 } |
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
|
228 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
229 /** |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
230 * 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
|
231 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
232 * @param debug Value to set |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
233 */ |
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
|
234 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
|
235 target.setDebug(debug); |
0
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 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
238 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
239 * 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
|
240 * user. If followRedirect is false, a RedirectionException is |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
241 * thrown when a redirect is encountered. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
242 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
243 * @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
|
244 * @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
|
245 * @param user the username |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
246 * @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
|
247 * @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
|
248 * 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
|
249 * @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
|
250 * @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
|
251 * @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
|
252 * @throws MCLParseException if bogus data is received |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
253 * @throws MCLException if an MCL related error occurs |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
254 */ |
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
|
255 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
|
256 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
|
257 { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
258 target.setHost(host); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
259 target.setPort(port); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
260 target.setUser(user); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
261 target.setPassword(pass); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
262 return connect(target, null); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
263 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
264 |
811
ede3a59ff4f2
Add MapiSocket.connect(url, properties) method
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
803
diff
changeset
|
265 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
|
266 return connect(new Target(url, props), null); |
ede3a59ff4f2
Add MapiSocket.connect(url, properties) method
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
803
diff
changeset
|
267 } |
ede3a59ff4f2
Add MapiSocket.connect(url, properties) method
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
803
diff
changeset
|
268 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
269 /** |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
270 * 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
|
271 * If followRedirect is false, a RedirectionException is |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
272 * thrown when a redirect is encountered. |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
273 * |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
274 * 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
|
275 * 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
|
276 * To do so, create and pass a subclass of {@link MapiSocket.OptionsCallback}. |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
277 * |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
278 * @param target the connection settings |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
279 * @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
|
280 * initial handshake |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
281 * @return A List with informational (warning) messages. If this |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
282 * list is empty; then there are no warnings. |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
283 * @throws IOException if an I/O error occurs when creating the socket |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
284 * @throws SocketException - if there is an error in the underlying protocol, such as a TCP error. |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
285 * @throws UnknownHostException if the IP address of the host could not be determined |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
286 * @throws MCLParseException if bogus data is received |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
287 * @throws MCLException if an MCL related error occurs |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
288 */ |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
289 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
|
290 // 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
|
291 close(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
292 this.target = target; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
293 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
294 Target.Validated validated; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
295 try { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
296 validated = target.validate(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
297 } catch (ValidationError e) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
298 throw new MCLException(e.getMessage()); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
299 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
300 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
301 if (validated.connectScan()) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
302 return scanUnixSockets(callback); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
303 } |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
304 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
305 ArrayList<String> warnings = new ArrayList<>(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
306 int attempts = 0; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
307 do { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
308 boolean ok = false; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
309 try { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
310 boolean done = tryConnect(callback, warnings); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
311 ok = true; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
312 if (done) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
313 return warnings; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
314 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
315 } finally { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
316 if (!ok) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
317 close(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
318 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
319 } while (attempts++ < this.ttl); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
320 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
|
321 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
322 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
323 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
|
324 // 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
|
325 // target.connectScan() will now return false; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
326 target.setHost("localhost"); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
327 return connect(target, callback); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
328 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
329 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
330 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
|
331 try { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
332 // We need a valid target |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
333 Target.Validated validated = target.validate(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
334 // 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
|
335 if (con == null) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
336 connectSocket(validated); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
337 return handshake(validated, callback, warningBuffer); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
338 } catch (IOException | MCLException e) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
339 close(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
340 throw e; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
341 } catch (ValidationError e) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
342 close(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
343 throw new MCLException(e.getMessage()); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
344 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
345 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
346 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
347 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
|
348 // 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
|
349 String tcpHost = validated.connectTcp(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
350 if (tcpHost.isEmpty()) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
351 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
|
352 } |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
353 int port = validated.connectPort(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
354 Socket sock = new Socket(tcpHost, port); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
355 sock.setSoTimeout(validated.getSoTimeout()); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
356 sock.setTcpNoDelay(true); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
357 sock.setKeepAlive(true); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
358 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
359 sock = wrapTLS(sock, validated); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
360 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
361 fromMonet = new BlockInputStream(sock.getInputStream()); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
362 toMonet = new BlockOutputStream(sock.getOutputStream()); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
363 reader = new BufferedMCLReader(fromMonet, StandardCharsets.UTF_8); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
364 writer = new BufferedMCLWriter(toMonet, StandardCharsets.UTF_8); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
365 writer.registerReader(reader); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
366 reader.advance(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
367 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
368 // Only assign to sock when everything went ok so far |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
369 con = sock; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
370 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
371 |
800
09f463444dde
TLS support in its most basic form
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
799
diff
changeset
|
372 private Socket wrapTLS(Socket sock, Target.Validated validated) throws IOException { |
801
88b3e8e89126
TLS seems to work
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
800
diff
changeset
|
373 if (validated.getTls()) |
88b3e8e89126
TLS seems to work
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
800
diff
changeset
|
374 return SecureSocket.wrap(validated, sock); |
803
1671f2eb130b
Send NUL bytes on non-TLS connect
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
801
diff
changeset
|
375 else { |
1671f2eb130b
Send NUL bytes on non-TLS connect
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
801
diff
changeset
|
376 // Send an even number of NUL bytes. |
1671f2eb130b
Send NUL bytes on non-TLS connect
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
801
diff
changeset
|
377 // We expect the server to speak MAPI and in that case, it's a NOP. |
1671f2eb130b
Send NUL bytes on non-TLS connect
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
801
diff
changeset
|
378 // If we're accidentally connecting to a TLS server, the bytes are |
1671f2eb130b
Send NUL bytes on non-TLS connect
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
801
diff
changeset
|
379 // invalid as a Client Hello message and most TLS implementations |
1671f2eb130b
Send NUL bytes on non-TLS connect
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
801
diff
changeset
|
380 // drop the connection. |
1671f2eb130b
Send NUL bytes on non-TLS connect
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
801
diff
changeset
|
381 // This is nice because otherwise we would hang, as the TLS server |
1671f2eb130b
Send NUL bytes on non-TLS connect
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
801
diff
changeset
|
382 // is waiting for us to send a TLS CLient Hello, and we are waiting |
1671f2eb130b
Send NUL bytes on non-TLS connect
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
801
diff
changeset
|
383 // for a MAPI server to send a server challenge. |
1671f2eb130b
Send NUL bytes on non-TLS connect
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
801
diff
changeset
|
384 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
|
385 } |
1671f2eb130b
Send NUL bytes on non-TLS connect
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
801
diff
changeset
|
386 return sock; |
801
88b3e8e89126
TLS seems to work
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
800
diff
changeset
|
387 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
388 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
389 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
|
390 String challenge = reader.getLine(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
391 reader.advance(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
392 if (reader.getLineType() != LineType.PROMPT) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
393 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
|
394 String response = challengeResponse(validated, challenge, callback); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
395 writer.writeLine(response); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
396 reader.advance(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
397 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
398 // Process the response lines. |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
399 String redirect = null; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
400 StringBuilder errors = new StringBuilder(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
401 while (reader.getLineType() != LineType.PROMPT) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
402 switch (reader.getLineType()) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
403 case REDIRECT: |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
404 if (redirect == null) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
405 redirect = reader.getLine(1); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
406 break; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
407 case ERROR: |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
408 if (errors.length() > 0) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
409 errors.append("\n"); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
410 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
|
411 break; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
412 case INFO: |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
413 warnings.add(reader.getLine(1)); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
414 break; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
415 default: |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
416 // ignore??!! |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
417 break; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
418 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
419 reader.advance(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
420 } |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
421 if (errors.length() > 0) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
422 throw new MCLException(errors.toString()); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
423 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
424 if (redirect == null) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
425 return true; // we're happy |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
426 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
427 // process redirect |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
428 try { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
429 MonetUrlParser.parse(target, redirect); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
430 } catch (URISyntaxException | ValidationError e) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
431 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
|
432 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
433 if (redirect.startsWith("mapi:merovingian://proxy")) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
434 // 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
|
435 // next challenge is already there. |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
436 reader.resetLineType(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
437 reader.advance(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
438 } else { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
439 close(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
440 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
441 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
442 return false; // we need another go |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
443 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
444 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
445 private String challengeResponse( |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
446 Target.Validated validated, final String challengeLine, |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
447 OptionsCallback callback |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
448 ) throws MCLException { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
449 // The challengeLine looks like this: |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
450 // |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
451 // 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
|
452 // 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
|
453 // 0 1 2 3 4 5 6 7 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
454 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
455 String parts[] = challengeLine.split(":"); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
456 if (parts.length < 3) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
457 throw new MCLException("Invalid challenge: expect at least 3 fields"); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
458 String challengePart = parts[0]; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
459 String serverTypePart = parts[1]; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
460 String versionPart = parts[2]; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
461 int version; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
462 if (versionPart.equals("9")) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
463 version = 9; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
464 else |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
465 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
|
466 if (parts.length < 6) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
467 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
|
468 String serverHashesPart = parts[3]; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
469 // String endianPart = parts[4]; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
470 String passwordHashPart = parts[5]; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
471 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
|
472 // 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
|
473 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
474 String userResponse; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
475 String password = target.getPassword(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
476 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
|
477 userResponse = "merovingian"; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
478 password = "merovingian"; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
479 } else { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
480 userResponse = target.getUser(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
481 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
482 String passwordResponse = hashPassword(challengePart, password, passwordHashPart, validated.getHash(), serverHashesPart); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
483 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
484 String optionsResponse = handleOptions(callback, optionsPart); |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
485 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
486 // Response looks like this: |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
487 // |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
488 // LIT:monetdb:{RIPEMD160}f2236256e5a9b20a5ecab4396e36c14f66c3e3c5:sql:demo |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
489 // :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
|
490 StringBuilder response = new StringBuilder(80); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
491 response.append("BIG:"); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
492 response.append(userResponse).append(":"); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
493 response.append(passwordResponse).append(":"); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
494 response.append(validated.getLanguage()).append(":"); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
495 response.append(validated.getDatabase()).append(":"); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
496 response.append("FILETRANS:"); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
497 response.append(optionsResponse).append(":"); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
498 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
499 return response.toString(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
500 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
501 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
502 // challengePart, passwordHashPart, supportedHashesPart, target.getPassword() |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
503 private String hashPassword(String challenge, String password, String passwordAlgo, String configuredHashes, String serverSupportedAlgos) throws MCLException { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
504 int maxHashLength = 512; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
505 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
506 StringBuilder output = new StringBuilder(10 + maxHashLength / 4); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
507 MessageDigest passwordDigest = pickBestAlgorithm(Collections.singleton(passwordAlgo), output); |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
508 |
835
071be9a628e8
Suppress warning about unchecked conversion
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
834
diff
changeset
|
509 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
|
510 if (!configuredHashes.isEmpty()) { |
835
071be9a628e8
Suppress warning about unchecked conversion
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
834
diff
changeset
|
511 Set<String> keep = new HashSet<>(Arrays.asList(configuredHashes.toUpperCase().split("[, ]"))); |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
512 algoSet.retainAll(keep); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
513 if (algoSet.isEmpty()) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
514 throw new MCLException("None of the hash algorithms <" + configuredHashes + "> are supported, server only supports <" + serverSupportedAlgos + ">"); |
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 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
517 MessageDigest challengeDigest = pickBestAlgorithm(algoSet, null); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
518 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
519 // First we use the password algo to hash the password. |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
520 // Then we use the challenge algo to hash the combination of the resulting hash digits and the challenge. |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
521 StringBuilder intermediate = new StringBuilder(maxHashLength / 4 + challenge.length()); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
522 hexhash(intermediate, passwordDigest, password); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
523 intermediate.append(challenge); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
524 hexhash(output, challengeDigest, intermediate.toString()); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
525 return output.toString(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
526 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
527 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
528 private MessageDigest pickBestAlgorithm(Set<String> algos, StringBuilder appendPrefixHere) throws MCLException { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
529 for (String[] choice: KNOWN_ALGORITHMS) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
530 String mapiName = choice[0]; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
531 String algoName = choice[1]; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
532 MessageDigest digest; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
533 if (!algos.contains(mapiName)) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
534 continue; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
535 try { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
536 digest = MessageDigest.getInstance(algoName); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
537 } catch (NoSuchAlgorithmException e) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
538 continue; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
539 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
540 // we found a match |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
541 if (appendPrefixHere != null) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
542 appendPrefixHere.append('{'); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
543 appendPrefixHere.append(mapiName); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
544 appendPrefixHere.append('}'); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
545 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
546 return digest; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
547 } |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
548 String algoNames = String.join(",", algos); |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
549 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
|
550 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
551 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
552 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
|
553 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
|
554 digest.update(bytes); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
555 byte[] output = digest.digest(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
556 for (byte b: output) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
557 int hi = (b & 0xF0) >> 4; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
558 int lo = b & 0x0F; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
559 buffer.append(HEXDIGITS[hi]); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
560 buffer.append(HEXDIGITS[lo]); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
561 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
562 } |
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
|
563 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
564 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
|
565 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
|
566 return ""; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
567 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
568 StringBuilder buffer = new StringBuilder(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
569 callback.setBuffer(buffer); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
570 for (String optlevel: optionsPart.split(",")) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
571 int eqindex = optlevel.indexOf('='); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
572 if (eqindex < 0) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
573 throw new MCLException("Invalid options part in server challenge: " + optionsPart); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
574 String lang = optlevel.substring(0, eqindex); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
575 int level; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
576 try { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
577 level = Integer.parseInt(optlevel.substring(eqindex + 1)); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
578 } catch (NumberFormatException e) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
579 throw new MCLException("Invalid option level in server challenge: " + optlevel); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
580 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
581 callback.addOptions(lang, level); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
582 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
583 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
584 return buffer.toString(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
585 } |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
586 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
587 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
588 * 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
|
589 * the MapiSocket. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
590 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
591 * @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
|
592 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
593 public InputStream getInputStream() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
594 return fromMonet; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
595 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
596 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
597 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
598 * Returns an output stream for this MapiSocket. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
599 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
600 * @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
|
601 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
602 public OutputStream getOutputStream() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
603 return toMonet; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
604 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
605 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
606 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
607 * 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
|
608 * BufferedMCLReader which does protocol interpretation of the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
609 * BlockInputStream produced by this MapiSocket. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
610 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
611 * @return a BufferedMCLReader connected to this MapiSocket |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
612 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
613 public BufferedMCLReader getReader() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
614 return reader; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
615 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
616 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
617 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
618 * 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
|
619 * BufferedMCLWriter which produces protocol compatible data blocks |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
620 * that the BlockOutputStream can properly translate into blocks. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
621 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
622 * @return a BufferedMCLWriter connected to this MapiSocket |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
623 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
624 public BufferedMCLWriter getWriter() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
625 return writer; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
626 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
627 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
628 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
629 * 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
|
630 * 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
|
631 * MapiSocket should check this version to act appropriately. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
632 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
633 * @return the mapi protocol version |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
634 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
635 public int getProtocolVersion() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
636 return version; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
637 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
638 |
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 * 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
|
641 * 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
|
642 * encouraged to start debugging before actually connecting the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
643 * socket. |
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 * @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
|
646 * @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
|
647 */ |
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
|
648 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
|
649 debug(new FileWriter(filename)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
650 } |
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
|
651 |
0
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 * 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
|
654 * 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
|
655 * encouraged to start debugging before actually connecting the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
656 * socket. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
657 * |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
658 * @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
|
659 * @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
|
660 */ |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
661 // 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
|
662 // 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
|
663 // 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
|
664 // } |
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
|
665 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
666 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
667 * 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
|
668 * 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
|
669 * encouraged to start debugging before actually connecting the |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
670 * socket. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
671 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
672 * @param out to write the log to |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
673 */ |
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
|
674 public void debug(final Writer out) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
675 log = out; |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
676 setDebug(true); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
677 } |
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 /** |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
680 * 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
|
681 * |
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
682 * @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
|
683 */ |
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
684 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
|
685 return log; |
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
686 } |
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
687 |
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
688 /** |
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
|
689 * 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
|
690 * 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
|
691 * |
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
|
692 * 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
|
693 * 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
|
694 * 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
|
695 * |
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
|
696 * @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
|
697 * @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
|
698 * @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
|
699 * @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
|
700 */ |
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
|
701 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
|
702 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
|
703 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
|
704 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
|
705 } |
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
|
706 |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
707 /** |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
708 * For internal use |
626
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
616
diff
changeset
|
709 * |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
616
diff
changeset
|
710 * @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
|
711 * @return previous setting |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
712 */ |
511
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
713 public boolean setInsertFakePrompts(boolean b) { |
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
714 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
|
715 } |
eaad79c3235f
Make the fake prompts at block ends optional
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
498
diff
changeset
|
716 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
717 public boolean isDebug() { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
718 return target.isDebug(); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
719 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
720 |
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
|
721 /** |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
722 * 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
|
723 * 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
|
724 * "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
|
725 * 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
|
726 * 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
|
727 * 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
|
728 * being written to the stream. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
729 */ |
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
|
730 final class BlockOutputStream extends FilterOutputStream { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
731 private int writePos = 0; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
732 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
|
733 private final byte[] block = new byte[BLOCK]; |
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 * Constructs this BlockOutputStream, backed by the given |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
737 * 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
|
738 * @param out an OutputStream |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
739 */ |
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
|
740 public BlockOutputStream(final OutputStream out) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
741 // 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
|
742 // 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
|
743 // some reason |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
744 super(new BufferedOutputStream(out)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
745 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
746 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
747 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
748 public void flush() throws IOException { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
749 // write the block (as final) then flush. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
750 writeBlock(true); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
751 out.flush(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
752 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
753 // 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
|
754 // 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
|
755 // 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
|
756 // 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
|
757 // 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
|
758 // 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
|
759 if (isDebug()) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
760 log.flush(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
761 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
762 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
763 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
764 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
765 * 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
|
766 * 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
|
767 * 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
|
768 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
769 * @param last whether this is the last block |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
770 * @throws IOException if writing to the stream failed |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
771 */ |
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
|
772 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
|
773 if (last) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
774 // always fits, because of BLOCK's size |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
775 blocksize = (short)writePos; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
776 // this is the last block, so encode least |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
777 // significant bit in the first byte (little-endian) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
778 blklen[0] = (byte)(blocksize << 1 & 0xFF | 1); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
779 blklen[1] = (byte)(blocksize >> 7); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
780 } else { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
781 // always fits, because of BLOCK's size |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
782 blocksize = (short)BLOCK; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
783 // another block will follow, encode least |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
784 // significant bit in the first byte (little-endian) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
785 blklen[0] = (byte)(blocksize << 1 & 0xFF); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
786 blklen[1] = (byte)(blocksize >> 7); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
787 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
788 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
789 out.write(blklen); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
790 // write the actual block |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
791 out.write(block, 0, writePos); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
792 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
793 if (isDebug()) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
794 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
|
795 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
|
796 } 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
|
797 log("TD ", "write block: " + writePos + " bytes", false); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
798 } |
555
90c346571eb4
Use StandardCharsets.UTF_8 where possible
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
554
diff
changeset
|
799 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
|
800 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
801 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
802 writePos = 0; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
803 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
804 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
805 @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
|
806 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
|
807 if (writePos == BLOCK) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
808 writeBlock(false); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
809 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
810 block[writePos++] = (byte)b; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
811 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
812 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
813 @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
|
814 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
|
815 write(b, 0, b.length); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
816 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
817 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
818 @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
|
819 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
|
820 while (len > 0) { |
556
87feb93330a6
Misc. changes suggested by analysis tool
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
555
diff
changeset
|
821 int t = BLOCK - writePos; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
822 if (len > t) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
823 System.arraycopy(b, off, block, writePos, t); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
824 off += t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
825 len -= t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
826 writePos += t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
827 writeBlock(false); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
828 } else { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
829 System.arraycopy(b, off, block, writePos, len); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
830 writePos += len; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
831 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
832 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
833 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
834 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
835 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
836 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
837 public void close() throws IOException { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
838 // 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
|
839 // the FilterOutputStream), so we close manually here |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
840 out.close(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
841 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
842 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
843 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
844 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
845 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
846 * 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
|
847 * available as a normal stream. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
848 */ |
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
|
849 final class BlockInputStream extends FilterInputStream { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
850 private int readPos = 0; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
851 private int blockLen = 0; |
508
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
852 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
|
853 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
|
854 private boolean insertFakePrompts = true; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
855 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
856 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
857 * Constructs this BlockInputStream, backed by the given |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
858 * 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
|
859 * @param in an InputStream |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
860 */ |
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
|
861 public BlockInputStream(final InputStream in) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
862 // 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
|
863 // 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
|
864 // some reason |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
865 super(new BufferedInputStream(in)); |
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 |
511
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
868 public boolean setInsertFakePrompts(boolean doFake) { |
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
869 boolean old = insertFakePrompts; |
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
870 insertFakePrompts = doFake; |
501
eaad79c3235f
Make the fake prompts at block ends optional
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
498
diff
changeset
|
871 return old; |
eaad79c3235f
Make the fake prompts at block ends optional
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
498
diff
changeset
|
872 } |
eaad79c3235f
Make the fake prompts at block ends optional
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
498
diff
changeset
|
873 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
874 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
875 public int available() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
876 return blockLen - readPos; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
877 } |
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 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
880 public boolean markSupported() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
881 return false; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
882 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
883 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
884 @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
|
885 public void mark(final int readlimit) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
886 throw new AssertionError("Not implemented!"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
887 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
888 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
889 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
890 public void reset() { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
891 throw new AssertionError("Not implemented!"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
892 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
893 |
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 * 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
|
896 * 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
|
897 * 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
|
898 * 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
|
899 * data will greatly complicate matters, while a performance |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
900 * 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
|
901 * 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
|
902 * consider this method a quick bug fix/workaround. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
903 * |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
904 * @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
|
905 * @param len number of bytes to read |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
906 * @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
|
907 * @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
|
908 */ |
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
|
909 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
|
910 int s; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
911 int off = 0; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
912 while (len > 0) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
913 s = in.read(b, off, len); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
914 if (s == -1) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
915 // 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
|
916 // 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
|
917 if (off > 0) { |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
918 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
|
919 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
|
920 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
|
921 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
922 throw new IOException("Read from " + |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
923 con.getInetAddress().getHostName() + ":" + |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
924 con.getPort() + ": Incomplete block read from stream"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
925 } |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
926 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
|
927 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
|
928 return false; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
929 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
930 len -= s; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
931 off += s; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
932 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
933 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
934 return true; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
935 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
936 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
937 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
938 * 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
|
939 * or writes the prompt in the buffer. |
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 * 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
|
942 * 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
|
943 * 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
|
944 * 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
|
945 * 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
|
946 * 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
|
947 * 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
|
948 * read methods. |
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 * 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
|
951 * 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
|
952 * 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
|
953 * 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
|
954 * 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
|
955 * Reader that is possibly chained to this InputStream. |
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 * 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
|
958 * loose. |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
959 * |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
960 * @return blockLen |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
961 * @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
|
962 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
963 private int readBlock() throws IOException { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
964 // read next two bytes (short) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
965 if (!_read(blklen, 2)) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
966 return(-1); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
967 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
968 // 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
|
969 blockLen = (short)( |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
970 (blklen[0] & 0xFF) >> 1 | |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
971 (blklen[1] & 0xFF) << 7 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
972 ); |
508
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
973 wasEndBlock = (blklen[0] & 0x1) == 1; |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
974 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
975 readPos = 0; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
976 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
977 if (isDebug()) { |
508
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
978 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
|
979 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
|
980 } 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
|
981 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
|
982 } |
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 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
985 // 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
|
986 // stack trace |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
987 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
|
988 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
|
989 blockLen + " > " + block.length); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
990 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
|
991 return -1; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
992 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
993 if (isDebug()) |
555
90c346571eb4
Use StandardCharsets.UTF_8 where possible
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
554
diff
changeset
|
994 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
|
995 |
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
|
996 // 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
|
997 if (wasEndBlock) { |
537
242debd7e866
Fix mistake in comment
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
535
diff
changeset
|
998 // insert 'fake' newline and prompt |
511
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
999 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
|
1000 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
|
1001 // 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
|
1002 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
|
1003 } |
501
eaad79c3235f
Make the fake prompts at block ends optional
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
498
diff
changeset
|
1004 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
|
1005 block[blockLen++] = b; |
eaad79c3235f
Make the fake prompts at block ends optional
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
498
diff
changeset
|
1006 } |
eaad79c3235f
Make the fake prompts at block ends optional
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
498
diff
changeset
|
1007 block[blockLen++] = '\n'; |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1008 if (isDebug()) { |
511
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
1009 log("RD ", "inserting prompt", true); |
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
1010 } |
498
4cfe4991ee63
Use the prompt characters from mapi_prompt.h
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
497
diff
changeset
|
1011 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1012 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1013 |
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
|
1014 return blockLen; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1015 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1016 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1017 @Override |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1018 public int read() throws IOException { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1019 if (available() == 0) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1020 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
|
1021 return -1; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1022 } |
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
|
1023 |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1024 if (isDebug()) |
555
90c346571eb4
Use StandardCharsets.UTF_8 where possible
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
554
diff
changeset
|
1025 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
|
1026 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1027 return (int)block[readPos++]; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1028 } |
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 @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
|
1031 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
|
1032 return read(b, 0, b.length); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1033 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1034 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1035 @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
|
1036 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
|
1037 int t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1038 int size = 0; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1039 while (size < len) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1040 t = available(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1041 if (t == 0) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1042 if (size != 0) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1043 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1044 if (readBlock() == -1) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1045 if (size == 0) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1046 size = -1; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1047 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1048 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1049 t = available(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1050 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1051 if (len > t) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1052 System.arraycopy(block, readPos, b, off, t); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1053 off += t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1054 len -= t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1055 readPos += t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1056 size += t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1057 } else { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1058 System.arraycopy(block, readPos, b, off, len); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1059 readPos += len; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1060 size += len; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1061 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1062 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1063 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1064 return size; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1065 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1066 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1067 @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
|
1068 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
|
1069 long skip = n; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1070 while (skip > 0) { |
556
87feb93330a6
Misc. changes suggested by analysis tool
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
555
diff
changeset
|
1071 int t = available(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1072 if (skip > t) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1073 skip -= t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1074 readPos += t; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1075 readBlock(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1076 } 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
|
1077 readPos += (int)skip; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1078 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1079 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1080 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1081 return n; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1082 } |
508
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1083 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1084 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1085 * 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
|
1086 * @return new Raw object |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1087 */ |
508
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1088 Raw getRaw() { |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1089 return new Raw(); |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1090 } |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1091 |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1092 /** 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
|
1093 final class Raw { |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1094 byte[] getBytes() { |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1095 return block; |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1096 } |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1097 |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1098 int getLength() { |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1099 return blockLen; |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1100 } |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1101 |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1102 int getPosition() { |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1103 return readPos; |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1104 } |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1105 |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1106 int consume(int delta) { |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1107 int pos = readPos; |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1108 readPos += delta; |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1109 return pos; |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1110 } |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1111 |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1112 int readBlock() throws IOException { |
511
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
1113 boolean wasFaking = setInsertFakePrompts(false); |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1114 try { |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1115 return BlockInputStream.this.readBlock(); |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1116 } finally { |
511
bd860e850fe1
rename insertFakeFlushes to insertFakePrompts
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
509
diff
changeset
|
1117 setInsertFakePrompts(wasFaking); |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1118 } |
508
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1119 } |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1120 |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1121 boolean wasEndBlock() { |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1122 return wasEndBlock; |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1123 } |
7730d65dfd55
Add MapiSocket.BlockInputStream.Raw
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
507
diff
changeset
|
1124 } |
0
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 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1127 /** |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
1128 * 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
|
1129 * 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
|
1130 * resources as possible are closed. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1131 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1132 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
|
1133 if (writer != null) { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1134 try { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1135 writer.close(); |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1136 writer = null; |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1137 } 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
|
1138 } |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1139 if (reader != null) { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1140 try { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1141 reader.close(); |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1142 reader = null; |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1143 } 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
|
1144 } |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1145 if (toMonet != null) { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1146 try { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1147 toMonet.close(); |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1148 toMonet = null; |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1149 } 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
|
1150 } |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1151 if (fromMonet != null) { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1152 try { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1153 fromMonet.close(); |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1154 fromMonet = null; |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1155 } 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
|
1156 } |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1157 if (con != null) { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1158 try { |
281
b58c1b245ede
Correct and improve implementation of getChallengeResponse() for protocol 9
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
276
diff
changeset
|
1159 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
|
1160 con = null; |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1161 } 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
|
1162 } |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1163 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
|
1164 try { |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1165 log.close(); |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1166 log = null; |
6cc63d6cb224
Implemented fix as suggested in Bug 3973
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
1167 } catch (IOException e) { /* ignore it */ } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1168 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1169 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1170 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1171 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1172 * 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
|
1173 * |
552
7b320303b579
Doc comment improvements
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
547
diff
changeset
|
1174 * 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
|
1175 * |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1176 * @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
|
1177 * @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
|
1178 */ |
521
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1179 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
|
1180 return new UploadStream(chunkSize); |
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1181 } |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1182 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1183 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1184 * 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
|
1185 * |
552
7b320303b579
Doc comment improvements
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
547
diff
changeset
|
1186 * 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
|
1187 * |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
616
diff
changeset
|
1188 * @return UploadStream new upload stream |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1189 */ |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1190 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
|
1191 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
|
1192 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1193 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1194 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1195 * 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
|
1196 * |
552
7b320303b579
Doc comment improvements
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
547
diff
changeset
|
1197 * 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
|
1198 * |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1199 * @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
|
1200 * @return DownloadStream new download stream |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1201 */ |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1202 public DownloadStream downloadStream(boolean prependCr) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1203 return new DownloadStream(fromMonet.getRaw(), toMonet, prependCr); |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1204 } |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1205 |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1206 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1207 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1208 * 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
|
1209 * |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1210 * 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
|
1211 * |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1212 * 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
|
1213 * the opportunity to abort the upload. |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1214 */ |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1215 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
|
1216 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
|
1217 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
|
1218 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
|
1219 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
|
1220 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
|
1221 private byte[] promptBuffer; |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1222 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
|
1223 |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
1224 /** |
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
700
diff
changeset
|
1225 * 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
|
1226 * @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
|
1227 */ |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1228 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
|
1229 super(toMonet); |
521
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1230 if (chunkSize <= 0) { |
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1231 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
|
1232 } |
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1233 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
|
1234 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
|
1235 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
|
1236 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
|
1237 chunkLeft = this.chunkSize; |
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1238 } |
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1239 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1240 /** 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
|
1241 UploadStream() { |
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1242 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
|
1243 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1244 |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1245 /** 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
|
1246 * |
06d69b82d409
Resolve javadoc error and warnings :
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
616
diff
changeset
|
1247 * @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
|
1248 */ |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1249 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
|
1250 this.cancellationCallback = cancellationCallback; |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1251 } |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1252 |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1253 @Override |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1254 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
|
1255 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
|
1256 // 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
|
1257 // 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
|
1258 // 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
|
1259 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
|
1260 } |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1261 handleChunking(); |
612
1d44b8a577ca
write to out, not to super when implementing FilterOutputStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
610
diff
changeset
|
1262 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
|
1263 wrote(1); |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1264 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1265 |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1266 @Override |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1267 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
|
1268 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
|
1269 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1270 |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1271 @Override |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1272 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
|
1273 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
|
1274 // 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
|
1275 // 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
|
1276 // 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
|
1277 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
|
1278 } |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1279 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
|
1280 handleChunking(); |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1281 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
|
1282 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
|
1283 off += toWrite; |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1284 len -= toWrite; |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1285 wrote(toWrite); |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1286 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1287 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1288 |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1289 @Override |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1290 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
|
1291 // suppress flushes |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1292 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1293 |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1294 @Override |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1295 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
|
1296 if (closed) { |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1297 return; |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1298 } |
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
|
1299 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
|
1300 |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1301 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
|
1302 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
|
1303 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
|
1304 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
|
1305 } |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1306 |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1307 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
|
1308 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
|
1309 // 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
|
1310 flushAndReadPrompt(); |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1311 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1312 // 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
|
1313 out.flush(); |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1314 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
|
1315 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
|
1316 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
|
1317 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1318 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1319 |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1320 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
|
1321 // 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
|
1322 } |
b75464874130
Keep better track of whether the server has cancelled the upload
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
521
diff
changeset
|
1323 |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1324 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
|
1325 chunkLeft -= i; |
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 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
|
1329 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
|
1330 return; |
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 flushAndReadPrompt(); |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1333 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1334 |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1335 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
|
1336 out.flush(); |
521
72007c4f8f8a
Allow MonetUploadHandler to configure the chunk size
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
512
diff
changeset
|
1337 chunkLeft = chunkSize; |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1338 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
|
1339 switch (lineType) { |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1340 case MORE: |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1341 return; |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1342 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
|
1343 // 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
|
1344 // 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
|
1345 serverCancelled = true; |
557
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1346 if (cancellationCallback != null) { |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1347 cancellationCallback.run(); |
ce2b616ed22e
Add a cancellation callback to UploadHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
556
diff
changeset
|
1348 } |
502
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1349 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
|
1350 default: |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1351 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
|
1352 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1353 } |
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 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
|
1356 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
|
1357 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
|
1358 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
|
1359 } |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1360 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
|
1361 } |
83354bd21320
Upload fake data when an upload request is received
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
501
diff
changeset
|
1362 } |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1363 |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1364 |
535
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1365 /** |
c9d88af06d35
Javadoc and some minor changes
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
533
diff
changeset
|
1366 * 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
|
1367 * |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1368 * 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
|
1369 */ |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1370 public static class DownloadStream extends InputStream { |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1371 private final BlockInputStream.Raw rawIn; |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1372 private final OutputStream out; |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1373 private final boolean prependCr; |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1374 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
|
1375 private boolean closed = false; |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1376 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
|
1377 |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1378 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
|
1379 this.rawIn = rawIn; |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1380 this.out = out; |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1381 this.prependCr = prependCr; |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1382 } |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1383 |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1384 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
|
1385 if (endBlockSeen || closed) |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1386 return; |
576
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1387 final int ret = rawIn.readBlock(); |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1388 if (ret < 0 || rawIn.wasEndBlock()) { |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1389 endBlockSeen = true; |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1390 } |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1391 } |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1392 |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1393 @Override |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1394 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
|
1395 if (closed) |
8029d7368b5a
Make sure the download stream isn't closed twice
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
541
diff
changeset
|
1396 return; |
8029d7368b5a
Make sure the download stream isn't closed twice
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
541
diff
changeset
|
1397 closed = true; |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1398 while (!endBlockSeen) { |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1399 nextBlock(); |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1400 } |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1401 // Send acknowledgement to server |
512
a4000e374a43
Fix silly mistake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
511
diff
changeset
|
1402 out.write('\n'); |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1403 out.flush(); |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1404 // Do whatever super has to do |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1405 super.close(); |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1406 } |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1407 |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1408 @Override |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1409 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
|
1410 final byte[] buf = { 0 }; |
095e896f9d7a
Updated comments. Improved code. Added final keywords
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
573
diff
changeset
|
1411 final int nread = read(buf, 0, 1); |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1412 if (nread == 1) |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1413 return buf[0]; |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1414 else |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1415 return -1; |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1416 } |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1417 |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1418 @Override |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1419 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
|
1420 final int origOff = off; |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1421 int end = off + len; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1422 |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1423 while (off < end) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1424 // 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
|
1425 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
|
1426 assert chunk >= 0; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1427 if (chunk == 0) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1428 // make progress by fetching more data |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1429 if (endBlockSeen) |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1430 break; |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1431 nextBlock(); |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1432 continue; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1433 } |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1434 // make progress copying some bytes |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1435 if (!prependCr) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1436 // no conversion needed, use arraycopy |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1437 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
|
1438 off += chunk; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1439 rawIn.consume(chunk); |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1440 } else { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1441 int chunkEnd = off + chunk; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1442 if (newlinePending && off < chunkEnd) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1443 // 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
|
1444 dest[off++] = '\n'; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1445 newlinePending = false; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1446 } |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1447 while (off < chunkEnd) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1448 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
|
1449 if (b != '\n') { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1450 dest[off++] = b; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1451 } else if (chunkEnd - off >= 2) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1452 dest[off++] = '\r'; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1453 dest[off++] = '\n'; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1454 } else { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1455 dest[off++] = '\r'; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1456 newlinePending = true; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1457 break; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1458 } |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1459 } |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1460 } |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1461 } |
616
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1462 |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1463 if (off < end && newlinePending) { |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1464 dest[off++] = '\n'; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1465 newlinePending = false; |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1466 } |
65641a7cea31
Implement line ending conversion for downloads
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
612
diff
changeset
|
1467 |
509
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1468 if (off == origOff && endBlockSeen) |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1469 return -1; |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1470 else |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1471 return off - origOff; |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1472 } |
455497783026
Add MapiSocket.DownloadStream
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
508
diff
changeset
|
1473 } |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1474 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1475 /** |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1476 * Callback used during the initial MAPI handshake. |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1477 * |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1478 * 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
|
1479 * The options are language-specific and each has a 'level'. The server |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1480 * advertises up to which level options are supported for a given language |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1481 * and for each language/option combination, {@link addOptions} will be invoked. |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1482 * It should call {@link contribute} for each option it wants to set. |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1483 * |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1484 * 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
|
1485 * 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
|
1486 */ |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1487 public static abstract class OptionsCallback { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1488 private StringBuilder buffer; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1489 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1490 /** |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1491 * Callback called for each language/level combination supported by the |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1492 * server. May call {@link contribute} for options with a level STRICTLY |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1493 * LOWER than the level passed as a parameter. |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1494 * @param lang language advertised by the server |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1495 * @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
|
1496 */ |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1497 public abstract void addOptions(String lang, int level); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1498 |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1499 /** |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1500 * Pass option=value during the handshake |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1501 * @param field |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1502 * @param value |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
811
diff
changeset
|
1503 */ |
793
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1504 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
|
1505 if (buffer.length() > 0) |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1506 buffer.append(','); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1507 buffer.append(field); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1508 buffer.append('='); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1509 buffer.append(value); |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1510 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1511 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1512 |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1513 void setBuffer(StringBuilder buf) { |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1514 buffer = buf; |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1515 } |
5bfe3357fb1c
Use the new url parser
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
768
diff
changeset
|
1516 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1517 } |