|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--net.yagga.util.MetaJarResources
Class that implements reading data from a Jar file. The Jar file can be in the class path or included in the jar file we are executing!. This class reads bytes arrays for a given entry in a given jar file. If the case is the simple one:
./Test.class ./net/yagga/util/MetaJarResource.class ./sample.jar +- icon.gifone can read data from the file "sample.jar" via this class, in the main method of the Test class. This case is more or less the same as seen in JavaWorld's tip 49 (JarResource). The class reads the specified Jar entry and returns the byte array. The trick is a bit more complicated if we are in such a case:
./all.jar
+- Test.class
+- net/yagga/util/MetaJarResource.class
+- sample.jar
+- icon.gif
If we execute the Jar file "all.jar" Test class cannot find a resource inside the sample.jar file using the
usual trick in JArResource. We must extract in a JarResource way from the top level Jar (all.jar) the entry for
sample.jar, then extracting from it the entry from icon.gif.
I have not found a simple way to do this:
| Field Summary | |
private boolean |
executingFromJar
|
private java.util.Hashtable |
htSizes
|
private java.lang.String |
jarFile
|
private java.lang.String |
jarJarFile
|
private java.util.Hashtable |
metaJarContent
|
private java.util.jar.Manifest |
metaManifest
|
| Constructor Summary | |
MetaJarResources(java.lang.String jFile)
Construct a MetaJarResources file, a jar file that can be in the class path (simple case) or enclosed in the same jar file that is executing now. |
|
| Method Summary | |
java.lang.String |
getActualJarName()
Return the actual jar name. |
byte[] |
getBytes(java.lang.String entryName)
Method that actually reads raw bytes. this method reads in the appropriate way raw bytes for the given entry. |
java.util.jar.Manifest |
getManifest()
Return the manifest for the jar file. |
private java.util.jar.JarInputStream |
getTopJIS()
Get top level JAR input stream. |
private void |
initTopJarSizes()
Read the sizes for top-level JAR file. |
private java.io.InputStream |
openResource(java.lang.String filename)
open a stream from the environment. |
private byte[] |
readBytesFromTopJar(java.lang.String entryName)
Reads bytes from Top level Jar file. |
private void |
readJarInJar()
Reads in self contained jar file. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
private java.util.Hashtable htSizes
private java.lang.String jarFile
private boolean executingFromJar
private java.util.Hashtable metaJarContent
private java.lang.String jarJarFile
private java.util.jar.Manifest metaManifest
| Constructor Detail |
public MetaJarResources(java.lang.String jFile)
jFile - the name of the Jar file we want to read resources from.| Method Detail |
public byte[] getBytes(java.lang.String entryName)
entryName - a String containing the full qualified name of the entryi in the jar file
the name must be given in the usual directory/filename format, for examplepublic java.util.jar.Manifest getManifest()
public java.lang.String getActualJarName()
private void readJarInJar()
FOO.jar
+- Installer.class
+- net/yagga/util/MetaJarResources.class
+- PACK1.jar
+- ClassIWantToInvoke.class <===
private void initTopJarSizes()
private byte[] readBytesFromTopJar(java.lang.String entryName)
entryName - a String containig the top-level entry we eant to read. Ther entry mustbe given in the
usual directory/filename formatprivate java.util.jar.JarInputStream getTopJIS()
private java.io.InputStream openResource(java.lang.String filename)
filename - the filename of the resource we want to read
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||