Skip to content

Commit 756784b

Browse files
committed
use try with resources
1 parent 32ee220 commit 756784b

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/ChecksumEnforcingInputStreamTest.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,13 @@ public void read_withValidChecksum_differentPayloadSizes() throws Exception {
6262
@Test
6363
public void read_withInvalidChecksum() {
6464
// build a test instance with invalidchecksum
65-
ChecksumEnforcingInputStream instance =
66-
new ChecksumEnforcingInputStream(
67-
new ByteArrayInputStream("hello there".getBytes(UTF_8)),
68-
"this checksum is invalid",
69-
digest);
7065
// read 1000 bytes at a time
7166
// Since checksum should be correct, do not expect IOException
72-
byte[] buf = new byte[1000];
73-
try {
67+
try (ChecksumEnforcingInputStream instance = new ChecksumEnforcingInputStream(
68+
new ByteArrayInputStream("hello there".getBytes(UTF_8)),
69+
"this checksum is invalid",
70+
digest)) {
71+
byte[] buf = new byte[1000];
7472
while (instance.read(buf, 0, 1000) != -1) {
7573
// do nothing with the bytes read
7674
}
@@ -83,8 +81,9 @@ public void read_withInvalidChecksum() {
8381

8482
@Test
8583
public void markNotSupported() throws Exception {
86-
ChecksumEnforcingInputStream testInstance = setUpData(1);
87-
assertFalse(testInstance.markSupported());
84+
try (ChecksumEnforcingInputStream testInstance = setUpData(1)) {
85+
assertFalse(testInstance.markSupported());
86+
}
8887
}
8988

9089
private ChecksumEnforcingInputStream setUpData(int payloadSize) throws Exception {
@@ -93,7 +92,7 @@ private ChecksumEnforcingInputStream setUpData(int payloadSize) throws Exception
9392
String payload;
9493
if (payloadSize > str.length()) {
9594
int num = payloadSize / str.length();
96-
StringBuffer buf = new StringBuffer();
95+
StringBuilder buf = new StringBuilder();
9796
for (int i = 0; i < num; i++) {
9897
buf.append(str);
9998
}

0 commit comments

Comments
 (0)