Skip to Content
author's profile photo Former Member
Former Member

Java object as IResource content

Hi everyone,

I'm stuck. Again. I'm trying to write an object to an

IResource. What i'd like to do is delete the IResource

and then recreate one with the new object as content.

I then want to read this object back in as an object at

some later point. What i have so far for the writing is:


IResource aResource = aResourceFactory.getResource(financeRID, rContext);
aResource.delete();

ICollection ic = (ICollection) aResourceFactory.getResource(baseDirectory, rContext);
IContent content = (IContent) null;
ic.createResource(FINANCE_DATA_FILE, null, content, true);

financeRID is the RID of the file i want to create. I use .delete() to get delete the file and then i use createResource to create it again. Now, i'm not sure how to create the IPropertyMap, so i just pass null and

ignore any error as i don't really need a property map.

Now the object i'm trying to write into this resource

is called FinanceDataType.

How can i write this into the file?

Also for reading it back out again i was thinking of

doing:

IContent ic = aResource.getContent();
ObjectInputStream s = new ObjectInputStream(ic.getInputStream());
FinanceDataType dfd = (FinanceDataType) s.readObject();
return dfd;

Will that work??

Thanks a tone! I'm really clueless...

Alessandro

Add a comment
10|10000 characters needed characters exceeded

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on May 05, 2005 at 02:36 PM

    The object i'm trying to write is a custom object that

    extends Object.

    So it has the Object class methods and its own methods.

    How would i cast an Object to a byte input stream?

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Alessandro,

      if the Object is serializalbe in any way, you can simple create ObjectInputStreams and write the object as content to the RF. But keep in mind that there is no application/iView on top on of the RF who can display your content. You have to develop something, which displays the custom object.

      Regards,

      Thilo

  • Posted on May 05, 2005 at 01:44 PM

    Hi Alessandro,

    Why are you deleting the resource? Why not use something like:

    String out = new String(conent);
    ByteArrayInputStream data = new ByteArrayInputStream(out.getBytes());			
    IContent content = new Content(data, mimetype, data.available());
    resource.updateContent(content);
    

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 05, 2005 at 01:58 PM

    Thanks for the reply.

    Now i'm not deleting the file but merely updating it.

    However, how do i get it to write an object into the

    file?

    So i have an object called FinanceDataType. I instantiate

    it and want to put it into a file in KM so that i can

    later retrieve it.

    FinanceDataType fdt = new FinanceDataType();
    
    IContent c = new Content(?????);
    
    resource.updateContent(c);
    

    What do i put in the ???? part?

    Thanks

    Add a comment
    10|10000 characters needed characters exceeded

    • What is the object you are trying to add? I believe you need to cast it to ByteArrayInputStream as shown in the following code. textForFileContent is a simple string in this case.

      	
      String out = new String(textForFileContent);
      ByteArrayInputStream data = new ByteArrayInputStream(out.getBytes());
      

  • author's profile photo Former Member
    Former Member
    Posted on May 09, 2005 at 08:45 AM

    Thanks Thilo,

    That's exactly what i'm trying to do. The only problem

    is that i have no idea how to write the object using

    the ObjectInputStream. Do you have any sample code?

    Thanks,

    Alessandro

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.