• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

library for IO without throwing exceptions

 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, so you've done it in the opposite way.
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic