use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.
the class CachingFilterInputStreamTest_NonMarkableByteArrayInputStream method available_onPartiallyReadStream.
@Test
public void available_onPartiallyReadStream() throws IOException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
final String testString = "helloWorld";
final byte[] testData = testString.getBytes();
final InputStream is = new UnsynchronizedByteArrayInputStream(testData);
final CachingFilterInputStream cfis = new CachingFilterInputStream(getNewCache(is));
// read first 2 bytes
cfis.read();
cfis.read();
assertEquals(testData.length - 2, cfis.available());
}
use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.
the class CachingFilterInputStreamTest_NonMarkableByteArrayInputStream method readByte_pastEndOfStream_fromCache.
@Test
public void readByte_pastEndOfStream_fromCache() throws IOException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
final String testString = "he";
final byte[] testData = testString.getBytes();
final InputStream is = new UnsynchronizedByteArrayInputStream(testData);
final CachingFilterInputStream cfis = new CachingFilterInputStream(getNewCache(is));
cfis.mark(Integer.MAX_VALUE);
assertEquals(testData[0], cfis.read());
assertEquals(testData[1], cfis.read());
cfis.reset();
assertEquals(testData[0], cfis.read());
assertEquals(testData[1], cfis.read());
// read byte past end of cache
final int b = cfis.read();
assertEquals(-1, b);
}
use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.
the class CachingFilterInputStreamTest_NonMarkableByteArrayInputStream method available_onOffsetPartiallyCachedStream.
@Test
public void available_onOffsetPartiallyCachedStream() throws IOException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
final String testString = "helloWorld";
final byte[] testData = testString.getBytes();
final InputStream is = new UnsynchronizedByteArrayInputStream(testData);
final CachingFilterInputStream cfis = new CachingFilterInputStream(getNewCache(is));
// read first 2 bytes
cfis.read();
cfis.read();
// mark for later reset
cfis.mark(Integer.MAX_VALUE);
// read next 2 bytes
cfis.read();
cfis.read();
// return to the start of the stream
cfis.reset();
assertEquals(testData.length - 2, cfis.available());
}
use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.
the class CachingFilterInputStreamTest_NonMarkableByteArrayInputStream method readByte_onClosedStream.
@Test(expected = IOException.class)
public void readByte_onClosedStream() throws IOException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
final String testString = "helloWorld";
final byte[] testData = testString.getBytes();
final InputStream is = new UnsynchronizedByteArrayInputStream(testData);
final CachingFilterInputStream cfis = new CachingFilterInputStream(getNewCache(is));
assertEquals(testData[0], cfis.read());
cfis.close();
// should cause IOException
cfis.read();
}
use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.
the class CachingFilterInputStreamTest_NonMarkableByteArrayInputStream method readByte_pastEndOfStream.
@Test
public void readByte_pastEndOfStream() throws IOException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
final String testString = "helloWorld";
final byte[] testData = testString.getBytes();
final InputStream is = new UnsynchronizedByteArrayInputStream(testData);
final CachingFilterInputStream cfis = new CachingFilterInputStream(getNewCache(is));
// read all the bytes upto end of stream
int b = -1;
int testDataOffset = 0;
while ((b = cfis.read()) > -1) {
assertEquals(testData[testDataOffset++], b);
}
// read byte past end of stream
b = cfis.read();
assertEquals(-1, b);
}
Aggregations