use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.
the class CachingFilterInputStreamTest 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();
InputStream is = new UnsynchronizedByteArrayInputStream(testData);
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
int b = cfis.read();
assertEquals(-1, b);
}
use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.
the class CachingFilterInputStreamTest method available_onPartiallyReadStream.
@Test
public void available_onPartiallyReadStream() throws IOException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
final String testString = "helloWorld";
final byte[] testData = testString.getBytes();
InputStream is = new UnsynchronizedByteArrayInputStream(testData);
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 method skip_correctlyAdjustsSrcOffset_onSharedCache.
@Test
public void skip_correctlyAdjustsSrcOffset_onSharedCache() throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, IOException {
final String testString = "helloWorld";
final byte[] testData = testString.getBytes();
final InputStream is = new UnsynchronizedByteArrayInputStream(testData);
final FilterInputStreamCache cache = getNewCache(is);
final CachingFilterInputStream cfis1 = new CachingFilterInputStream(cache);
final CachingFilterInputStream cfis2 = new CachingFilterInputStream(cache);
assertEquals(0, cfis1.offset());
final long skipped1 = cfis1.skip(5);
assertEquals(5, skipped1);
assertEquals(5, cfis1.offset());
assertEquals(0, cfis2.offset());
final long skipped2 = cfis2.skip(5);
assertEquals(5, skipped2);
assertEquals(5, cfis2.offset());
}
use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.
the class CachingFilterInputStreamTest method available_onPartiallyCachedStream.
@Test
public void available_onPartiallyCachedStream() throws IOException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
final String testString = "helloWorld";
final byte[] testData = testString.getBytes();
InputStream is = new UnsynchronizedByteArrayInputStream(testData);
CachingFilterInputStream cfis = new CachingFilterInputStream(getNewCache(is));
// mark for later reset
cfis.mark(Integer.MAX_VALUE);
// read first 2 bytes
cfis.read();
cfis.read();
// return to the start of the stream
cfis.reset();
assertEquals(testData.length, cfis.available());
}
use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.
the class CachingFilterInputStreamTest method available_onOffsetCachedStream.
@Test
public void available_onOffsetCachedStream() throws IOException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
final String testString = "helloWorld";
final byte[] testData = testString.getBytes();
InputStream is = new UnsynchronizedByteArrayInputStream(testData);
CachingFilterInputStream cfis = new CachingFilterInputStream(getNewCache(is));
// read first 2 bytes
cfis.read();
cfis.read();
// mark for later reset
cfis.mark(Integer.MAX_VALUE);
for (int i = 0; i < testData.length - 2; i++) {
cfis.read();
}
// return to the start of the stream
cfis.reset();
assertEquals(testData.length - 2, cfis.available());
}
Aggregations