AutoCRLFInputStreamTest: Open auto-closeable resources in try-with-resource

Change-Id: I427ab43a82861f7bc69b104e29dc4360048aec4e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
David Pursehouse 2018-03-05 20:59:31 +09:00
parent 8ab6f78d02
commit fd20f8c657
1 changed files with 16 additions and 17 deletions

View File

@ -93,9 +93,9 @@ private void assertNoCrLfHelper(String expect, String input)
byte[] expectBytes = expect.getBytes(); byte[] expectBytes = expect.getBytes();
for (int i = 0; i < 5; ++i) { for (int i = 0; i < 5; ++i) {
byte[] buf = new byte[i]; byte[] buf = new byte[i];
ByteArrayInputStream bis = new ByteArrayInputStream(inbytes); try (ByteArrayInputStream bis = new ByteArrayInputStream(inbytes);
InputStream in = new AutoCRLFInputStream(bis, true); InputStream in = new AutoCRLFInputStream(bis, true);
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream()) {
if (i > 0) { if (i > 0) {
int n; int n;
while ((n = in.read(buf)) >= 0) { while ((n = in.read(buf)) >= 0) {
@ -107,13 +107,12 @@ private void assertNoCrLfHelper(String expect, String input)
out.write(c); out.write(c);
} }
out.flush(); out.flush();
in.close();
out.close();
byte[] actualBytes = out.toByteArray(); byte[] actualBytes = out.toByteArray();
Assert.assertEquals("bufsize=" + i, encode(expectBytes), Assert.assertEquals("bufsize=" + i, encode(expectBytes),
encode(actualBytes)); encode(actualBytes));
} }
} }
}
String encode(byte[] in) { String encode(byte[] in) {
StringBuilder str = new StringBuilder(); StringBuilder str = new StringBuilder();