Giter Club home page Giter Club logo

chkstream's Introduction

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?

filenames.parallelStream()
  .map(Files::readFully)
  .collect(toList());

Be foiled no more!

ChkStreams.of(filenames.parallelStream())
  .canThrow(IOException.class)
  .map(Files::readFully)
  .collect(toList());

Usage

ChkStreams extends the existing Java 8 Stream API. To use it, simply:

  1. Wrap any Stream using ChkStreams.of(Stream) to get a ChkStream.
  2. Declare one or more checked exceptions by calling ChkStream#canThrow(Exception), so that subsequent stream operations will allow that Exception.
  3. Use the same Stream API you're used to (except now your lambdas can throw the declared exceptions!)
  4. 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)).
  • (Optional) support for the StreamSupport backport and Retrolambda. Enjoy the power of ChkStream on Java 6+ and Android!
  • May cause you to barf rainbows.

Limitations

  • A maximum of 5 checked exceptions may be added to a ChkStream.
  • No interfaces in common with Stream or between ChkStreams 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.

chkstream's People

Contributors

adorokhine avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.