comparison src/main/java/org/monetdb/jdbc/MonetConnection.java @ 521:72007c4f8f8a onclient

Allow MonetUploadHandler to configure the chunk size (every chunk_size bytes, the client suspends the upload and asks the server whether to continue)
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Thu, 26 Aug 2021 11:50:11 +0200 (2021-08-26)
parents 704a11b93e6b
children 6060ca8c5c1a
comparison
equal deleted inserted replaced
520:b4c7816e3592 521:72007c4f8f8a
3265 3265
3266 public static class Upload { 3266 public static class Upload {
3267 private final MapiSocket server; 3267 private final MapiSocket server;
3268 private PrintStream print = null; 3268 private PrintStream print = null;
3269 private String error = null; 3269 private String error = null;
3270 private int customChunkSize = -1;
3270 3271
3271 Upload(MapiSocket server) { 3272 Upload(MapiSocket server) {
3272 this.server = server; 3273 this.server = server;
3273 } 3274 }
3274 3275
3277 throw new IOException("another error has already been sent: " + error); 3278 throw new IOException("another error has already been sent: " + error);
3278 } 3279 }
3279 error = errorMessage; 3280 error = errorMessage;
3280 } 3281 }
3281 3282
3283 public void setChunkSize(int chunkSize) {
3284 this.customChunkSize = chunkSize;
3285 }
3286
3282 public PrintStream getStream() throws IOException { 3287 public PrintStream getStream() throws IOException {
3283 if (error != null) { 3288 if (error != null) {
3284 throw new IOException("Cannot send data after an error has been sent"); 3289 throw new IOException("Cannot send data after an error has been sent");
3285 } 3290 }
3286 if (print == null) { 3291 if (print == null) {
3287 try { 3292 try {
3288 MapiSocket.UploadStream up = server.uploadStream(); 3293 MapiSocket.UploadStream up = customChunkSize >= 0 ? server.uploadStream(customChunkSize) : server.uploadStream();
3289 print = new PrintStream(up, false, "UTF-8"); 3294 print = new PrintStream(up, false, "UTF-8");
3290 up.write('\n'); 3295 up.write('\n');
3291 } catch (UnsupportedEncodingException e) { 3296 } catch (UnsupportedEncodingException e) {
3292 throw new RuntimeException("The system is guaranteed to support the UTF-8 encoding but apparently it doesn't", e); 3297 throw new RuntimeException("The system is guaranteed to support the UTF-8 encoding but apparently it doesn't", e);
3293 } 3298 }