use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.
the class CachingFilterInputStreamTest_NonMarkableByteArrayInputStream method readBytes_onClosedStream.
@Test(expected = IOException.class)
public void readBytes_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));
final byte[] result = new byte[2];
cfis.read(result);
assertArrayEquals(subArray(testData, 2), result);
cfis.close();
// should cause IOException
cfis.read(result);
}
use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.
the class CachingFilterInputStreamTest_NonMarkableByteArrayInputStream method available_onOffsetCachedStream.
@Test
public void available_onOffsetCachedStream() 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);
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());
}
use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream 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.UnsynchronizedByteArrayInputStream in project exist by eXist-db.
the class CachingFilterInputStreamTest_NonMarkableByteArrayInputStream method skip.
@Test
public void skip() 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 the first 3 bytes
assertEquals(testData[0], cfis.read());
assertEquals(testData[1], cfis.read());
assertEquals(testData[2], cfis.read());
// skip 3 bytes
cfis.skip(3);
// read bytes 5 to 7 inclusive
assertEquals(testData[6], cfis.read());
assertEquals(testData[7], cfis.read());
assertEquals(testData[8], cfis.read());
}
use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.
the class CachingFilterInputStreamTest method skip_onClosedStream.
@Test(expected = IOException.class)
public void skip_onClosedStream() 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));
cfis.close();
// should cause IOException
cfis.skip(1);
}
Aggregations