Serializing in-memory class

Dear all,
Given that I have a user defined class loaded in the VM. If I no longer have access to the .java or .class files, how can I get a serialised version of the class?
I am doing the following:
Class clazz = MyClass.class;
File file = new File("c:\\MyClass.class");
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
oos.writeObject(clazz);
oos.flush();
oos.close();
But when I try to execute the resulting MyClass.class file, I get a bad magic number exception. I think this has something to do with the class checksum value at the start of a valid class file. I am using j2sdk v1.4.
What is the best approach to writing the in-memory class to a file, or better still, to a byte array?
Thanks
Raj

I'm guessing you can't, but if you could it probably would be
ClassLoader.getResourceAsStream()

Similar Messages

  • What is an in-memory class in java.

    what is an in-memory class in java. Please explain me about it and even give a sample code if possible.
    thanks in advance.

    what is an in-memory class in java. Please explain me
    about it and even give a sample code if possible.
    thanks in advance.In what context was this question asked?

  • Access jar file from in-memory classes...

    I have some classes that I compile to memory and everything works fine until one class that must access some external jar files. I have been unable to access those jar files from disk after trying every suggestion using URLClassLoader. I even tried someone's example to hack the SystemClassLoader which properly adds the jar file paths, but still they can't be seen. The only way it works is if I put the files in the jdk/jre/lib/ext directory. Then everything works fine. There must be a way to load the jar files in memory as well as the class files so they can be accessible. Has anyone done anything like this? Is it possible? Even though the class files are in memory, why would the jar files not be seen even when they are added to the same URLClassLoader's URL's. Thanks.

    Sorry that wasn't clear. What I mean is that the classes are compiled to byte code directly to memory and no physical .class file is created. Yes, I'm using my own ClassLoader that extends URLClassLoader and I'm setting the parent to ClassLoader.getSystemClassLoader(). I also should mention that I'm doing this inside a Netbeans module that is part of a Netbeans Platform application. I don't know why that should matter though, since I'm trying to do everything in memory without creating the physical files. Thanks.

  • Serializing applet - Listener Classes

    I have a Frame which has a Inner Listener Class which extends KeyAdapter. When I try serializing this Frame using writeObject( Object ) It gives a non-serializble exception on the inner class . Are Inner Classes Serializable. My Inner Class looks as follows
    public class myListener extends KeyAdapter
    public void KeyPressed...
    I get an Exception - myListener not Serializable

    Inner classes exist to avoid cluttering the top-level name space, for their anonymity when no name is required and so forth. If they are member inner classes then they are tied to a given enclosing instance at creation time and must be created in a member context of their enclosing class (or subclass). There is no relation between an inner class and its encloser as far as their class or interface inheritance is concerned, so if you serialise an enclosing class then its inner classes must implement serializable also.
    Hope that helps

  • Serial Port Communication Class

    Hi
    Does anyone know if there is a java class doing serial port communication using RS485 4 wireport.
    Thanks

    There's the Java Communications API that does serial port communication. Don't know whether it handles whatever it was you said.

  • Serializing object of class implementing Singleton Pattern

    hi ,
    if i've a object of a singleton pattern based class and i seriailize that and when i'm desrializing that, i 'll get the object back, but on calling getInstance() method for my singleton class, it will agian call constructor because for the class's static object reference is null, i need to avoid this, for this i've written a setInstance method, which sets the Singleton class's static refernce to the object i desialized, which is fine, but it defeats the singleton pattern
    can anybody suggest me some other way of achieving this...

    If you are trying to deserialize a Singleton implement the Object readResolve() method.
    http://java.sun.com/javase/6/docs/platform/serialization/spec/input.html#5903
    ~Ryan

  • CX_SHM_EXTERNAL_REFERENCE exc. when passing Class instance to Shared memory

    Hi all,
    when setting up the writing to a shared memory (using the SHMA and SHMM transactions), we get an exception mentioning CX_SHM_EXTERNAL_REFERENCE
    This problem is raised because we are trying to move an instantiated class from the calling development to the Shared memory class.
    Therefore, this exception is raised, the sap standard documentation tells me:
    "There are still references from the current area instance version to a different area instance of the shared objects memory, or to the internal session."
    How can we work around this problem, I really want to pass the instantiated class to the Shared memory?
    Thanks in advance for any help,
    Pascal Decock

    My problem is that I would like to embed a Standard SAP class into this shared memory.
    Therefore, I'm obliged to accept the 'Create object' references that are written in standard SAP code.
    That also means that it is impossible to include an instantiated SAP class into a shared object memory?

  • Treo 680 sdhc class 6 memory card

    Hi friends,
    i would to know if treo 680, firmware 2.12 row, is compatible with 16GB sdhc memory class 6.
    thanks

    No, unfortunately.  Please check this list for maximum SD card sizes for various Palm devices:
    http://h30434.www3.hp.com/t5/Palm-OS-WinMo-Hardwar​e-and-Software/Maximum-quot-Tested-quot-Expansion-​...
    smkranz
    I am a volunteer, and not an HP employee.
    Palm OS ∙ webOS ∙ Android

  • Object serialized Problem

    Hi there,
    I got one window mapped to a object ( say ObjectA ). The window
    contains textbox, droplist. I then serialized the object (ObjectA) to a
    file and read it back to memory. Everything seems fine except the droplist
    shown the wrong data.
    e.g. The droplist map to a listelement having objects ( say
    Object1,Object2,Object3).
    The ObjectA has value Object3.
    After writeserialized and readserialized the window shown Object1 in
    the droplist rather than Object3. In the debugger, I can tell the ObjectA
    has value Object3. But after displaying the window, the value in ObjectA
    changed to Object1 same as the droplist.
    Any ideal what's going on ?
    Any help is welcome!
    Kelvin
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

    Yes, I know that I cannot serialized a window class. But ObjectA is not a
    window class. It is only a object. I have a window ( says WindowA ) which
    mapped to ObjectA. Can I serialized objectA ??
    Kelvin
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

  • E3631A IVI class driver can not enable power supply three channel outputs at same time

    Hallo,
    with E3631A IVI class driver i am trying to enable all the channels at the same time,The problem is that class driver supports only Channel Switching between three Channel,i find in this Forums this Discussion 
    http://forums.ni.com/t5/Instrument-Control-GPIB-Serial/E3631A-IVI-class-driver-cannot-enable-power-s...
    is it possible to enable all outputs at same time  that I modify the source code and recompile the drivers,but it is complicated for me.
     Is there a another easy way to solve this problem??
    Would appreciate if someone who has worked on it suggest a method appropriately. Thanks!
    Note:Labview 2009 sp1

    You'll either have to modify yourself, ask the poster in that other thread for it, or use the LabVIEW driver.

  • Where classes should be stored?

    Hi
    im developing a chat program based on RMI.
    the chat client program contains a list of clients and a connected id panel with their details( nickname,age,image e.g) , so whenever I move the list highlight on each client the id panel change with the highlighted client information.
    As you see I need to make up a cash memory class in the client program which stores the clients information in order to provide a smooth slider action of the id panel.
    Since I use RMI I wonder if I need to make this cash memory object under the client or under the server?
    Do the RMI registry server actually downloads the remote object to the client computer?
    thanks

    o If you think the clients can get that list fast
    enough from the server to support the screen, then you
    don't need a cache.Don�t you think that I refer this sketchy question to be considered with the answered expert?
    Im developing a chat program with lots of gui states. the server is a remote object , I store the client�s info and image in a storage object on the server , my client need this storage elements to be available and fast as it was a local object. I ask if I should put this storage object in the server as a remote remote object or should I copy it to the client itself in order to provides faster performance. ?
    The registry does not do any downloading of anything
    except a reference to a server (when the server is
    looked up).
    The client then uses that reference to make calls on
    server methods. Those calls execute on the server
    computer.What happens if the remote server has to store a real-time object ( object which change as Hashtable) ?
    thanks

  • TSV_TNEW_PAGE_ALLOC_FAILED Shortdump , memory issue

    Hello,
    We are facing one issue of Memory dump for one of the Background Job. The Job is fetching a very huge data and it is failing with the shortdump TSV_TNEW_PAGE_ALLOC_FAILED. I have asked application user to brake the variant of period and now he is running job for 1 single day. But since the amount of data volume is so huge, it is not going thru.
    ~
    The short dump gives following information about memory parameter value:
    The amount of storage space (in bytes) filled at termination time was:
    Roll area...................... 6225552
    Extended memory (EM)........... 1001392792
    Assigned memory (HEAP)......... 2998638656
    Short area..................... " "
    Paging area.................... 24576
    Maximum address space.......... 18446744048641535328
    ~
    The termination occurred in line 1009 of the source code of the (Include)
    1009 -> SELECT * FROM .............
    ~
    Instance Profile Memory parameter values :
    rdisp/ROLL_SHM                              8000
    rdisp/ROLL_MAXFS                            16384
    ztta/roll_area                              6500000
    ztta/roll_first                             1
    ztta/roll_extension                         1000000000
    abap/heaplimit                              20000000
    abap/heap_area_nondia                       3000000000
    abap/heap_area_dia                          3000000000
    abap/heap_area_total                        6000000000
    ~
    Please note that once we got the dump "SYSTEM_IMODE_TOO_LARGE" and we have set the abap/max_imode = four_gb.
    ~
    Can any one help me to resolve this error ? how much memory I can assign ? How to calculate memory available and how to calculate memory required ?
    The job is very important from business point of view and do not have time to optimize the code as of now.
    Any help will be higly appreciated.
    Thanks
    Best Regards,
    Basis CK

    Hi Markus,
    I have gone tru the SAP note you have recommanded. Actually our requirement is that this job is very urgent from business point of view and code optimization will take time as we need to first test in sandbox and then the production. Looking at the scenario, I have decided with this approach :
    <b>Step 1 -></b> Remove parameter abap/max_imode  = four_gb from instance profile as this parameter is not required.
    Please refer note SAP note 548845 - Internal modes users more than 2 GB. According to this note "As of SAP_BASIS 6.20 Support Package 38 and SAP_BASIS 6.40, you do no longer require the profile parameter. Therefore, delete this parameter from the profile; otherwise there is an upper limit of 4 GB."
    (Here I assume that by removing the parameter abap/max_imode, it can go beyound 4GB)
    <b>Step 2 -></b> Increase the memory dyanimcally thru RSMEMORY program for that application server and run the Background Job to make it finish successfully.
    RSMEMORY Parameter is showing following value. <b>Is it possible for you to recommand how much we can increase the memory ?</b>*
    Result of RSMEMORY
    ~~~~~~~~~~~~~~~~~
    Quota Dialog
    Step       Memory class           Size [bytes]
      1                               1
      2               1               1000000000
      3                               6500000
      4               2               3000000000
      5
    Memory classes: ROLL(0) EM(1) HEAP(2)
        1                               6500000
        2               2               3000000000
        3               1               1000000000
        4
        5
    Memory classes: ROLL(0) EM(1) HEAP(2)
      abap/heap area dia:      3000000000
      abap/heap area nondia:   3000000000
      abap/heap area total:    6000000000
      em/stat log timeout:     600
      em/stat log size MB:     20
    Any help  will be highly appreciated.
    Thanks
    Best Regards,
    Basis

  • Want to create sequence at class level  row_number , DENSE_RANK() , rank(),

    Dear All,
    I want to create serial no at class level please check my query , i have already try , row_number , DENSE_RANK() , rank(), it shows 1
    Please guie .
    Regards
    SELECT
    distinct
    cla.R_Description,
    cla.N_Description,
    period.period_name,
    cla.BRANCH,
    cla.CLASS_NAME,
    cla.CLASS_NAME CLASS_NAME_SEQ,
    DENSE_RANK() OVER (partition by cla.R_Description order by cla.CLASS_NAME) CLASS_NAME_desk,
    RANK() OVER (partition by cla.CLASS_NAME order by cla.CLASS_NAME) CLASS_NAME_rank,
    st.ACCOUNT_NUMBER,
    st.PARTY_NAME,
    decode(ASCII(substr(site.attribute13,length(site.attribute13),length(site.attribute13)-1)),13,
    substr(site.attribute13,1,length(site.attribute13)-1),site.attribute13) FATHER,
    pay.amount_due_original,
    trx.trx_number challan_no,
    ST.SECTION,
    pay.amount_due_remaining,
    TO_NUMBER(trx.attribute3) Concession,
    ARREAR.DUE_AMOUNT
    FROM
    RA_CUSTOMER_TRX_ALL TRX,
    student_city_school_all st,
    class_v_table cla,
    bill_period period,
    ar_payment_schedules_all pay,
    HZ_CUST_SITE_USES_ALL SITE_USE,
    HZ_CUST_ACCT_SITES_ALL SITE,
    --branch_network_region_link br,
    ( SELECT BILL_TO_CUSTOMER_ID,SUM(DUE_AMOUNT) DUE_AMOUNT FROM ARREARS_STUDENT WHERE PERIOD_START_DATE < nvl(:P_START_DATE,PERIOD_START_DATE)
    --AND
    -- ORG_ID=NVL( :P_ORG_ID , ORG_ID )
    GROUP BY BILL_TO_CUSTOMER_ID
    ) ARREAR
    WHERE TRX.ATTRIBUTE_CATEGORY='Periodic Billing'
    AND trx.attribute2=cla.Fee_Structure_Id
    AND trx.bill_to_customer_id=st.CUST_ACCOUNT_ID
    AND TRX.BILL_TO_SITE_USE_ID=SITE_USE.SITE_USE_ID
    AND SITE_USE.CUST_ACCT_SITE_ID=SITE.CUST_ACCT_SITE_ID
    AND TRX.BILL_TO_CUSTOMER_ID=ARREAR.BILL_TO_CUSTOMER_ID(+)
    AND trx.org_id=nvl(:p_org_id,trx.org_id)
    AND trx.attribute1=period.period_id
    -- AND period.period_id=:P_PERIOD_ID
    AND trx.customer_trx_id=pay.customer_trx_id
    -- AND cla.branch=nvl(:P_BRANCH,cla.branch)
    -- AND CLA.CLASS_NAME=NVL(:P_CLASS,CLA.CLASS_NAME)
    -- AND cla.N_Description LIKE '%KAPCO%'
    -- and (cla.CLASS_NAME like '%kapco%' or cla.CLASS_NAME like '%kapco%' )
    --&P_WHERE
    ORDER BY CLA.CLASS_NAME, ST.SECTION,
    ST.ACCOUNT_NUMBER

    Please have the decency to format your code and put it in between delimiters.
    Also provide create table statements and some test data along with some output that your expecting to see.
    Finally you have had 18 posts and 15 are unresolved. Could you please take the time to mark those as answered
    or we will assume that it is a waste of time helping you as our answers aren't helpful to you.
    All the above is explained clearly in the FAQ
    SQL and PL/SQL FAQ
    Edited by: Paul Horth on 05-Mar-2012 23:55                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Dynamic Java bean classes for XSD using JAVA (not any external batch or sh)

    Hi,
    How can we generate dynamic Java bean classes for XSD (dynamically support All XSD at runtime)?
    Note: - Through java code via only needs to generate this process. (Not using any xjc.bat or xjc.sh from JAXB).
    Thanks

    Muthu wrote:
    How can we generate dynamic Java bean classes for XSD (dynamically support All XSD at runtime)?
    Pretty sure you can't. Probably can do a lot of them with years of work.
    And can probably can do a resonable subset suitable for the business at hand with only a moderate effort.
    Note: - Through java code via only needs to generate this process. (Not using any xjc.bat or xjc.sh from JAXB).The Sun jdk, not jre, comes with the java compiler as part of it. You can create in memory class (I believe in memory) based on java code you create.
    I believe BCEL alllows the same thing (in memory) but you start with byte codes.
    You could just create a dynamic meta data solution as well, via maps and generic methods. Not as fast though.

  • Registering class - what does it mean?

    In one book dealing with JDBC there's statement like: "Whenever a driver is loaded into memory
    Class.forName("org.gjt.mm.mysql.Driver")
    it is registered as an available driver with the
    java.sql.DriverManager
    class".
    I have to say that I'm not newbie in database/JDBC programming and that I already created dozens of programs and web applications working with databases using DriverManager/DataSource approaches but now I'd like to understand what's really going on in the background with driver class.
    When you say "driver is registered" what does it really mean; what is registered and where?, how it is registered?, is it registered somewhere as ActiveX/COM component in Windows registry?

    hi sbrbot,
    There has been lot of confusion in people who try to get deep into what the books are telling. let me tell you what i could understand from analysing the informations and specifications ....
    when u call Class.forName with the driver class as the argument.., u instantiate a class of the driver.. like org.gjit.mm.mysql.Driver.. This class will contain some mechanism.., usually a static method that will call the java.sql.DriverManager.registerDriver(DriverClass) method.. this method needs the driver class as argument.. u can see it in the java sdk source code..
    The DriverManager now gets a handle to the driver class instance and whatit does can be seen from the foll. code ..in the java.sql.DriverManager class...
        public static synchronized void registerDriver(java.sql.Driver driver)
         throws SQLException {
         if (!initialized) {
             initialize();
         DriverInfo di = new DriverInfo();
         di.driver = driver;
         di.driverClass = driver.getClass();
         di.driverClassName = di.driverClass.getName();
         drivers.addElement(di);
         println("registerDriver: " + di);
        }for your information.. if u are again doubtful abt something.. see the foll. code part tooo again from java.sql.DriverManager
    // DriverInfo is a package-private support class.
    class DriverInfo {
        Driver         driver;
        Class          driverClass;
        String         driverClassName;
        public String toString() {
         return ("driver[className=" + driverClassName + "," + driver + "]");
        }So i hope u now know how the DriverManager class stores the information about the drivers that are available.. :-D
    Hope that was of some help.. do correct me if my concepts are wrong.
    cheers,
    -Jer

Maybe you are looking for