on 05-05-2005 2:32 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
Regards
Daniel
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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());
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);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.