/* * [JarLook.java] * * Summary: Display a sorted list of files inside a jar with package names. * * Copyright: (c) 2006-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2006-01-16 initial version * 1.1 2006-01-16 * 1.2 2006-03-06 reformat with IntelliJ, add Javadoc */ package com.mindprod.jarlook; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import static java.lang.System.*; /** * Display a sorted list of files inside a jar with package names. *

* Also works on zip created with Java, e.g. ANT zip. * Display uses / in package names. * * @author Roedy Green, Canadian Mind Products * @version 1.2 2006-03-06 * @since 2006-01-16 */ public final class JarLook { private static final int FIRST_COPYRIGHT_YEAR = 2006; /** * undisplayed copyright notice */ private static final String EMBEDDED_COPYRIGHT = "Copyright: (c) 2006-2017 Roedy Green, Canadian Mind Products, http://mindprod.com"; private static final String RELEASE_DATE = "2006-03-06"; private static final String USAGE = "\njava.exe -jar jarlook.jar jartoexamine.jar"; /** * embedded version string. */ private static final String VERSION_STRING = "1.2"; /** * Main reads jar and display sorted list of files in it. * * @param args jar name to display. */ public static void main( String[] args ) { if ( args.length != 1 ) { err.println( USAGE ); System.exit( 1 ); } ArrayList names = new ArrayList<>( 100 ); String jarFile = args[ 0 ]; ZipFile zip = null; try { // O P E N zip = new ZipFile( new File( jarFile ), ZipFile.OPEN_READ ); } catch ( IOException e ) { err.println( "Problems opening file " + args[ 0 ] ); System.exit( 1 ); } try { // R E A D // for each entry in jar // can't use for:each, only works with Iterator not Enumeration. for ( Enumeration e = zip.entries(); e.hasMoreElements(); ) { ZipEntry entry = ( ZipEntry ) e.nextElement(); names.add( entry.getName() ); } // end for // C L O S E zip.close(); } catch ( IOException e ) { err.println( "Problems processing file " + args[ 0 ] ); System.exit( 1 ); } // S O R T // case-sensitive alpha sort Collections.sort( names ); // D I S P L A Y for ( String name : names ) { out.println( name ); } } // end main } // end JarLook