blob: 14ae58ab166966a12665d65dfeaed7906c4f1b30 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/* Listing2001.java */
import java.io.*;
class ClassFileReader
{
private RandomAccessFile f;
public ClassFileReader(String name)
throws IOException
{
if (!name.endsWith(".class")) {
name += ".class";
}
f = new RandomAccessFile(name,"r");
}
public void close()
{
if (f != null) {
try {
f.close();
} catch (IOException e) {
//nichts
}
}
}
public void printSignature()
throws IOException
{
String ret = "";
int b;
f.seek(0);
for (int i=0; i<4; ++i) {
b = f.read();
ret += (char)(b/16+'A'-10);
ret += (char)(b%16+'A'-10);
}
System.out.println(
"Signatur...... "+
ret
);
}
public void printVersion()
throws IOException
{
int minor, major;
f.seek(4);
minor = f.readShort();
major = f.readShort();
System.out.println(
"Version....... "+
major+"."+minor
);
}
}
public class Listing2001
{
public static void main(String[] args)
{
ClassFileReader f;
try {
f = new ClassFileReader("Listing2001");
f.printSignature();
f.printVersion();
} catch (IOException e) {
System.out.println(e.toString());
}
}
}
|