Added resourceToString, resourceToByteArray, and resourceToURL methods to IOUtils#17
Closed
behrangsa wants to merge 10 commits into
Closed
Added resourceToString, resourceToByteArray, and resourceToURL methods to IOUtils#17behrangsa wants to merge 10 commits into
behrangsa wants to merge 10 commits into
Conversation
added 2 commits
August 21, 2016 00:06
Added resourceToString(String name, Charset encoding) to read a classpath resource and convert it to String.
| } | ||
|
|
||
| @Test(expected = Test.None.class) public void testResourceToURL_ExistingResourceAtSubPackage() throws Exception { | ||
| IOUtils.resourceToURL("/org/apache/commons/io/FileUtilsTestDataCR.dat"); |
Member
There was a problem hiding this comment.
It is useful in positive test cases to verify things like the size or contents of the result to ensure that it isn't silently returning unuseful results. Ie, assertEquals("Wrong output size", expectedSize, result.size()) or similar as you can find above in this file.
Author
|
Hi all, Any comments, ideas, or suggestions? The JIRA issue is also created: https://issues.apache.org/jira/browse/IO-513# Cheers, |
|
|
||
| @Test public void testResourceToString_ExistingResourceAtRootPackage() throws Exception { | ||
| final long fileSize = new File(getClass().getResource("/test-file-utf8.bin").getFile()).length(); | ||
| final String content = IOUtils.resourceToString("/test-file-utf8.bin", Charset.defaultCharset()); |
Member
There was a problem hiding this comment.
Charset.defaultCharset here and in other tests seems wrong as it is locale/environment dependent. StandardCharsets.UTF_8 may be more appropriate.
Replaced Charset.defaultCharset() with StandardCharsets.UTF_8 to make the tests non-fragile
Author
|
Hi all, I think this PR is good to go ;) Cheers, |
Author
|
This PR has been moved to: #28 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added
resourceToString(String name, Charset encoding),resourceToByteArray(String name), andresourceToURL(String name)to read a classpath resource and convert it to String, byte array, and URL respectively.