Getting the "code" of a class as byte array

Hi!
My problem is the following. My algorithm gets a Class object and it should return the code of the class as byte array.
e.g. public byte [] getTheCode (Class forThisClass);
I found out, that I can get an InputStream for a ressource, so that i can load my own classes like getResourceAsStream("my/package/MyClass.class"), but it should also be possible to get the code of the built-in classes like String, Integer etc.
thanks, Ingo

The real name of String is java.lang.String; perhaps you didn't use the full name.No, that's not the problem. The classloader of java.lang.String is usually the bootstrap class loader, and its Class.getClassLoader() == null.
Class.getClassLoader() explicitly defers to the system class loader (not the bootstrap class loader) if getClassLoader() == null, The system class loader (the thing that looks at CLASSPATH, etc.) cannot load anything from rt.jar.
So basically I think you're sort of SOL, unless you want to check for this condition yourself. I.e. first try your approach (using getResourceAsStream()), and if that returns null, go and open ${java.home}/lib/rt.jar, and walk it on your own.

Similar Messages

  • How to programmatically get the source for a class provided the class name?

    Hello,
    As a quick background, I am providing some tools to potential users of an in-house framework. One is the ability to generate quick prototypes from our existing demo applications. Assume a user downloads our jars and uses them in their project (we are using Eclipse, but that detail should not greatly affect my question). Included in the jars is a demos package that contains ready-to-run classes that serve to exhibit certain functionality. Since many users may just need quick extensions of these demos, I am trying to provide a way for them to be able to create a new project that starts with a copy of the demo class.
    So, the user is provided a list of the existing demos (each one uses a single class). When the user makes their selection, with the knowledge of our framework, I can translate that into what demo class they need (returned as a string of format package.subpack1.subpackn.DemoClassName). What I now want to do is to use that complete class name to get the source (look up the file) for the corresponding class, and copy it into to a new file in their project (the copying into the project can be done easily in Eclipse, so what I need help with is the bolded part). Is there a simple way to get the source given a class path for a class as described above? You may assume the source files are included in the jars for the framework.
    Thanks in advance.

    If there's a file named "package.subpack1.subpackn.DemoClassName.java" in a "demos" directory in the jar, then yes. You'd just use
    InputStream code = getResourceAsStream("/demos.package.subpack1.subpackn.DemoClassName.java");Or if those dots in the name actually separate directory names, i.e. you have a "package" directory under "demos" and a "subpack1" director under that and so on, then:
    InputStream code = getResourceAsStream("/demos/package/subpack1/subpackn/DemoClassName.java");

  • Communication b/n iviews --- Can we get the code for SAP's standard iviews?

    hi All,
    I have a requirement where I have to pass the user input data obtained in a standard iview(provided by sap) to a custom built iview and process it from there.
    If I have to use the EPCF's client data bag for this purpose, I must be able to edit the code which produces the standard iview(provided by sap) which I think is not possible, as we cannot get the code for the standard iviews provided by sap.
    Have anybody come across this kind of issue? If so, can you help me in solving this issue? Is there any workaround for this?
    Any input in this regard will be of great help to me and will be suitably rewarded.
    Thanks & best regds,
    Alagammai.

    hi George,
    Tnx a lot.
    But I have already tried importing par files into NWDS. I am not able to see any source code(like jsp or java)which can be edited. I am able to see only class files.
    Does that mean that the class files are to be decompiled, edited, compiled and then uploaded to the portal?
    best regds,
    alagammai.

  • How can I purchase an iTunes card online and get the code online to purchase apps.

    How can I purchase an iTunes card online and get the code online to purchase apps.

    iTunes Gift Options
    http://support.apple.com/kb/HT2736

  • HT201209 My wife purchased an iTunes gift card for me and I scratched off the back to get the code and when I entered it to redeem it told me that it had already been redeemed what do I do?

    My wife purchased an iTunes gift card for me and I scratched off the back to get the code and when I entered it to redeem it told me that it had already been redeemed what do I do?

    Try Here  >  http://support.apple.com/kb/TS1292
    If no joy...
    Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact
    And there is this...
    http://www.apple.com/hk/en/support/itunes/store/giftcard/

  • HT4009 How long does it take for apple to return with the needed code for in app purchases.  We have a developer working through elance that states he submitted a finalized version last friday to apple and is still waiting to get the code back from Apple?

    We are being told by our elance developer that he is just waiting on apple to return the code for in app purchases with our app.  he says he had to submit a complete version before they would give it to him and that he did that last friday.  Needless to say i don;t beleive him.  Can anyone validate for me the process of getting the code installed into our app and how long it should really take.

    I'd say an average of one week, depending on backlog. Expect two if you are outside the US.
    The outage has caused some lingering effects that seem to be delaying things for some, however.
    Patience is key in all things when it comes to being a developer

  • Getting the name of outer class in an inner class

    Hi,
    I have a private inner class, something like this:
    public class OuterClass extends AnotherClass {
    public OuterClass() {
    supre();
    private class innerClass1 extends SomeotherClass {
    protected void someMethod() {
    // how to get the name of outer class, that is, "OuterClass"
    Can someone please tell me how to get the name of the outer class inside the inner class method?
    Thanks in advance..
    Prasanna

    getClass().getEnclosingClass().getName()But then, you already know it, don't you?

  • Can anyonehelp, i have updated to ios7 which has put a passcode on my ipad, i keep getting the code wrong, i have ne itunes of cloud sync

    can anyonehelp, i have updated to ios7 which has put a passcode on my ipad, i keep getting the code wrong, i have no itunes or cloud sync

    Duncanray10 wrote:
    ...  I keep getting a message stating my ipad needs software to be 10.6.3. ...
    You are misreading it... it is referring to iTunes on your computer...
    Download and Install the Latest version of iTunes onto your computer...
    http://www.apple.com/support/itunes/install/

  • How can i get the code html and css of my form please help me

    how can i get the code html and css of my form

    HI,
    If you like to embed the HTML form in your web page then you will need to obtain the form code from the Distribite/Embed tab. Additional information can be found here: http://forums.adobe.com/docs/DOC-1991
    You will not be able to access/modify the css code or the rest of the form html code.  If you like to view the source of of a HTML page, please use your browser 'view source code' functionality.
    I hope this answer your question,
    Thanks,
    Lucia

  • Can I buy an iTunes voucher and get the code sent straight to my email?

    Can I buy an iTunes voucher and get the code sent straight to my email?

    If the iTunes Store sells gift certificates in your country, yes, but you'll need to provide a credit card issued in that country to make the purchase.
    Regards.

  • How do i redeem a 10.00 gift... when i click redeem i am prompted to download itunes... i already have itunes...how do i get the code... or get past the download

    omg how many times do i have to ask the question...., i am trying to redeem a gift of 10.00.. when i click on redeem it wants me to download itunes... i already have itunes.... how do i get the code.... when it gets this complicated to ask a question it doesnt seem worth it...wass up????

    Redeeming iTunes Gift Cards and content codes
    iTunes 11 for Mac- Redeem an iTunes allowance, gift certificate, or Gift Card
    iTunes 11 for Windows- Redeem an iTunes allowance, gift certificate, or Gift Card
    If you can't redeem your iTunes Gift Card or code

  • I scratched the label off on a £25 gift card and it removed the code. How can I get the code for the card?

    I scratched the label off on a £25 gift card and it removed the code. How can I get the code for the card?

    Click here and request assistance. Gift cards are usually if not always final sale because it would be easy enough for someone dishonest to abuse returns or replacements of them.
    (58640)

  • HOW DO I GET THE CODE? (Upgrade från CS 5.5 to 6.0)

    I am trying to install Adobe CS 6 on my computer. The installation goes fine until I enter my serialnumber. Then I get the message "The serial number is valid, but could not find a qualifying product on this computer." When I search on the Adobe site I find information about a new installation process. It says that I no longer need a serialnumber but a code. The question is HOW DO I GET THE CODE?
    The only thing I got on my purchase is our 7 licenses (volume licenses) is 1 order number and 7 serial numbers.

    Adobe what CS6? We are an Audition U2U forum and can't answer any questions about installation issues at all. Adobe have a free assistance chatline available for this - you need to call that.

  • Dear Sirs , my I phone 4 is limited to some network so i wanna make my I phone free to all networkes all over , how can i get the code to unblock it

    Dear Sirs ,
    my I phone 4 is limited to some network so i wanna make my I phone free to all networkes all over , how can i get the code to unblock it

    There is no "code to unblock it". It can only be unlocked by the carrier it's locked to. Contact them and see if they offer that service and if you qualify.

  • On Maverick my i cloud will not change the verification phone number even though I have change the phone number in apple and on contacts and restarted the computer. Help? I can't get the code necessary to fix the keychain.

    On Maverick my i cloud will not change the verification phone number even though I have change the phone number in apple and on contacts and restarted the computer. Help? I can't get the code necessary to fix the keychain without it.

    You can change the phone number the verification code is sent to from a device or Mac that has your iCloud keychain enabled as follows:
    In iOS 8, tap Settings > iCloud > Keychain > Advanced. In iOS 7, tap Settings > iCloud > Account > Keychain. Make sure the phone number under Verification Number is correct. If not, enter another phone number.
    In OS X Mavericks v10.9, choose Apple () > System Preferences. Click iCloud, then click Account Details. Make sure the phone number under Verification number is correct. If not, enter another phone number.
    If you don't have access to a device or Mac with your iCloud keychain enabled, you'll have to contact Apple support to verify your identity and get assistance making the change: http://www.apple.com/support/icloud/contact/.

Maybe you are looking for

  • Service Order Material Requirement

    Dear SAP consultants Need to check with you guys on this matter. I have a service order with list of components. I would like to do an advance shipment and create a quotation from it. Problem is , once the quotation is created the material requiremen

  • Can't install Adobe Air Applications!

    Installed Adobe Air without problems - but when I try to install any application it will restart my computer before completing the install. Usually gets to the... "Would you like to install desktop icons etc." then I click 'OK' and it reboots my pc.

  • Flash upgrade; 5 year old mac 5; is there a way without being jacked?

    I spent all the money I had on Apple products just 5 years ago spending sixteen thousand dollars on my MAC 5 with all the bells and whistles you can think of. Now, all over the internet there is a growing experience of receiving more and more error m

  • DB Tools Fetch Next Recordset

    I am having trouble iterating through the set of recordsets returned from a query that returns multiple tables.  I am using the DB Tools Fetch Next Recordset.vi in a loop to iterate through recordsets until they have all been processed.  One problem

  • How to generate a report with Courrier font and no horizontal lines?

    Hi guys, In a wizard-generated report, I want to accomplish the following things. 1. Print table data (I'm only printing one column) in a non-proportional font (e.g. Courrier). 2. Suppress the vertical lines that Apex automatically puts in between ea