diff example/OnClientExample.java @ 551:5ce6a942aff3 onclient

Last minute API fix: 'int offset' -> 'long linesToSkip' Int -> long because there might be many lines Offset -> linesToSkip to save users some work. The COPY INTO statement has an OFFSET modifier which is 1-based but also allows 0. This means both 0 and 1 mean 'upload the whole file' and any N > 1 means skip N-1 lines and upload the rest. To avoid having to deal with this over and over in every implementation of MonetConnection.UploadHandler#handleUpload(), parameter 'offset' has been replaced with 'linesToSkip' where the adjustment has already been performed.
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Tue, 14 Sep 2021 10:52:04 +0200 (2021-09-14)
parents d462000fc410
children 87feb93330a6
line wrap: on
line diff
--- a/example/OnClientExample.java
+++ b/example/OnClientExample.java
@@ -96,15 +96,14 @@ public class OnClientExample {
 		}
 
 		@Override
-		public void handleUpload(MonetConnection.Upload handle, String name, boolean textMode, int offset) throws IOException {
+		public void handleUpload(MonetConnection.Upload handle, String name, boolean textMode, long linesToSkip) throws IOException {
 
 			// COPY OFFSET line numbers are 1-based but 0 is also allowed.
 			// Compute the number of lines to skip
-			long toSkip = offset <= 1 ? 0 : offset - 1;
 
 			// We can upload data read from the file system but also make up our own data
 			if (name.equals("generated.csv")) {
-				uploadGenerated(handle, toSkip);
+				uploadGenerated(handle, linesToSkip);
 				return;
 			}
 
@@ -124,12 +123,12 @@ public class OnClientExample {
 			boolean binary = !textMode;
 			if (binary) {
 				uploadBinary(handle, path);
-			} else if (toSkip == 0 && filesAreUtf8) {
+			} else if (linesToSkip == 0 && filesAreUtf8) {
 				// Avoid unnecessary character set conversions by pretending it's binary
 				uploadBinary(handle, path);
 			} else {
 				// Charset and skip handling really necessary
-				uploadTextFile(handle, path, toSkip);
+				uploadTextFile(handle, path, linesToSkip);
 			}
 		}