Resources and NIO ?

As you all know, it is very convenient to put all kind of resources (images, audio files, …) into a jar-archive and access them using getResource or getResourceAsStream. The disadvantage is that one cannot use nio classes in order to have fast random access like using the FileChannel.

Therefore I was wondering how a JRE deals with reources/jar files in the classpath. Would it be possible at all to get random access on resources. I mean, does the runtime decompress all classes/resources when noticing their presence? Of course a fast random access on compressed ZipEntries does not make sense.

Any thoughts on this?

As i don’t know how that with the jars is dealt, i wanna only say that the game content for a level should loaded completly on level loading. Regardless a player finds a secret room that only 1% of all players might find. So putting everything into a jar should work fine, but my personal opinion about this that everyone with a zip programm can access my files.

Because the classpath is at its lowest level a series of URLs, it’s possible for (almost) any jar file on the classpath to be accessed over the network rather than as a file on the local file system. For this reason I think NIO-like APIs don’t really work in the context of ClassLoader.getResource() and similar APIs since they would have to return null for resources that don’t live on the local disk, are zip-compressed (as you point out), etc. which are distinctions the programmer probably doesn’t want to worry about.