diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/hjp5/examples/Listing2001.java | |
| download | Studium-master.tar.gz Studium-master.tar.bz2 | |
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing2001.java')
| -rw-r--r-- | Master/Reference Architectures and Patterns/hjp5/examples/Listing2001.java | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing2001.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2001.java new file mode 100644 index 0000000..14ae58a --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing2001.java @@ -0,0 +1,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());
+ }
+ }
+}
\ No newline at end of file |
