use of org.apache.commons.io.input.NullInputStream in project jackrabbit-oak by apache.
the class StatsCollectingStreamsTest method downloadCallback.
@Test
public void downloadCallback() throws Exception {
NullInputStream in = new NullInputStream(1042);
TestCollector stats = new TestCollector();
InputStream wrappedStream = StatsCollectingStreams.wrap(stats, "foo", in);
assertEquals(0, stats.callbackCount);
//Copy the content to get size
CountingOutputStream cos = new CountingOutputStream(new NullOutputStream());
IOUtils.copy(wrappedStream, cos);
assertEquals(1042, cos.getCount());
//Stream not closed so no callback
assertEquals(0, stats.callbackCount);
wrappedStream.close();
assertEquals(1042, stats.size);
assertEquals(1, stats.downloadCompletedCount);
}
use of org.apache.commons.io.input.NullInputStream in project jackrabbit-oak by apache.
the class OakDirectoryTest method writeFile.
private static void writeFile(Directory directory, String fileName, long size) throws Exception {
IndexOutput o = directory.createOutput(fileName, IOContext.DEFAULT);
o.copyBytes(new InputStreamDataInput(new NullInputStream(size)), size);
o.close();
}
use of org.apache.commons.io.input.NullInputStream in project webservices-axiom by apache.
the class TestReadFromIllegalState method runTest.
@Override
protected void runTest(WritableBlob blob) throws Throwable {
try {
blob.readFrom(new NullInputStream(0));
fail("Expected IllegalStateException");
} catch (IllegalStateException ex) {
// Expected
}
}
use of org.apache.commons.io.input.NullInputStream in project webservices-axiom by apache.
the class TestReadFromWithError method runTest.
@Override
protected void runTest(WritableBlob blob) throws Throwable {
ExceptionInputStream in = new ExceptionInputStream(new NullInputStream(1000), 500);
try {
blob.readFrom(in);
fail("Expected StreamCopyException");
} catch (StreamCopyException ex) {
assertThat(ex.getOperation()).isEqualTo(StreamCopyException.READ);
assertThat(ex.getCause()).isSameAs(in.getException());
}
}
use of org.apache.commons.io.input.NullInputStream in project webservices-axiom by apache.
the class TestReadZeroLength method runTest.
@Override
protected void runTest(WritableBlob blob) throws Throwable {
blob.readFrom(new NullInputStream(100));
InputStream in = blob.getInputStream();
try {
IOUtils.toByteArray(in, 50);
assertThat(in.read(new byte[0])).isEqualTo(0);
} finally {
in.close();
}
}
Aggregations