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
}
}
}
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;
}
Aggregations