|
|
@ -97,35 +97,38 @@ 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); |
|
|
|
index1++; |
|
|
|
index1++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(expected.length, index1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int read = 0; |
|
|
|
assertEquals(expected.length, index1); |
|
|
|
for (int readNow = cis2.read(buffer, 0, buffer.length); readNow != -1 |
|
|
|
|
|
|
|
&& read < expected.length; readNow = cis2.read(buffer, 0, |
|
|
|
for (int bufferSize = 1; bufferSize < 10; bufferSize++) { |
|
|
|
buffer.length)) { |
|
|
|
final byte[] buffer = new byte[bufferSize]; |
|
|
|
for (int index2 = 0; index2 < readNow; index2++) { |
|
|
|
try (InputStream bis2 = new ByteArrayInputStream(input); |
|
|
|
assertEquals(expected[read + index2], buffer[index2]); |
|
|
|
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 index2 = 0; index2 < readNow; index2++) { |
|
|
|
|
|
|
|
assertEquals(expected[read + index2], |
|
|
|
|
|
|
|
buffer[index2]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
read += readNow; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(expected.length, read); |
|
|
|
} |
|
|
|
} |
|
|
|
read += readNow; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(expected.length, read); |
|
|
|
|
|
|
|
cis2.close(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
cis1.close(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static byte[] asBytes(String in) { |
|
|
|
private static byte[] asBytes(String in) { |
|
|
|