Access to unzipped assets within jars

2011-11-05 Thread Sam Aaron
Hi there,

consider there exists foo.jar on Clojars which contains a bunch of asset files 
i.e. png images. If I were to declare foo as one of my project's dependencies, 
is it possible to get access to those asset files? I essentially want a path to 
a non-zipped version of each asset.

Sam

---
http://sam.aaron.name

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Access to unzipped assets within jars

2011-11-05 Thread Ben Smith-Mannschott
On Sat, Nov 5, 2011 at 14:42, Sam Aaron samaa...@gmail.com wrote:
 Hi there,

 consider there exists foo.jar on Clojars which contains a bunch of asset 
 files i.e. png images. If I were to declare foo as one of my project's 
 dependencies, is it possible to get access to those asset files? I 
 essentially want a path to a non-zipped version of each asset.

These kinds of assets are known as resources in java parlance. A
resource is named by a path relative to an entry in the classpath.
Declaring foo as a dependency will place it in the classpath. The name
of the resource will therefore be the path of the asset within
foo.jar.

Give clojure.java.io/resource [1] that name, and it will return a URL.

Pass that URL to clojure.java.io/input-stream [2] to open the resource
for reading.

[1] 
http://clojure.github.com/clojure/clojure.java.io-api.html#clojure.java.io/resource

[2] 
http://clojure.github.com/clojure/clojure.java.io-api.html#clojure.java.io/input-stream

hth,
Ben

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Access to unzipped assets within jars

2011-11-05 Thread Baishampayan Ghose
Sam,

 consider there exists foo.jar on Clojars which contains a bunch of asset 
 files i.e. png images. If I were to declare foo as one of my
 project's dependencies, is it possible to get access to those asset files? I 
 essentially want a path to a non-zipped version of each
 asset.

I think `clojure.java.io/resource` will do the trick for you. You just
need to know the path to the png file inside the JAR and as long as
the JAR is in your classpath, you should be able to read it.

Regards,
BG

-- 
Baishampayan Ghose
b.ghose at gmail.com

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Access to unzipped assets within jars

2011-11-05 Thread Sam Aaron
Interesting - thanks for this. So is it fair to assume that the JVM is ok with 
reading URL resources that are zipped in a jar. I also assume to have an actual 
non-zipped version of the resource I need to copy the file from inside the 
zipped jar to an external path in my file system?

Sam

---
http://sam.aaron.name

On 5 Nov 2011, at 14:03, Ben Smith-Mannschott wrote:

 On Sat, Nov 5, 2011 at 14:42, Sam Aaron samaa...@gmail.com wrote:
 Hi there,
 
 consider there exists foo.jar on Clojars which contains a bunch of asset 
 files i.e. png images. If I were to declare foo as one of my project's 
 dependencies, is it possible to get access to those asset files? I 
 essentially want a path to a non-zipped version of each asset.
 
 These kinds of assets are known as resources in java parlance. A
 resource is named by a path relative to an entry in the classpath.
 Declaring foo as a dependency will place it in the classpath. The name
 of the resource will therefore be the path of the asset within
 foo.jar.
 
 Give clojure.java.io/resource [1] that name, and it will return a URL.
 
 Pass that URL to clojure.java.io/input-stream [2] to open the resource
 for reading.
 
 [1] 
 http://clojure.github.com/clojure/clojure.java.io-api.html#clojure.java.io/resource
 
 [2] 
 http://clojure.github.com/clojure/clojure.java.io-api.html#clojure.java.io/input-stream
 
 hth,
 Ben
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en