Add option to upload InputStream to KeepWebApi
[arvados.git] / sdk / java-v2 / src / main / java / org / arvados / client / api / client / CountingFileRequestBody.java
index 43fcdba5c69a20a1817aa77400ca6cae95b0513d..d6eb033ff5cd2717369aa5d034f01a140889d72a 100644 (file)
@@ -7,12 +7,9 @@
 
 package org.arvados.client.api.client;
 
-import okhttp3.MediaType;
-import okhttp3.RequestBody;
 import okio.BufferedSink;
 import okio.Okio;
 import okio.Source;
-import org.slf4j.Logger;
 
 import java.io.File;
 
@@ -20,32 +17,20 @@ import java.io.File;
  * Based on:
  * {@link} https://gist.github.com/eduardb/dd2dc530afd37108e1ac
  */
-public class CountingFileRequestBody extends RequestBody {
-
-    private static final int SEGMENT_SIZE = 2048; // okio.Segment.SIZE
-    private static final MediaType CONTENT_BINARY = MediaType.parse(com.google.common.net.MediaType.OCTET_STREAM.toString());
-
-    private final File file;
-    private final ProgressListener listener;
+public class CountingFileRequestBody extends CountingRequestBody<File> {
 
     CountingFileRequestBody(final File file, final ProgressListener listener) {
-        this.file = file;
-        this.listener = listener;
+        super(file, listener);
     }
 
     @Override
     public long contentLength() {
-        return file.length();
-    }
-
-    @Override
-    public MediaType contentType() {
-        return CONTENT_BINARY;
+        return requestBodyData.length();
     }
 
     @Override
     public void writeTo(BufferedSink sink) {
-        try (Source source = Okio.source(file)) {
+        try (Source source = Okio.source(requestBodyData)) {
             long total = 0;
             long read;
 
@@ -61,24 +46,4 @@ public class CountingFileRequestBody extends RequestBody {
             //ignore
         }
     }
-
-    static class TransferData {
-
-        private final Logger log = org.slf4j.LoggerFactory.getLogger(TransferData.class);
-        private int progressValue;
-        private long totalSize;
-
-        TransferData(long totalSize) {
-            this.progressValue = 0;
-            this.totalSize = totalSize;
-        }
-
-        void updateTransferProgress(long transferred) {
-            float progress = (transferred / (float) totalSize) * 100;
-            if (progressValue != (int) progress) {
-                progressValue = (int) progress;
-                log.debug("{} / {} / {}%", transferred, totalSize, progressValue);
-            }
-        }
-    }
 }
\ No newline at end of file