Search in sources :

Example 1 with NullInputStream

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);
}
Also used : CountingOutputStream(org.apache.commons.io.output.CountingOutputStream) NullInputStream(org.apache.commons.io.input.NullInputStream) InputStream(java.io.InputStream) NullInputStream(org.apache.commons.io.input.NullInputStream) NullOutputStream(org.apache.commons.io.output.NullOutputStream) Test(org.junit.Test)

Example 2 with NullInputStream

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();
}
Also used : IndexOutput(org.apache.lucene.store.IndexOutput) InputStreamDataInput(org.apache.lucene.store.InputStreamDataInput) NullInputStream(org.apache.commons.io.input.NullInputStream)

Example 3 with NullInputStream

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
    }
}
Also used : NullInputStream(org.apache.commons.io.input.NullInputStream)

Example 4 with NullInputStream

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());
    }
}
Also used : ExceptionInputStream(org.apache.axiom.testutils.io.ExceptionInputStream) StreamCopyException(org.apache.axiom.ext.io.StreamCopyException) NullInputStream(org.apache.commons.io.input.NullInputStream)

Example 5 with NullInputStream

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();
    }
}
Also used : NullInputStream(org.apache.commons.io.input.NullInputStream) InputStream(java.io.InputStream) NullInputStream(org.apache.commons.io.input.NullInputStream)

Aggregations

NullInputStream (org.apache.commons.io.input.NullInputStream)12 InputStream (java.io.InputStream)4 IOException (java.io.IOException)2 StreamCopyException (org.apache.axiom.ext.io.StreamCopyException)2 ByteSource (com.google.common.io.ByteSource)1 XmlFile (hudson.XmlFile)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 OutputStream (java.io.OutputStream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 Node (javax.jcr.Node)1 ReadFromSupport (org.apache.axiom.ext.io.ReadFromSupport)1 ExceptionInputStream (org.apache.axiom.testutils.io.ExceptionInputStream)1 ExceptionOutputStream (org.apache.axiom.testutils.io.ExceptionOutputStream)1 CountingOutputStream (org.apache.commons.io.output.CountingOutputStream)1 NullOutputStream (org.apache.commons.io.output.NullOutputStream)1 IndexOutput (org.apache.lucene.store.IndexOutput)1 InputStreamDataInput (org.apache.lucene.store.InputStreamDataInput)1 Blob (org.jclouds.blobstore.domain.Blob)1 Test (org.junit.Test)1