• Post Reply Bookmark Topic Watch Topic
  • New Topic

library for IO without throwing exceptions  RSS feed

 
author & internet detective
Marshal
Posts: 38152
617
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java 8, you have to wrap checked exceptions in an unchecked exception to use them within a lambda. Does anyone know of an open source library that wraps Java NIO.2 (The Files class in particular) so it doesn't throw checked exceptions. For example, I want to delete files, write to files, etc.

I could write what I need, but it feels like this exists so asking first.
 
Sheriff
Posts: 21313
87
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For use in streams I've written a copy of all the functional interfaces, including methods to convert these copies to the "regular" versions and vice versa. See https://github.com/robtimus/io-functions for more information.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 38152
617
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, so you've done it in the opposite way.
 
Rob Spoor
Sheriff
Posts: 21313
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the unchecked methods doing the wrapping to form a bridge with the existing libraries. It does make it a bit more verbose but it was the least amount of work, and makes it generic enough to handle any IOException throwing code.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 38152
617
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote:With the unchecked methods doing the wrapping to form a bridge with the existing libraries. It does make it a bit more verbose but it was the least amount of work, and makes it generic enough to handle any IOException throwing code.


Understood. My team uses a set of less than a dozen IO methods regularly. And a lot of them are new to Java 8 so I want them to get used to the built in functional interfaces.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!