Last active
May 17, 2017 14:15
-
-
Save swthomas55/af8612fb6c9dd30d23cb36bc5c937fc6 to your computer and use it in GitHub Desktop.
Detect corrupted jar files. Eclipse Maven plugin seems prone to creating these.
This file contains hidden or 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
import java.util.jar.JarFile; | |
import java.io.File; | |
/** | |
* List corrupted Jar files. | |
* <p> | |
* Usage: java JarTest file ... | |
* <p> | |
* Prints the name and a message for each corrupted file. | |
* <p> | |
* At the end prints the number of good files scanned and the number of bad files found. | |
*/ | |
public class JarTest { | |
public static void main(String[] args) { | |
if(args.length < 1) { | |
System.err.println("need jar file"); | |
return; | |
} | |
int goodCount = 0; | |
int badCount = 0; | |
for (String pathname: args) { | |
try (JarFile file = new JarFile(new File(pathname))) { | |
file.getManifest(); | |
file.stream().map(e -> true); | |
// System.out.println(pathname + " OK"); | |
goodCount++; | |
} catch(Exception ex) { | |
System.out.println(pathname + " " + ex.getMessage()); | |
badCount++; | |
// ex.printStackTrace(); | |
} | |
} | |
System.out.printf("Good: %d\nBad: %d\n", goodCount, badCount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I run this as follows:
Typical output when there are no problems is below (with two runs because xargs decided to split the file list into two groups):