diff src/main/java/org/monetdb/jdbc/MonetConnection.java @ 579:72f4437de9be onclient

Reencode downloads if necessary
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Thu, 14 Oct 2021 16:11:52 +0200 (2021-10-14)
parents 095e896f9d7a
children 6aa38e8c0f2d
line wrap: on
line diff
--- a/src/main/java/org/monetdb/jdbc/MonetConnection.java
+++ b/src/main/java/org/monetdb/jdbc/MonetConnection.java
@@ -3524,6 +3524,22 @@ public class MonetConnection
 		}
 
 		/**
+		 * Write the textual data from the server to the given {@link Writer}
+		 * @param writer
+		 */
+		public void downloadTo(final Writer writer) throws IOException {
+			final InputStream s = getStream();
+			final InputStreamReader r = new InputStreamReader(s, StandardCharsets.UTF_8);
+			final char[] buffer = new char[65536];
+			while (true) {
+				final int nread = r.read(buffer);
+				if (nread < 0)
+					break;
+				writer.write(buffer, 0, nread);
+			}
+		}
+
+		/**
 		 * @return  true if data has been received or an error has been sent.
 		 */
 		public boolean hasBeenUsed() {