-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pending #6, write out a *.txt side file with a summary, and make the …
…JAR executable to dump binary contents readably.
- Loading branch information
Showing
5 changed files
with
113 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package net.java.sezpoz.impl; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.InputStream; | ||
import java.io.ObjectInput; | ||
import java.io.ObjectInputStream; | ||
import java.util.Arrays; | ||
import java.util.Enumeration; | ||
import java.util.jar.JarEntry; | ||
import java.util.jar.JarFile; | ||
|
||
/** CLI utility for inspecting binary SezPoz metadata. */ | ||
public class Inspector { | ||
|
||
private static final byte[] ZIP_MAGIC = {0x50, 0x4b, 0x03, 0x04}; | ||
private static final byte[] SER_MAGIC = {(byte) 0xac, (byte) 0xed, 0x00, 0x05}; | ||
|
||
public static void main(String[] args) throws Exception { | ||
if (args.length == 0) { | ||
System.err.println("Usage: java -jar sezpoz.jar [ something.jar | some.serialized.Annotation ]+"); | ||
} | ||
for (String arg : args) { | ||
System.out.println("--- " + arg); | ||
byte[] magic = new byte[4]; | ||
InputStream is = new FileInputStream(arg); | ||
try { | ||
is.read(magic, 0, 4); | ||
} finally { | ||
is.close(); | ||
} | ||
if (Arrays.equals(magic, ZIP_MAGIC)) { | ||
JarFile jf = new JarFile(arg, false); | ||
try { | ||
Enumeration<JarEntry> entries = jf.entries(); | ||
while (entries.hasMoreElements()) { | ||
JarEntry entry = entries.nextElement(); | ||
String name = entry.getName(); | ||
if (name.startsWith(Indexer6.METAINF_ANNOTATIONS)) { | ||
String annotation = name.substring(Indexer6.METAINF_ANNOTATIONS.length()); | ||
if (annotation.isEmpty() || annotation.endsWith(".txt")) { | ||
continue; | ||
} | ||
System.out.println("# " + annotation); | ||
is = jf.getInputStream(entry); | ||
try { | ||
dump(is); | ||
} finally { | ||
is.close(); | ||
} | ||
} | ||
} | ||
} finally { | ||
jf.close(); | ||
} | ||
} else if (Arrays.equals(magic, SER_MAGIC)) { | ||
is = new FileInputStream(arg); | ||
try { | ||
dump(is); | ||
} finally { | ||
is.close(); | ||
} | ||
} else { | ||
System.err.println("does not look like either a JAR file or a Java serialized file"); | ||
} | ||
} | ||
} | ||
|
||
private static void dump(InputStream is) throws Exception { | ||
ObjectInput oi = new ObjectInputStream(is); | ||
while (true) { | ||
SerAnnotatedElement el = (SerAnnotatedElement) oi.readObject(); | ||
if (el == null) { | ||
break; | ||
} | ||
System.out.println(el); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters