Skip to content

Commit 66d76e2

Browse files
jean-philippe-martinmziccard
authored andcommitted
---
yaml --- r: 4317 b: refs/heads/gcs-nio c: ed440e9 h: refs/heads/master i: 4315: 8aeb551
1 parent a788d9c commit 66d76e2

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
@@ -11,7 +11,7 @@ refs/tags/v0.0.12: 2fd8066e891fb3dfea69b65f6bf6461db79342b9
1111
refs/heads/compute-alpha: 969cba2627f1d53d352cc4a5ffe0879dacf65e6c
1212
refs/heads/dns-alpha: 2f90e7e338349287ace33375896907af0f032ca1
1313
refs/heads/dns-alpha-batch: 17442b07867021b85d0452f5f3eda29a3413288f
14-
refs/heads/gcs-nio: 441918b95daf8b04554f99e54753e13802b184d7
14+
refs/heads/gcs-nio: ed440e95d223c6d50621a06c329a57f80028b8a5
1515
refs/heads/logging-alpha: db5312bffa7fccac194f6a7feb8cc3066de16aff
1616
refs/tags/v0.1.0: a615317f7424ed58621b1f65d5c4d8cbbe8a6ed8
1717
refs/tags/v0.1.1: 7a7f6985fe465e9dd6a075af55493f42b4933be0

branches/gcs-nio/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/gcs-nio/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)