Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How can I create URI that refers to in-memory byte array stream?
How can I create URI that refers to in-memory byte array stream? [message #421008] Mon, 21 July 2008 14:18 Go to next message
koloale is currently offline koloaleFriend
Messages: 41
Registered: July 2009
Member
Hello,

I want to save/load model instance to some strings in memory. When using
ResourceSet it needs to pass URI in 'createResource' method, so I need
to create URI on ByteArrayStream. Passing null in 'createResource'
method causes exception.

Thanks in advance
Alexey
Re: How can I create URI that refers to in-memory byte array stream? [message #421012 is a reply to message #421008] Mon, 21 July 2008 17:33 Go to previous messageGo to next message
Maximilian Koegel is currently offline Maximilian KoegelFriend
Messages: 253
Registered: July 2009
Senior Member
Hi,
you can use this code to save the resource to a string:

ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
resource.save(out, null);
} catch (IOException e) {
e.printStackTrace();
}

Maximilian

koloale wrote:
> Hello,
>
> I want to save/load model instance to some strings in memory. When using
> ResourceSet it needs to pass URI in 'createResource' method, so I need
> to create URI on ByteArrayStream. Passing null in 'createResource'
> method causes exception.
>
> Thanks in advance
> Alexey
Re: How can I create URI that refers to in-memory byte array stream? [message #421018 is a reply to message #421008] Mon, 21 July 2008 19:38 Go to previous messageGo to next message
David Steinberg is currently offline David SteinbergFriend
Messages: 489
Registered: July 2009
Senior Member
Hi Alexy,

You can use any non-null URI (even URI.createURI("") should be fine) to
create the resource. If you use the two-argument form of save() and
load(), as suggested by Maximilian, it won't need to use the URI to try
to obtain a stream (since you'll have provided it directly).

Then, the only reason the URI might come into play is to compute or
resolve proxy URIs for cross-document references.

Cheers,
Dave


koloale wrote:
> Hello,
>
> I want to save/load model instance to some strings in memory. When using
> ResourceSet it needs to pass URI in 'createResource' method, so I need
> to create URI on ByteArrayStream. Passing null in 'createResource'
> method causes exception.
>
> Thanks in advance
> Alexey
Re: How can I create URI that refers to in-memory byte array stream? [message #421026 is a reply to message #421018] Tue, 22 July 2008 07:24 Go to previous messageGo to next message
koloale is currently offline koloaleFriend
Messages: 41
Registered: July 2009
Member
Thank you, Dave, for your answer. However it seems a litle strange to
require passing not null URI in 'createResource(URI uri)' method if I'm
going to use other streams in two-argument methods.

Dave Steinberg wrote:
> Hi Alexy,
>
> You can use any non-null URI (even URI.createURI("") should be fine) to
> create the resource. If you use the two-argument form of save() and
> load(), as suggested by Maximilian, it won't need to use the URI to try
> to obtain a stream (since you'll have provided it directly).
>
> Then, the only reason the URI might come into play is to compute or
> resolve proxy URIs for cross-document references.
>
> Cheers,
> Dave
>
>
> koloale wrote:
>> Hello,
>>
>> I want to save/load model instance to some strings in memory. When
>> using ResourceSet it needs to pass URI in 'createResource' method, so
>> I need to create URI on ByteArrayStream. Passing null in
>> 'createResource' method causes exception.
>>
>> Thanks in advance
>> Alexey
Re: How can I create URI that refers to in-memory byte array stream? [message #421034 is a reply to message #421026] Tue, 22 July 2008 14:28 Go to previous messageGo to next message
David Steinberg is currently offline David SteinbergFriend
Messages: 489
Registered: July 2009
Senior Member
koloale wrote:
> Thank you, Dave, for your answer. However it seems a litle strange to
> require passing not null URI in 'createResource(URI uri)' method if I'm
> going to use other streams in two-argument methods.

Hi Alexy,

It may seem a little strange, but I can live with that if you can. ;)

As I hinted in my previous reply, URIs play other roles in the
framework: they determine the type of each resource being created, they
uniquely identify a resource in a resource set, and they're instrumental
in persisting cross-resource references. So, from that perspective, it
doesn't make much sense to allow a resource not to have one.

Cheers,
Dave
Re: How can I create URI that refers to in-memory byte array stream? [message #421370 is a reply to message #421018] Wed, 06 August 2008 06:36 Go to previous messageGo to next message
Shahar Ronen is currently offline Shahar RonenFriend
Messages: 17
Registered: July 2009
Junior Member
Hello Dave,

Is there a way to create a resource from a ByteArrayStream via getResource()
or other ResourceSet methods? Passing a URI isn't a problem, but I want the
resource to be set from an in-memory byte stream, not from the file on the
disk whose URI is passed.

Thanks
Shahar.

"Dave Steinberg" <davidms@ca.ibm.com> wrote in message
news:g62om4$5ae$1@build.eclipse.org...
> Hi Alexy,
>
> You can use any non-null URI (even URI.createURI("") should be fine) to
> create the resource. If you use the two-argument form of save() and
> load(), as suggested by Maximilian, it won't need to use the URI to try to
> obtain a stream (since you'll have provided it directly).
>
> Then, the only reason the URI might come into play is to compute or
> resolve proxy URIs for cross-document references.
>
> Cheers,
> Dave
>
>
> koloale wrote:
>> Hello,
>>
>> I want to save/load model instance to some strings in memory. When using
>> ResourceSet it needs to pass URI in 'createResource' method, so I need to
>> create URI on ByteArrayStream. Passing null in 'createResource' method
>> causes exception.
>>
>> Thanks in advance
>> Alexey
Re: How can I create URI that refers to in-memory byte array stream? [message #421388 is a reply to message #421370] Wed, 06 August 2008 11:51 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Shahar,

Using resource.load(<inputStream>, <options) does the trick. The same
caveat about the URI applies, i.e., it's typical to use
resourceSet.createResource(<uri>) where the URI determines the type of
resource created (and there's a new-to-EMF 2.4 version that allows you
to specify the content type explicitly) and the URI will be used to
resolve any relative URIs within the byte stream.


Shahar Ronen wrote:
> Hello Dave,
>
> Is there a way to create a resource from a ByteArrayStream via
> getResource() or other ResourceSet methods? Passing a URI isn't a
> problem, but I want the resource to be set from an in-memory byte
> stream, not from the file on the disk whose URI is passed.
>
> Thanks
> Shahar.
>
> "Dave Steinberg" <davidms@ca.ibm.com> wrote in message
> news:g62om4$5ae$1@build.eclipse.org...
>> Hi Alexy,
>>
>> You can use any non-null URI (even URI.createURI("") should be fine)
>> to create the resource. If you use the two-argument form of save()
>> and load(), as suggested by Maximilian, it won't need to use the URI
>> to try to obtain a stream (since you'll have provided it directly).
>>
>> Then, the only reason the URI might come into play is to compute or
>> resolve proxy URIs for cross-document references.
>>
>> Cheers,
>> Dave
>>
>>
>> koloale wrote:
>>> Hello,
>>>
>>> I want to save/load model instance to some strings in memory. When
>>> using ResourceSet it needs to pass URI in 'createResource' method,
>>> so I need to create URI on ByteArrayStream. Passing null in
>>> 'createResource' method causes exception.
>>>
>>> Thanks in advance
>>> Alexey
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[Teneo] containment changes - problems with resaving
Next Topic:Problem with databinding
Goto Forum:
  


Current Time: Thu Apr 25 22:13:11 GMT 2024

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

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

Back to the top