OK, I finally got it going, I convert the InputStream to a String.
Here is the code:
InputStream exportTemplateStream =
getClass().getClassLoader().getResourceAsStream("export.template")
assert exportTemplateStream: "[export.template stream]
resource not found"
String exportTemplate = slurp(exportTemplateStream)
the "slurp" method is (guess it's limited to 4096 bytes which is lame):
public String slurp(InputStream input) {
StringBuffer out = new StringBuffer();
byte[] b = new byte[4096];
for (int n; (n = input.read(b)) != -1;) {
out.append(new String(b, 0, n));
}
return out.toString();
}
I stole this off google. Anyone know a better way to do it? Apache
FileUtils method somewhere? It's quite ugly...
phil
On Fri, Apr 29, 2011 at 2:00 PM, phil swenson <[email protected]> wrote:
> OK... I'll try this. So how do I convert an InputStream into either a
> File or a String?
>
> InputStream template =
> ClassLoader.getSystemResourceAsStream("export.template")
>
> phil
>
> On Fri, Apr 29, 2011 at 1:33 PM, Peter Niederwieser <[email protected]>
> wrote:
>>
>> phil swenson wrote:
>>>
>>> I even tried this code as I thought that perhaps I needed a "/" in
>>> front of the resource
>>>
>>
>> As far as I know, resource names passed to
>> ClassLoader.getResource/getResourceAsStream shouldn't have a leading slash,
>> but need to be absolute. The situation is different for
>> Class.getResource/getResourceAsStream. The latter are convenience methods
>> built on top of the former.
>>
>> --
>> Peter Niederwieser
>> Developer, Gradle
>> http://www.gradle.org
>> Trainer & Consultant, Gradleware
>> http://www.gradleware.com
>> Creator, Spock Framework
>> http://spockframework.org
>>
>> --
>> View this message in context:
>> http://gradle.1045684.n5.nabble.com/referencing-a-resource-in-gradle-tp4359379p4359589.html
>> Sent from the gradle-user mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>> http://xircles.codehaus.org/manage_email
>>
>>
>>
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email