Writing a Sling content via output stream as opposed to

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Writing a Sling content via output stream as opposed to

John Logan
Hehe, more questions...


When I'm writing content to resources, I've been using

ValueFactory to wrap an InputStream, and then setting

the jcr:data property of my content resource, and this

works fine.


I have one use case (a preexisting storage abstraction

layer) where I need to write a resource by getting an

OutputStream for the resource, akin to the way

java.nio.file.Files.newOutputStream() works.


Does the Sling Framework provide any way to do this?

I found nothing in either the JCR or the Sling docs, so

I'm planning to create a ResourceOutputStream that

derives from PipedOutputStream and creates a

copy thread, and PipedInputStream to plug into the

Binary value.  If there's already something that supports

this way of writing, I'd prefer to use that though.


Thanks once again!  John
Reply | Threaded
Open this post in threaded view
|

Re: Writing a Sling content via output stream as opposed to

John Logan
No need to worry about this issue; I have something in place now.


Using piped streams was going to be a headache because the output stream needed to be in the main thread, meaning that the jcr:data property update run in a thread, necessitating the use of a service resolver.  I didn't want to go there.


I instead created an extension of FilterOutputStream over a temporary FileOutputStream, overriding the close method to do the property update there.


It's inefficient, but it solves my problem.


John