Skip to content

Commit f39925f

Browse files
jean-philippe-martinmziccard
authored andcommitted
---
yaml --- r: 7405 b: refs/heads/tswast-patch-1 c: f2aa350 h: refs/heads/master i: 7403: 92bb904
1 parent 1c5d21d commit f39925f

3 files changed

Lines changed: 22 additions & 21 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: a176250251608b6e56bf7e2ee7b5e10c7eec3f0a
60+
refs/heads/tswast-patch-1: f2aa350398a73ce118533db5419127a37b3a3797
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-examples/src/main/java/com/google/cloud/examples/nio/CountBytes.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,26 @@ private static void countFile(String fname) {
7171
ByteBuffer buf = ByteBuffer.allocate(bufSize);
7272
System.out.println("Reading the whole file...");
7373
Stopwatch sw = Stopwatch.createStarted();
74-
SeekableByteChannel chan = Files.newByteChannel(path);
75-
long total = 0;
76-
int readCalls = 0;
77-
MessageDigest md = MessageDigest.getInstance("MD5");
78-
while (chan.read(buf) > 0) {
79-
readCalls++;
80-
md.update(buf.array(), 0, buf.position());
81-
total += buf.position();
82-
buf.flip();
83-
}
84-
readCalls++; // We must count the last call
85-
long elapsed = sw.elapsed(TimeUnit.SECONDS);
86-
System.out.println("Read all " + total + " bytes in " + elapsed + "s. " +
87-
"(" + readCalls +" calls to chan.read)");
88-
String hex = String.valueOf(BaseEncoding.base16().encode(md.digest()));
89-
System.out.println("The MD5 is: 0x" + hex);
90-
if (total != size) {
91-
System.out.println("Wait, this doesn't match! We saw " + total + " bytes, " +
92-
"yet the file size is listed at " + size + " bytes.");
74+
try (SeekableByteChannel chan = Files.newByteChannel(path)) {
75+
long total = 0;
76+
int readCalls = 0;
77+
MessageDigest md = MessageDigest.getInstance("MD5");
78+
while (chan.read(buf) > 0) {
79+
readCalls++;
80+
md.update(buf.array(), 0, buf.position());
81+
total += buf.position();
82+
buf.flip();
83+
}
84+
readCalls++; // We must count the last call
85+
long elapsed = sw.elapsed(TimeUnit.SECONDS);
86+
System.out.println("Read all " + total + " bytes in " + elapsed + "s. " +
87+
"(" + readCalls +" calls to chan.read)");
88+
String hex = String.valueOf(BaseEncoding.base16().encode(md.digest()));
89+
System.out.println("The MD5 is: 0x" + hex);
90+
if (total != size) {
91+
System.out.println("Wait, this doesn't match! We saw " + total + " bytes, " +
92+
"yet the file size is listed at " + size + " bytes.");
93+
}
9394
}
9495
} catch (Exception ex) {
9596
System.out.println(fname + ": " + ex.toString());

branches/tswast-patch-1/gcloud-java-examples/src/main/java/com/google/cloud/examples/nio/ParallelCountBytes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public WorkUnit call() throws IOException {
7979
return this;
8080
}
8181
chan.position(pos);
82-
// read until buffer it is full, or EOF
82+
// read until buffer is full, or EOF
8383
while (chan.read(buf) > 0) {};
8484
return this;
8585
}

0 commit comments

Comments
 (0)