summaryrefslogtreecommitdiff
path: root/src/fjbg/ch/epfl/lamp/fjbg/JOtherAttribute.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/fjbg/ch/epfl/lamp/fjbg/JOtherAttribute.java')
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JOtherAttribute.java30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JOtherAttribute.java b/src/fjbg/ch/epfl/lamp/fjbg/JOtherAttribute.java
index 7a64f91ee9..dcee9c2c13 100644
--- a/src/fjbg/ch/epfl/lamp/fjbg/JOtherAttribute.java
+++ b/src/fjbg/ch/epfl/lamp/fjbg/JOtherAttribute.java
@@ -1,11 +1,16 @@
+/* FJBG -- Fast Java Bytecode Generator
+ * Copyright 2002-2011 LAMP/EPFL
+ * @author Michel Schinz
+ */
package ch.epfl.lamp.fjbg;
-import java.io.*;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
/**
- * Attributes which are unknown to the JVM (or at least to this
- * library).
+ * Attributes which are unknown to the JVM (or at least to this library).
*
* @author Michel Schinz
* @version 1.0
@@ -45,9 +50,28 @@ public class JOtherAttribute extends JAttribute {
public String getName() { return name; }
+ // Follows javap output format for user-defined attributes.
+ /*@Override*/ public String toString() {
+ StringBuffer buf = new StringBuffer(" ");
+ buf.append(name);
+ buf.append(": length = 0x");
+ buf.append(Integer.toHexString(length).toUpperCase());
+ for (int i = 0; i < length; ++i) {
+ if (i % 16 == 0) buf.append("\n ");
+ buf.append(hexString(contents[i]));
+ buf.append(" ");
+ }
+ buf.append("\n");
+ return buf.toString();
+ }
+
protected int getSize() { return length; }
protected void writeContentsTo(DataOutputStream stream) throws IOException {
stream.write(contents, 0, length);
}
+
+ private static final String hexString(int i) {
+ return ((0 <= i && i < 16) ? "0" : "")+Integer.toHexString(i).toUpperCase();
+ }
}