Last change
on this file since 15356 was
15356,
checked in by Mark Evenson, 3 years ago
|
abcl-introspect: add convenience method to read class files
e.g.
(abcl-introspect/jvm/tools/javap:disassemble-class-bytes
(ext:read-class
"~work/abcl/build/classes/org/armedbear/lisp/run_program_60.cls"))
TODO: shorten into generic method
|
File size:
981 bytes
|
Line | |
---|
1 | (in-package :extensions) |
---|
2 | |
---|
3 | ;;; TODO: submit upstream patch to <cffi/src/cffi-abcl.lisp> for removal |
---|
4 | (defun write-class (class-bytes pathname) |
---|
5 | "Write the Java byte[] array CLASS-BYTES to PATHNAME." |
---|
6 | (with-open-file (stream pathname |
---|
7 | :direction :output |
---|
8 | :element-type '(unsigned-byte 8)) |
---|
9 | (dotimes (i (java:jarray-length class-bytes)) |
---|
10 | (write-byte (java:jarray-ref class-bytes i) stream)))) |
---|
11 | |
---|
12 | (defun read-class (pathname) |
---|
13 | "Read the file at PATHNAME as a Java byte[] array" |
---|
14 | (with-open-file (stream pathname |
---|
15 | :direction :input |
---|
16 | :element-type '(unsigned-byte 8)) |
---|
17 | (let* ((length |
---|
18 | (file-length stream)) |
---|
19 | (array |
---|
20 | (make-array length :element-type '(unsigned-byte 8)))) |
---|
21 | (read-sequence array stream :end length) |
---|
22 | (java:jnew-array-from-array "byte" array)))) |
---|
23 | |
---|
24 | |
---|
25 | (export '(write-class |
---|
26 | read-class) |
---|
27 | :extensions) |
---|
28 | |
---|
Note: See
TracBrowser
for help on using the repository browser.