Module: JavaClass::Dsl::Loader

Included in:
JavaClass, LoadingClasspath, Mixin
Defined in:
lib/javaclass/dsl/loader.rb

Overview

Load the classfiles and create the JavaClassHeader. This module ties together all ClassFile and Classpath modules.

Author

Peter Kofler

Instance Method Summary collapse

Instance Method Details

#disassemble(data) ⇒ Object

Read and disassemble the given class inside data (byte data). Might throw a ClassFile::ClassFormatError if the classfile is not valid. This creates a ClassFile::JavaClassHeader .



35
36
37
# File 'lib/javaclass/dsl/loader.rb', line 35

def disassemble(data)
  ClassFile::JavaClassHeader.new(data)
end

#load_cp(classname, classpath) ⇒ Object

Read and disassemble the given class classname from classpath .



23
24
25
26
27
28
29
30
# File 'lib/javaclass/dsl/loader.rb', line 23

def load_cp(classname, classpath)
  begin
    disassemble(classpath.load_binary(classname))
  rescue ClassFile::ClassFormatError => ex
    ex.add_classname(classname, classpath.to_s)
    raise ex
  end
end

#load_fs(filename) ⇒ Object

Read and disassemble the given class from filename (full file name).



13
14
15
16
17
18
19
20
# File 'lib/javaclass/dsl/loader.rb', line 13

def load_fs(filename)
  begin
    disassemble(File.open(filename, 'rb') { |io| io.read.freeze } )
  rescue ClassFile::ClassFormatError => ex
    ex.add_classname(filename)
    raise ex
  end
end