commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gary Gregory (JIRA)" <>
Subject [jira] [Commented] (IO-513) Add convenience methods for reading class path resources
Date Tue, 23 Aug 2016 14:50:20 GMT


Gary Gregory commented on IO-513:

Hi All:

The current patch for {{resourceToString}} and {{resourceToByteArray}} will throw an {{NullPointerException}}
when the input is bogus. You should most likely detect the null value and throw an {{IllegalArgumentException}}.

I usually end up with the kind of code in this proposal somewhere in most of my projects.
But where does it belong in Commons? One could argue that the URL and URI APIs belong in Commons

The {{resourcesTo*}} methods I usually put in a {{ResourceUtils}} class and call them {{get<ReturnType>()}}
or {{readAs<ReturnType}}>; the {{to}} prefix is not appropriate IMO because you are
not _converting_ anything, you are reading from a resource. 

I also usually end up needing a variant that takes a {{ClassLoader}} so the resource can be
found in the right place in more complex use-cases.

Dealing with Charsets is a must in my day to day work, so I am not surprised when it shows
up in APIs. Relying on the default platform encoding is usually problematic when you are moving
files around different machines.


> Add convenience methods for reading class path resources
> --------------------------------------------------------
>                 Key: IO-513
>                 URL:
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Utilities
>            Reporter: Behrang Saeedzadeh
>            Priority: Minor
>              Labels: beginner, features, github-import, newbie
> Add convenience methods to {{IOUtils}} for reading class path resources and returning
them as {{String}}, {{byte[]}}, and {{URL}} respectively.
> Github PR:

This message was sent by Atlassian JIRA

View raw message