Nice pattern for Java6, but in Java7 handling streams is a lot easier if you use try-with-resources: try (InputStream in = producer.produce) { consumer.consume(in);}Since InputStream implements java.lang.Autocloseable you don't need to manually close the stream in a finally (which may fail).
yes.. exactly... i read about those enhancements but i'm still using jdk1.6. Are you already using 1.7 in your projects nowadays? I delayed the switch at the time because 1.7 still had some issues as far as I remember
Nice pattern for Java6, but in Java7 handling streams is a lot easier if you use try-with-resources:
ReplyDeletetry (InputStream in = producer.produce) {
consumer.consume(in);
}
Since InputStream implements java.lang.Autocloseable you don't need to manually close the stream in a finally (which may fail).
yes.. exactly... i read about those enhancements but i'm still using jdk1.6. Are you already using 1.7 in your projects nowadays? I delayed the switch at the time because 1.7 still had some issues as far as I remember
Delete