Skip to content

Commit 4baca3f

Browse files
authored
Update example
1 parent d71abfa commit 4baca3f

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

README.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,32 @@ classFile.methods.forEach(md => {
3737
});
3838
```
3939

40-
Print all method names (browser)
40+
Usage Example (browser): print all method names
4141
```html
42-
<script src="https://cdn.rawgit.com/leonardosnt/java-class-tools/75091de36bb02714c276c885ff4ec1bd818ee2ea/dist/java-class-tools.min.js"></script>
42+
<script src="https://cdn.jsdelivr.net/npm/java-class-tools@latest/dist/java-class-tools.min.js"></script>
4343
<script>
44-
const reader = new JavaClassTools.JavaClassFileReader();
45-
const classFile = reader.read(CLASS_FILE_DATA);
44+
fetch('https://gist.githubusercontent.com/leonardosnt/69207dd9bcae55c93ff8fe6546c92eef/raw/fa008a94f9bc208cfa593cf568f0c504e3b30413/Class.class')
45+
.then(r => r.arrayBuffer())
46+
.then(printAllMethods);
47+
48+
function printAllMethods(classData) {
49+
const reader = new JavaClassTools.JavaClassFileReader();
50+
const classFile = reader.read(classData);
4651
47-
classFile.methods.forEach(md => {
48-
/**
49-
* Method name in constant-pool.
50-
*
51-
* Points to a CONSTANT_Utf8_info structure: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.7
52-
*/
53-
const nameInConstantPool = classFile.constant_pool[md.name_index];
52+
classFile.methods.forEach(md => {
53+
/**
54+
* Method name in constant-pool.
55+
*
56+
* Points to a CONSTANT_Utf8_info structure: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.7
57+
*/
58+
const nameInConstantPool = classFile.constant_pool[md.name_index];
5459
55-
// To string (hacky)
56-
const name = String.fromCharCode.apply(null, nameInConstantPool.bytes);
60+
// To string (hacky)
61+
const name = String.fromCharCode.apply(null, nameInConstantPool.bytes);
5762
58-
console.log(name);
59-
});
63+
console.log(name);
64+
});
65+
}
6066
</script>
6167
```
6268

0 commit comments

Comments
 (0)