use of org.apache.commons.io.input.MarkShieldInputStream in project exist by eXist-db.
the class CachingFilterInputStreamTest_NonMarkableByteArrayInputStream method interleavedSourceReads.
/**
* When given an underlying InputSource and caching it twice with the same
* cache we should be able to read the input twice assuming that the input
* that we are interested in has not been read before a mark()
*/
@Test
public void interleavedSourceReads() throws IOException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
final byte[] testData = generateRandomData(_64KB);
final InputStream is = new MarkShieldInputStream(new UnsynchronizedByteArrayInputStream(testData));
final FilterInputStreamCache cache1 = getNewCache(is);
final CachingFilterInputStream cfis1 = new CachingFilterInputStream(cache1);
cfis1.mark(Integer.MAX_VALUE);
final CachingFilterInputStream cfis2 = new CachingFilterInputStream(cache1);
final byte[] result1 = new byte[_12KB];
cfis1.read(result1);
assertArrayEquals(subArray(testData, _12KB), result1);
final byte[] result2 = new byte[_12KB];
cfis2.read(result2);
assertArrayEquals(subArray(testData, _12KB), result2);
}
use of org.apache.commons.io.input.MarkShieldInputStream in project exist by eXist-db.
the class CachingFilterInputStreamTest_NonMarkableByteArrayInputStream method sharedCacheWritesInOrder.
@Test
public void sharedCacheWritesInOrder() throws IOException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
final byte[] testData = generateRandomData(_64KB);
final InputStream is = new MarkShieldInputStream(new UnsynchronizedByteArrayInputStream(testData));
// first CachingFilterInputStream
final CachingFilterInputStream cfis1 = new CachingFilterInputStream(getNewCache(is));
// read first 6KB
final byte[] cfis1Part1 = new byte[_6KB];
cfis1.read(cfis1Part1);
// ensure first 6KB was read!
assertArrayEquals(subArray(testData, _6KB), cfis1Part1);
// second CachingFilterInputStream wraps first CachingFilterInputStream
final CachingFilterInputStream cfis2 = new CachingFilterInputStream(cfis1);
// read first 32KB from second InputStream
final byte[] cfis2Part1 = new byte[_32KB];
cfis2.read(cfis2Part1);
// ensure next 32KB was read!
assertArrayEquals(subArray(testData, _32KB), cfis2Part1);
// interleave by reading another 6KB from first InputStream
final byte[] cfis1Part2 = new byte[_6KB];
cfis1.read(cfis1Part2);
// ensure first 6KB was read!
assertArrayEquals(subArray(testData, _6KB, _6KB), cfis1Part2);
}
use of org.apache.commons.io.input.MarkShieldInputStream in project exist by eXist-db.
the class CachingFilterInputStreamTest_NonMarkableByteArrayInputStream method constructed_from_CachingFilterInputStream_consumed.
@Test
public void constructed_from_CachingFilterInputStream_consumed() throws IOException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
final byte[] testData = generateRandomData(_12KB);
final InputStream is = new MarkShieldInputStream(new UnsynchronizedByteArrayInputStream(testData));
// first CachingFilterInputStream
final CachingFilterInputStream cfis1 = new CachingFilterInputStream(getNewCache(is));
assertArrayEquals(testData, consumeInputStream(cfis1));
// second CachingFilterInputStream wraps first CachingFilterInputStream
final CachingFilterInputStream cfis2 = new CachingFilterInputStream(cfis1);
assertArrayEquals(testData, consumeInputStream(cfis2));
}
use of org.apache.commons.io.input.MarkShieldInputStream in project exist by eXist-db.
the class CachingFilterInputStreamTest_NonMarkableByteArrayInputStream method constructed_from_CachingFilterInputStream_partiallyConsumed.
@Test
public void constructed_from_CachingFilterInputStream_partiallyConsumed() throws IOException, InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
final byte[] testData = generateRandomData(_12KB);
final InputStream is = new MarkShieldInputStream(new UnsynchronizedByteArrayInputStream(testData));
// first CachingFilterInputStream
final CachingFilterInputStream cfis1 = new CachingFilterInputStream(getNewCache(is));
// read first 6KB
final byte[] firstPart = new byte[_6KB];
cfis1.read(firstPart);
// ensure first 6KB was read!
assertArrayEquals(subArray(testData, _6KB), firstPart);
// second CachingFilterInputStream wraps first CachingFilterInputStream
final CachingFilterInputStream cfis2 = new CachingFilterInputStream(cfis1);
assertArrayEquals(testData, consumeInputStream(cfis2));
}
Aggregations