[OTDev] Needed some help with restlet

Nina Jeliazkova nina at acad.bg
Tue Jan 26 08:59:52 CET 2010


Hi Surajit,

surajit ray wrote:
> Hi Nina,
> Thanks for the information
>
> Could you please clarify if the outputstreamrepresentation is a class from
> restlet 2.0
>
>   
Yes, sorry for not being clear, it is OutputRepresentation indeed. Our
code is at

https://ambit.svn.sourceforge.net/svnroot/ambit/trunk/ambit2-all/ambit2-www/src/main/java/ambit2/rest/RDFJenaConvertor.java

and the relevant piece is:
     return new OutputRepresentation(mediaType) {
                @Override
                public void write(OutputStream output) throws IOException {
                    try {
                        if (mediaType.equals(MediaType.APPLICATION_RDF_XML))
                            jenaModel.write(output,"RDF/XML");
                           
//getJenaModel().write(output,"RDF/XML-ABBREV");   
                        else if
(mediaType.equals(MediaType.APPLICATION_RDF_TURTLE))
                            jenaModel.write(output,"TURTLE");
                        else if (mediaType.equals(MediaType.TEXT_RDF_N3))
                            jenaModel.write(output,"N3");
                        else if
(mediaType.equals(MediaType.TEXT_RDF_NTRIPLES))
                            jenaModel.write(output,"N-TRIPLE");   
                        else
                            jenaModel.write(output,"RDF/XML-ABBREV");   

                    } catch (Exception x) {
                        Throwable ex = x;
                        while (ex!=null) {
                            if (ex instanceof IOException)
                                throw (IOException)ex;
                            ex = ex.getCause();
                        }
                       
Context.getCurrentLogger().warning(x.getMessage()==null?x.toString():x.getMessage());
                    } finally {

                        try {if (output !=null) output.flush(); } catch
(Exception x) { x.printStackTrace();}
                        try {getReporter().close(); } catch (Exception
x) { x.printStackTrace();}
                    }
                }
            };               
> I could not find it in the current stable. There is however a
> Outputrepresentation which is a subclass of Streamrepresentation. Is this
> the one you were referring to ?
>
>   
Yes.

> As a test I was using this : (see attached java file)
>
> Would it be incorrect to use it as such ?
>
>
>   
No, not incorrect. It will work, but may have performance penalty with
large RDF models.  ByteArrayOutputStream [1] is effectively an array in
the memory, which grows as you write into it.  This means 1)once you
have JenaModel already in memory and 2)second time the same model is
duplicated, this time with ByteArrayOutputStream  representation. 

On the other hand, writing directly to the output stream avoid the
duplication, which is quite helpful, as RDF models tend to be memory
hungry anyway.

[1]
http://java.sun.com/j2se/1.4.2/docs/api/java/io/ByteArrayOutputStream.html

Best regards,
Nina
>
> On Mon, Jan 25, 2010 at 6:30 PM, Nina Jeliazkova <nina at acad.bg> wrote:
>
>   
>> surajit ray wrote:
>>     
>>> Hi,
>>> I was wondering what type of Representation to use for a Jena model
>>>       
>> (within
>>     
>>> the Restlet framework ) ?
>>>
>>>
>>>       
>> OutputStreamRepresentation and write  the model  into the output stream.
>>
>> Hope this helps,
>> Nina
>> _______________________________________________
>> Development mailing list
>> Development at opentox.org
>> http://www.opentox.org/mailman/listinfo/development
>>
>>     
>
>
>
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> Development mailing list
> Development at opentox.org
> http://www.opentox.org/mailman/listinfo/development




More information about the Development mailing list