• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

library for IO without throwing exceptions  RSS feed

 
author & internet detective
Posts: 38906
684
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: 21463
97
Chrome Eclipse IDE Java Spring Ubuntu VI Editor 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
Posts: 38906
684
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: 21463
97
Chrome Eclipse IDE Java Spring Ubuntu VI Editor 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
Posts: 38906
684
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!