Skip to content

Commit 4a6b403

Browse files
authored
noop(cleanup) dedup w/factored-out (#1392) counter (#1393)
this utilizes the newly factored out streaming counter, so _should_ be noop.
1 parent 4cf9c5f commit 4a6b403

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

portability-transfer/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ configurations {
3636

3737
dependencies {
3838
compile project(':portability-api-launcher')
39+
compile project(':portability-spi-api')
3940
compile project(':portability-spi-service')
4041
compile project(':portability-spi-cloud')
4142
compile project(':portability-spi-transfer')
Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.datatransferproject.transfer;
22

3-
import java.io.IOException;
4-
import java.io.InputStream;
3+
import static org.datatransferproject.spi.api.transport.DiscardingStreamCounter.discardForLength;
4+
55
import java.util.Collection;
66
import java.util.LinkedHashMap;
77
import java.util.Map;
@@ -19,7 +19,9 @@ public class CallableSizeCalculator implements Callable<Map<String, Long>> {
1919
private final Collection<? extends DownloadableItem> items;
2020

2121
public CallableSizeCalculator(
22-
UUID jobId, ConnectionProvider connectionProvider, Collection<? extends DownloadableItem> items) {
22+
UUID jobId,
23+
ConnectionProvider connectionProvider,
24+
Collection<? extends DownloadableItem> items) {
2325
this.jobId = Objects.requireNonNull(jobId);
2426
this.connectionProvider = Objects.requireNonNull(connectionProvider);
2527
this.items = Objects.requireNonNull(items);
@@ -32,26 +34,12 @@ public Map<String, Long> call() throws Exception {
3234
InputStreamWrapper stream = connectionProvider.getInputStreamForItem(jobId, item);
3335
long size = stream.getBytes();
3436
if (size <= 0) {
35-
size = computeSize(stream);
37+
size = discardForLength(stream.getStream());
3638
}
3739

3840
result.put(item.getIdempotentId(), size);
3941
}
4042

4143
return result;
4244
}
43-
44-
// Reads the input stream in full
45-
private Long computeSize(InputStreamWrapper stream) throws IOException {
46-
long size = 0;
47-
try (InputStream inStream = stream.getStream()) {
48-
byte[] buffer = new byte[1024 * 1024]; // 1MB
49-
int chunkBytesRead;
50-
while ((chunkBytesRead = inStream.read(buffer)) != -1) {
51-
size += chunkBytesRead;
52-
}
53-
}
54-
55-
return size;
56-
}
5745
}

0 commit comments

Comments
 (0)