Package com.atlassian.confluence.util.io
Interface InputStreamConsumer<T>
- Type Parameters:
T
-
public interface InputStreamConsumer<T>
Implementors consume an
InputStream
.
Typical usage pattern for methods that accept a consumer is to pass in an anonymous implementation of this interface:
something.withConsumer(new InputStreamConsumer<Boolean>(){
@Override
public Boolean withInputStream(InputStream is) throws IOException {
// do something with the InputStream
return true;
}
});
The withConsumer
method can then easily ensure that the InputStream
will be closed after the consumer is done with it.
private <T> T withConsumer(final InputStreamConsumer<T> sc) {
InputStream inputStream = new BufferedInputStream(<something something>);
try {
return sc.withInputStream(inputStream);
} catch (IOException e) {
throw new ThumbnailRenderException(e);
} finally {
IOUtils.closeQuietly(inputStream);
}
}
-
Method Summary
-
Method Details
-
withInputStream
- Throws:
IOException
-