import java.util.jar.*; import java.io.*; import java.util.*; /** * @version 1.0 2002-03-21 * @author Takashi KOBAYASHI */ public class jarscape { public static void main( String[] args ) { File file = new File( args[0] ); if( ! file.exists() ) { System.out.println( args[0] + " not found." ); } else { try { jarscape js = new jarscape( new JarFile( file ), args[0] ); js.printMainAttributes(); js.printFileAttributes(); js.printFileEntries(); } catch( IOException ioe ) { ioe.printStackTrace(); } } } private String filename; private JarFile jar; public jarscape( JarFile jar, String filename ) { this.jar = jar; this.filename = filename; } public void printMainAttributes() throws IOException { Manifest mf = jar.getManifest(); Attributes att = mf.getMainAttributes(); Enumeration enm = jar.entries(); System.out.println( filename + ": Manifest Main Attributes ***********" ); Iterator itl = att.keySet().iterator(); while( itl.hasNext() ) { Attributes.Name name = (Attributes.Name)itl.next(); System.out.println( "key: " + name.toString() + ", value: " + att.getValue( name ) ); } System.out.println(); } public void printFileAttributes() throws IOException { Manifest mf = jar.getManifest(); Attributes att; Enumeration enm = jar.entries(); System.out.println( filename + ": Manifest File Attributes ***********" ); while( enm.hasMoreElements() ) { String str = ( (JarEntry)enm.nextElement() ).getName(); att = mf.getAttributes( str ); if( att == null ) continue; Iterator itl = att.keySet().iterator(); System.out.println( "File Entry: " + str ); while( itl.hasNext() ) { Attributes.Name name = (Attributes.Name)itl.next(); System.out.println( "key: " + name.toString() + ", value: " + att.getValue( name ) ); } } System.out.println(); } public void printFileEntries() throws IOException { Enumeration enm = jar.entries(); System.out.println( filename + ": File entries ***********************" ); while( enm.hasMoreElements() ) System.out.println( ( (JarEntry)enm.nextElement() ).getName() ); } }