Created
November 11, 2011 00:21
-
-
Save tango238/1356728 to your computer and use it in GitHub Desktop.
ClassReader
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.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