Skip to main content



      Home
Home » Modeling » EMF » EObject to StreamSource
EObject to StreamSource [message #908908] Thu, 06 September 2012 04:05 Go to next message
Eclipse UserFriend
Hi guys,

I am just looking for EObject to StreamSource conversion.

I used the following code:

//P is the EObject
Project p = ...;

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(p);
oos.flush();
oos.close();

InputStream is = new ByteArrayInputStream(baos.toByteArray());
StreamSource source = new StreamSource(is);

I get an error: java.io.NotSerializableException

any help is appriciated.

Thanks a mil
K
Re: EObject to StreamSource [message #908932 is a reply to message #908908] Thu, 06 September 2012 04:48 Go to previous messageGo to next message
Eclipse UserFriend
Kosala,

You can't assume EObject will generally be java.io.Serializeable. You
could implement that for your model's implementation classes...
Easier would be to use the facilities in BinaryResourceImpl, e.g.,
EObjectInputStream and EObjectOutputStream.


On 06/09/2012 10:05 AM, Kosala Yapa wrote:
> Hi guys,
>
> I am just looking for EObject to StreamSource conversion.
>
> I used the following code:
>
> //P is the EObject
> Project p = ...;
>
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> ObjectOutputStream oos = new ObjectOutputStream(baos);
> oos.writeObject(p);
> oos.flush();
> oos.close();
>
> InputStream is = new ByteArrayInputStream(baos.toByteArray());
> StreamSource source = new StreamSource(is);
>
> I get an error: java.io.NotSerializableException
>
> any help is appriciated.
>
> Thanks a mil
> K
Re: EObject to StreamSource [message #909564 is a reply to message #908932] Fri, 07 September 2012 06:38 Go to previous messageGo to next message
Eclipse UserFriend
Thanks a mil Ed.

I am just wondering how to extract an EObject to EObjectOutputStream?

//p is an EObject
Project p = getProject(...);


PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pin = new PipedInputStream(pout);
EObjectOutputStream eoOutStream = new EObjectOutputStream(pout,null);

//need to add p to eoOutStream
//ObjectOutputStream has writeObject method. How to do that for EObjectOutputStream ?

StreamSource source = new StreamSource(pin);

Thanks.
K

[Updated on: Fri, 07 September 2012 06:39] by Moderator

Re: EObject to StreamSource [message #909571 is a reply to message #909564] Fri, 07 September 2012 06:52 Go to previous message
Eclipse UserFriend
Kosala,

I think you'll get the idea when you look at what doSave and doLoad and
what the methods they call do. I.e., you'll notice there are
saveEObject and loadEObject methods.


On 07/09/2012 12:38 PM, Kosala Yapa wrote:
> Thanks Ed.
>
> I am just wondering how to extract an EObject to EObjectOutputStream?
>
> //p is an EObject
> Project p = getProject(...);
>
>
> PipedOutputStream pout = new PipedOutputStream(); PipedInputStream pin
> = new PipedInputStream(pout); EObjectOutputStream eoOutStream = new
> EObjectOutputStream(pout,null);
>
> //ObjectOutputStream has writeObject method. How to do that for
> EObjectOutputStream ?
>
> StreamSource source = new StreamSource(pin);
>
> Thanks.
> K
Previous Topic:Emap with EMF (in ecorediagram)
Next Topic:[Xcore] How to wrap an enum defined in an interface?
Goto Forum:
  


Current Time: Fri Nov 07 11:52:09 EST 2025

Powered by FUDForum. Page generated in 0.03944 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top