Search in sources :

Example 11 with NullInputStream

use of org.apache.commons.io.input.NullInputStream in project webservices-axiom by apache.

the class TestWriteAfterCommit method runTest.

@Override
protected void runTest(WritableBlob blob) throws Throwable {
    OutputStream out = blob.getOutputStream();
    out.close();
    try {
        out.write(new byte[10]);
        fail("Expected exception");
    } catch (IllegalStateException ex) {
    // OK
    } catch (IOException ex) {
    // OK
    }
    try {
        out.write(new byte[10], 3, 5);
        fail("Expected exception");
    } catch (IllegalStateException ex) {
    // OK
    } catch (IOException ex) {
    // OK
    }
    try {
        out.write(0);
        fail("Expected exception");
    } catch (IllegalStateException ex) {
    // OK
    } catch (IOException ex) {
    // OK
    }
    if (out instanceof ReadFromSupport) {
        try {
            ((ReadFromSupport) out).readFrom(new NullInputStream(10), -1);
            fail("Expected exception");
        } catch (IllegalStateException ex) {
        // OK
        } catch (IOException ex) {
        // OK
        }
    }
}
Also used : OutputStream(java.io.OutputStream) ReadFromSupport(org.apache.axiom.ext.io.ReadFromSupport) IOException(java.io.IOException) NullInputStream(org.apache.commons.io.input.NullInputStream)

Example 12 with NullInputStream

use of org.apache.commons.io.input.NullInputStream in project dhis2-core by dhis2.

the class JCloudsFileResourceContentStore method getFileResourceContent.

// -------------------------------------------------------------------------
// FileResourceContentStore implementation
// -------------------------------------------------------------------------
@Override
public ByteSource getFileResourceContent(String key) {
    final Blob blob = getBlob(key);
    if (blob == null) {
        return null;
    }
    final ByteSource byteSource = new ByteSource() {

        @Override
        public InputStream openStream() {
            try {
                return blob.getPayload().openStream();
            } catch (IOException e) {
                return new NullInputStream(0);
            }
        }
    };
    boolean isEmptyOrFailed;
    try {
        isEmptyOrFailed = byteSource.isEmpty();
    } catch (IOException e) {
        isEmptyOrFailed = true;
    }
    return isEmptyOrFailed ? null : byteSource;
}
Also used : Blob(org.jclouds.blobstore.domain.Blob) ByteSource(com.google.common.io.ByteSource) IOException(java.io.IOException) 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