ChkStreams extends the existing Java 8 Stream API. To use it, simply:
Wrap any Stream using ChkStreams.of(Stream) to get a ChkStream.
Declare one or more checked exceptions by calling
ChkStream#canThrow(Exception), so that subsequent stream operations will
allow that Exception.
Use the same Stream API you’re used to (except now your lambdas can throw the
declared exceptions!)
Handle the checked exceptions in the usual way (catch or declare thrown) in
any method that invokes a terminal operation on the stream.
Features
Adds checked exception support to the familiar Streams API!
Exceptions are enforced by the compiler in the usual way, and need only be
handled when invoking terminal operations.
Can be converted to/from regular Java Streams (See ChkStreams#of(Stream)
and ChkStream#toStream()). Regular streams obtained from
ChkStream#toStream() will throw unchecked exceptions (specifically
ChkStreamWrappedException) when checked exceptions occur in the stream.
All primitive specializations of Stream are supported without boxing (See
ChkStreams#ofInt(IntStream)).
Checked Exception Streams
Checked Exception Streams (ChkStreams) adds checked exception support to the Java 8 Stream API.
ChkStreams is not an official Google product.
Overview
Have you ever wanted to write something like this, but been foiled by the dreaded
Unhandled exception type IOException?Be foiled no more!
Usage
ChkStreams extends the existing Java 8 Stream API. To use it, simply:
StreamusingChkStreams.of(Stream)to get aChkStream.ChkStream#canThrow(Exception), so that subsequent stream operations will allow thatException.Features
Streams (SeeChkStreams#of(Stream)andChkStream#toStream()). Regular streams obtained fromChkStream#toStream()will throw unchecked exceptions (specificallyChkStreamWrappedException) when checked exceptions occur in the stream.Streamare supported without boxing (SeeChkStreams#ofInt(IntStream)).ChkStreamon Java 6+ and Android!Limitations
ChkStream.Streamor betweenChkStreams with different numbers of exceptions.License
This project is licensed under the GNU GPLv2 with Classpath Exception, which is the same license as OpenJDK itself.