Skip to content

Instantly share code, notes, and snippets.

@tango238
Created November 11, 2011 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tango238/1356728 to your computer and use it in GitHub Desktop.
Save tango238/1356728 to your computer and use it in GitHub Desktop.
ClassReader
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
public class ClassReader {
public static void main(String[] args) {
if(args.length < 1){
System.out.println("Input a path of the class file for the first argument.");
return;
}
String f = args[0];
InputStream input = null;
try {
input = new BufferedInputStream(new FileInputStream(new File(f)));
System.out.print(paddingRight("Binary", 8));
System.out.println("|Hex");
System.out.println("------------");
int c;
while ((c = input.read()) != -1) {
System.out.print(String.format("%08d", Integer.parseInt(Integer.toBinaryString(c))));
System.out.print(" ");
System.out.print(Integer.toHexString(c).toUpperCase());
System.out.println("");
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static String paddingRight(String s, int n) {
return String.format("%1$-" + n + "s", s);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment