Browse Source

AutoLFInputStreamTest: Use try-with-resource

Change-Id: I162bfa6b2f87f2ce9154f3ed6bb628c4cda88f50
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
stable-5.0
David Pursehouse 7 years ago
parent
commit
48554989d3
  1. 23
      org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java

23
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java

@ -97,8 +97,8 @@ public class AutoLFInputStreamTest {
private static void test(byte[] input, byte[] expected,
boolean detectBinary) throws IOException {
final InputStream bis1 = new ByteArrayInputStream(input);
final InputStream cis1 = new AutoLFInputStream(bis1, detectBinary);
try (InputStream bis1 = new ByteArrayInputStream(input);
InputStream cis1 = new AutoLFInputStream(bis1, detectBinary)) {
int index1 = 0;
for (int b = cis1.read(); b != -1; b = cis1.read()) {
assertEquals(expected[index1], (byte) b);
@ -109,23 +109,26 @@ public class AutoLFInputStreamTest {
for (int bufferSize = 1; bufferSize < 10; bufferSize++) {
final byte[] buffer = new byte[bufferSize];
final InputStream bis2 = new ByteArrayInputStream(input);
final InputStream cis2 = new AutoLFInputStream(bis2, detectBinary);
try (InputStream bis2 = new ByteArrayInputStream(input);
InputStream cis2 = new AutoLFInputStream(bis2,
detectBinary)) {
int read = 0;
for (int readNow = cis2.read(buffer, 0, buffer.length); readNow != -1
&& read < expected.length; readNow = cis2.read(buffer, 0,
buffer.length)) {
for (int readNow = cis2.read(buffer, 0,
buffer.length); readNow != -1
&& read < expected.length; readNow = cis2
.read(buffer, 0, buffer.length)) {
for (int index2 = 0; index2 < readNow; index2++) {
assertEquals(expected[read + index2], buffer[index2]);
assertEquals(expected[read + index2],
buffer[index2]);
}
read += readNow;
}
assertEquals(expected.length, read);
cis2.close();
}
cis1.close();
}
}
}
private static byte[] asBytes(String in) {

Loading…
Cancel
Save