• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

loading class files from jar files

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
I am trying to load class files within a jar file. The program extracts and iterates through all the ZipEntrys. For each ZipEntry i obtain the InputStream and read in the contents of each class file in to a byte array. I've made a ClassLoader which relaxes the access rights to the define method which take an array of bytes: Class defineClass(String name, byte[] data, int start, int end);
However only certain classes correctly return a Class objects. The majority of class files i try to read in this manner throws a ClassFormatException with one if the following messages:
Illegal constant pool type
Illegal UTF8 string in constant pool
Illegal constant pool index
Arguments can't fit into locals
any ideas?
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you've probably done sth like: inputStreamInstance.read(byte[] b)
like me...
This is what you should do:
new DataInputStream(inputStreamInstance).readFully(byte[] b)
I don't really know why because the apidoc for both methods looks the same. But it works!
[ May 06, 2004: Message edited by: sander hautvast ]
 
The only thing that kept the leeches off of me was this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic