Showing results for 
Search instead for 
Did you mean: 

Java object as IResource content

Former Member
0 Kudos

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);

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


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...


Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

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?



Former Member
0 Kudos

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?

Active Contributor
0 Kudos

Given that it is a custom object its hard to say.

But I take it that the object is some sort of file or has some displayable content?

I doubt it would be as simple as getting the object as a string and then casting the string to a stream..

Other than that it will be very difficult to know what can be done without knowing what sort of object we are dealing with.



0 Kudos

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.



Former Member
0 Kudos

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


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(?????);


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


Active Contributor
0 Kudos

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());

Active Contributor
0 Kudos

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());