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