Skip to content

Commit

Permalink
#4 Add raw data for number values
Browse files Browse the repository at this point in the history
  • Loading branch information
amosshi committed Sep 1, 2019
1 parent 6c4c9b4 commit 59c6ed5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,20 @@
*/
public class ConstantDoubleInfo extends CPInfo {

public static final int RAW_DATA_SIZE = 8;
public static final int LENGTH = 9;

//private u4 high_bytes;
//private u4 low_bytes;
public final byte[] rawData;
public final double doubleValue;

ConstantDoubleInfo(final PosDataInputStream posDataInputStream) throws IOException {
super(CPInfo.ConstantType.CONSTANT_Double.tag, true, ClassFile.Version.Format_45_3, JavaSEVersion.Version_1_0_2);
super.startPos = posDataInputStream.getPos() - 1;
super.length = LENGTH;

this.rawData = posDataInputStream.getBuf(posDataInputStream.getPos(), RAW_DATA_SIZE);
this.doubleValue = posDataInputStream.readDouble();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@
*/
public class ConstantFloatInfo extends CPInfo {

public static final int RAW_DATA_SIZE = 4;
public static final int LENGTH = 5;
public final byte[] rawData;
public final Float floatValue;

ConstantFloatInfo(final PosDataInputStream posDataInputStream) throws IOException {
super(CPInfo.ConstantType.CONSTANT_Float.tag, true, ClassFile.Version.Format_45_3, JavaSEVersion.Version_1_0_2);
super.startPos = posDataInputStream.getPos() - 1;
super.length = LENGTH;

this.rawData = posDataInputStream.getBuf(posDataInputStream.getPos(), RAW_DATA_SIZE);
this.floatValue = posDataInputStream.readFloat();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@
*/
public class ConstantIntegerInfo extends CPInfo {

public static final int RAW_DATA_SIZE = 4;
public static final int LENGTH = 5;
public final byte[] rawData;
public final int integerValue;

ConstantIntegerInfo(final PosDataInputStream posDataInputStream) throws IOException {
super(CPInfo.ConstantType.CONSTANT_Integer.tag, true, ClassFile.Version.Format_45_3, JavaSEVersion.Version_1_0_2);
super.startPos = posDataInputStream.getPos() - 1;
super.length = LENGTH;

this.rawData = posDataInputStream.getBuf(posDataInputStream.getPos(), RAW_DATA_SIZE);
this.integerValue = posDataInputStream.readInt();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@
*/
public class ConstantLongInfo extends CPInfo {

public static final int RAW_DATA_SIZE = 8;
public static final int LENGTH = 9;

//private u4 high_bytes;
//private u4 low_bytes;
public final byte[] rawData;
public final long longValue;

ConstantLongInfo(final PosDataInputStream posDataInputStream) throws IOException {
super(CPInfo.ConstantType.CONSTANT_Long.tag, true, ClassFile.Version.Format_45_3, JavaSEVersion.Version_1_0_2);
super.startPos = posDataInputStream.getPos() - 1;
super.length = LENGTH;

this.rawData = posDataInputStream.getBuf(posDataInputStream.getPos(), RAW_DATA_SIZE);
this.longValue = posDataInputStream.readLong();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.freeinternals.javaclassviewer.ui;

import javax.swing.tree.DefaultMutableTreeNode;
import org.freeinternals.commonlib.core.BytesTool;
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
import org.freeinternals.format.classfile.constant.CPInfo;
import org.freeinternals.format.classfile.ClassFile;
Expand Down Expand Up @@ -112,15 +113,15 @@ private void generateTreeNode(final DefaultMutableTreeNode rootNode, final Const
rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
integerInfo.getStartPos() + 1,
4,
"bytes: " + integerInfo.integerValue
"bytes: " + integerInfo.integerValue + " - " + BytesTool.getByteDataHexView(integerInfo.rawData)
)));
}

private void generateTreeNode(final DefaultMutableTreeNode rootNode, final ConstantFloatInfo floatInfo) {
rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
floatInfo.getStartPos() + 1,
4,
"bytes: " + floatInfo.floatValue
"bytes: " + floatInfo.floatValue + " - " + BytesTool.getByteDataHexView(floatInfo.rawData)
)));
}

Expand All @@ -130,7 +131,7 @@ private void generateTreeNode(final DefaultMutableTreeNode rootNode, final Const
rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
startPos + 1,
4,
"high_bytes - value: " + longInfo.longValue
"high_bytes - value: " + longInfo.longValue + " - " + BytesTool.getByteDataHexView(longInfo.rawData)
)));
rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
startPos + 5,
Expand All @@ -145,7 +146,7 @@ private void generateTreeNode(final DefaultMutableTreeNode rootNode, final Const
rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
startPos + 1,
4,
"high_bytes - value: " + doubleInfo.doubleValue
"high_bytes - value: " + doubleInfo.doubleValue + " - " + BytesTool.getByteDataHexView(doubleInfo.rawData)
)));
rootNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
startPos + 5,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Supported Formats
Build the Source Code
=========================

We request the maven command line `mvn` has been instaled.
We require the maven command line `mvn` has been installed.

- `./build.sh` Build the source code and create the deploy packages

0 comments on commit 59c6ed5

Please sign in to comment.