Ignore:
Timestamp:
07/30/20 12:20:16 (3 years ago)
Author:
Mark Evenson
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/contrib/abcl-introspect/util.lisp

    r15282 r15356  
    66  (with-open-file (stream pathname
    77                          :direction :output
    8                           :element-type '(signed-byte 8))
     8                          :element-type '(unsigned-byte 8))
    99    (dotimes (i (java:jarray-length class-bytes))
    1010      (write-byte (java:jarray-ref class-bytes i) stream))))
    1111
    12 (export '(write-class) :extensions)
     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)
    1328
Note: See TracChangeset for help on using the changeset viewer.