Issue Details (XML | Word | Printable)

Key: GROOVY-2471
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Paul King
Reporter: Mike Dillon
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
groovy

Add newInputStream and withInputStream to java.net.URL for dealing with binary files

Created: 06/Jan/08 01:39 AM   Updated: 08/Feb/08 01:26 AM
Component/s: None
Affects Version/s: None
Fix Version/s: 1.5.2

Time Tracking:
Not Specified

File Attachments: 1. File URL-withInputStream.diff (2 kB)


Patch Submitted: Yes


 Description  « Hide
I recently came across a situation where I wanted to initialize a JCE Certificate directly from a URL. I wanted to do this:
def cfUrl = args[0].toURL()
def cf = CertificateFactory.getInstance("X.509")
def newRootCert = cfUrl.withInputStream { cf.generateCertificate(it) }

Putting aside the fact that the with* methods don't return the closure return value (which I'm going to create a separate JIRA for), there is not currently a withInputStream method for URL.

I could do something like this to work around it, but I'd rather do it the Groovier way:

def newRootCert = cfUrl.openStream().withStream { cf.generateCertificate(it) }

I've attached a patch to add URL.newInputStream and URL.withInputStream. It doesn't have any tests because I couldn't find any existing tests for URL.withReader (or File.withInputStream for that matter) and wasn't sure what the best way to handle it would be.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Paul King added a comment - 07/Jan/08 05:11 AM
should be in r10231

Paul King added a comment - 08/Feb/08 01:26 AM
close off release 1.5.4