You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by Shane Preater <sh...@googlemail.com> on 2006/10/11 14:43:26 UTC

Pulling binary data from a property

Hi,

I have a property on a node called 'blobData' this property has been loaded
using the following snippet:

ValueFactory factory = session.getValueFactory();
Value value = factory.createValue(new ByteArrayInputStream(data));
node.setProperty(propertyName, value);

Then obviously further on a call to session.save(); is used to persist this.

I am now trying to get this binary information back from the property using:

InputStream inputStream = node.getProperty(property)
                            .getStream();
int readInt = 0;
while ((readInt = inputStream.read()) >= 0) {
  outputStream.write(readInt);
 }
return outputStream.toByteArray();

However this always returns an empty byte array as the first call to
inputStream.read() returns -1 indicating the end of the stream.

Could someone point me in the direction of my error.

Thanks,
Shane.

Re: Pulling binary data from a property

Posted by Stefan Guggisberg <st...@gmail.com>.
hi shane,

On 10/11/06, Shane Preater <sh...@googlemail.com> wrote:
> Hi Stefan,
> Thanks for the help. I will put further questions to the user list. Sorry
> about that.
>
> I am using the RMI implementation to aquire a repository instance so this
> maybe my problem.
>
> The repository is acquired through JNDI and then I simply acquire the
> correct node using session.getRootNode(); then node.getNode("myNode");
>
> Hopefully this will help narrow the problem down.

this is probably a bug in the RMI stream handling code. please
create a jira issue and include all relevant information.

thanks
stefan

> Shane.
>
>
> On 11/10/06, Stefan Guggisberg <st...@gmail.com> wrote:
> >
> > hi shane,
> >
> > On 10/11/06, Shane Preater <sh...@googlemail.com> wrote:
> > > Hi,
> > >
> > > I have a property on a node called 'blobData' this property has been
> > loaded
> > > using the following snippet:
> > >
> > > ValueFactory factory = session.getValueFactory();
> > > Value value = factory.createValue(new ByteArrayInputStream(data));
> > > node.setProperty(propertyName, value);
> > >
> > > Then obviously further on a call to session.save(); is used to persist
> > this.
> > >
> > > I am now trying to get this binary information back from the property
> > using:
> > >
> > > InputStream inputStream = node.getProperty(property)
> > >                             .getStream();
> > > int readInt = 0;
> > > while ((readInt = inputStream.read()) >= 0) {
> > >   outputStream.write(readInt);
> > >  }
> > > return outputStream.toByteArray();
> > >
> > > However this always returns an empty byte array as the first call to
> > > inputStream.read() returns -1 indicating the end of the stream.
> > >
> > > Could someone point me in the direction of my error.
> >
> > your code looks fine so far. if you are directly accessing a local
> > jackrabbit
> > instance i guess the error must be in that part of the code that you
> > didn't
> > provide. if you're accessing a remote jackrabbit instance through RMI
> > there could be an issue wrt stream handling in the RMI implementation.
> >
> > in any case it would be good if you could provide a complete code sample.
> >
> > btw: the users list would be more appropriate for such questions.
> >
> > cheers
> > stefan
> >
> >
> >
> >
> > >
> > > Thanks,
> > > Shane.
> > >
> > >
> >
>
>

Re: Pulling binary data from a property

Posted by Shane Preater <sh...@googlemail.com>.
Hi Stefan,
Thanks for the help. I will put further questions to the user list. Sorry
about that.

I am using the RMI implementation to aquire a repository instance so this
maybe my problem.

The repository is acquired through JNDI and then I simply acquire the
correct node using session.getRootNode(); then node.getNode("myNode");

Hopefully this will help narrow the problem down.
Shane.


On 11/10/06, Stefan Guggisberg <st...@gmail.com> wrote:
>
> hi shane,
>
> On 10/11/06, Shane Preater <sh...@googlemail.com> wrote:
> > Hi,
> >
> > I have a property on a node called 'blobData' this property has been
> loaded
> > using the following snippet:
> >
> > ValueFactory factory = session.getValueFactory();
> > Value value = factory.createValue(new ByteArrayInputStream(data));
> > node.setProperty(propertyName, value);
> >
> > Then obviously further on a call to session.save(); is used to persist
> this.
> >
> > I am now trying to get this binary information back from the property
> using:
> >
> > InputStream inputStream = node.getProperty(property)
> >                             .getStream();
> > int readInt = 0;
> > while ((readInt = inputStream.read()) >= 0) {
> >   outputStream.write(readInt);
> >  }
> > return outputStream.toByteArray();
> >
> > However this always returns an empty byte array as the first call to
> > inputStream.read() returns -1 indicating the end of the stream.
> >
> > Could someone point me in the direction of my error.
>
> your code looks fine so far. if you are directly accessing a local
> jackrabbit
> instance i guess the error must be in that part of the code that you
> didn't
> provide. if you're accessing a remote jackrabbit instance through RMI
> there could be an issue wrt stream handling in the RMI implementation.
>
> in any case it would be good if you could provide a complete code sample.
>
> btw: the users list would be more appropriate for such questions.
>
> cheers
> stefan
>
>
>
>
> >
> > Thanks,
> > Shane.
> >
> >
>

Re: Pulling binary data from a property

Posted by Stefan Guggisberg <st...@gmail.com>.
hi shane,

On 10/11/06, Shane Preater <sh...@googlemail.com> wrote:
> Hi,
>
> I have a property on a node called 'blobData' this property has been loaded
> using the following snippet:
>
> ValueFactory factory = session.getValueFactory();
> Value value = factory.createValue(new ByteArrayInputStream(data));
> node.setProperty(propertyName, value);
>
> Then obviously further on a call to session.save(); is used to persist this.
>
> I am now trying to get this binary information back from the property using:
>
> InputStream inputStream = node.getProperty(property)
>                             .getStream();
> int readInt = 0;
> while ((readInt = inputStream.read()) >= 0) {
>   outputStream.write(readInt);
>  }
> return outputStream.toByteArray();
>
> However this always returns an empty byte array as the first call to
> inputStream.read() returns -1 indicating the end of the stream.
>
> Could someone point me in the direction of my error.

your code looks fine so far. if you are directly accessing a local jackrabbit
instance i guess the error must be in that part of the code that you didn't
provide. if you're accessing a remote jackrabbit instance through RMI
there could be an issue wrt stream handling in the RMI implementation.

in any case it would be good if you could provide a complete code sample.

btw: the users list would be more appropriate for such questions.

cheers
stefan




>
> Thanks,
> Shane.
>
>

Re: Pulling binary data from a property

Posted by Shane Preater <sh...@googlemail.com>.
Hmm OK I have put together a test case to exercise the RMI stream issue and
it is passing!! Looks like this problem has already been resolved for the
1.1.1 release which is what I am currently using.

Please see the attached JUnit TestCase that I have been using and let me
know if it fails for you.

The only thing I can think of which is different from when I experienced the
problem before is the size of the binary data. As in the real app we are
storing image data as a property on the node.

Shane.

On 29/01/07, Stefan Guggisberg <st...@gmail.com> wrote:
>
> On 1/29/07, Shane Preater <sh...@googlemail.com> wrote:
> > Hi there,
> > Yeah there was an issue but I did not get a chance to add the JIRA at
> the
> > time and then totally forgot about it.
> >
> > Sorry about that :(
>
> np, thanks for the feedback.
>
> >
> > The work around is, as suggested, use a bufferedInputStream around the
> one
> > from the property and all is good.
> >
> > Are you going to raise the JIRA or would you like me to do so now?
>
> i'd prefer you create the issue. if possible please include a small test
> case
> that demonstrates the issue. and don't forget to mention that the problem
> occurs when using rmi.
>
> thanks!
> stefan
>
> >
> > On 29/01/07, Stefan Guggisberg <st...@gmail.com> wrote:
> > >
> > > On 1/26/07, JavaJ <po...@yahoo.com> wrote:
> > > >
> > > > Hi there,
> > > >
> > > > Were you ever able to resolve this problem?
> > >
> > > i am not convinced whether there *was* a problem. at least shane did
> not
> > > create
> > > a jira issue as suggested.
> > >
> > > >
> > > > I having the same problem and I am not using RMI.   Basically, I am
> > > using
> > > > almost the exact same code to persist the binary property.  I can
> verify
> > > > that the property is persisted properly because if I retrieve the
> node
> > > back
> > > > (in another thread), the property looks fine.  However, after the
> > > initial
> > > > call of save() on the node, if I try to retrieve the property from
> the
> > > same
> > > > instance of the node, the stream has 0 bytes.
> > >
> > > please create a jira issue if you're able to reproduce the issue.
> please
> > > inlcude a simple test case that demonstrates the issue.
> > >
> > > however i'm pretty confident that there's an issue with your test
> code.
> > > i did a quick test with the following code, everything worked as
> expected.
> > >
> > >             byte[] data = new byte[100000];
> > >             ValueFactory factory = session.getValueFactory();
> > >             Value value = factory.createValue(new
> > > ByteArrayInputStream(data));
> > >
> > >             Node node = root.addNode("foo");
> > >             node.setProperty("bin", new ByteArrayInputStream(data));
> > >             root.save();
> > >
> > >             InputStream in = node.getProperty("bin").getStream();
> > >             ByteArrayOutputStream baos = new ByteArrayOutputStream();
> > >             try {
> > >                 int read = 0;
> > >                 while ((read = in.read()) >= 0) {
> > >                     baos.write(read);
> > >                 }
> > >             } finally {
> > >                 in.close();
> > >             }
> > >             byte[] data1 = baos.toByteArray();
> > >             System.out.println(Arrays.equals(data, data1));
> > >
> > >
> > >
> > > >
> > > > Perhaps it's a bug with using ByteArrayInputStream?
> > >
> > > rather unlikely ;-)
> > >
> > > cheers
> > > stefan
> > >
> > > >
> > > >
> > > >
> > > >
> > > > zagarol wrote:
> > > > >
> > > > > Hi,
> > > > >
> > > > > I have a property on a node called 'blobData' this property has
> been
> > > > > loaded
> > > > > using the following snippet:
> > > > >
> > > > > ValueFactory factory = session.getValueFactory();
> > > > > Value value = factory.createValue(new ByteArrayInputStream(data));
> > > > > node.setProperty(propertyName, value);
> > > > >
> > > > > Then obviously further on a call to session.save(); is used to
> persist
> > > > > this.
> > > > >
> > > > > I am now trying to get this binary information back from the
> property
> > > > > using:
> > > > >
> > > > > InputStream inputStream = node.getProperty(property)
> > > > >                             .getStream();
> > > > > int readInt = 0;
> > > > > while ((readInt = inputStream.read()) >= 0) {
> > > > >   outputStream.write(readInt);
> > > > >  }
> > > > > return outputStream.toByteArray();
> > > > >
> > > > > However this always returns an empty byte array as the first call
> to
> > > > > inputStream.read() returns -1 indicating the end of the stream.
> > > > >
> > > > > Could someone point me in the direction of my error.
> > > > >
> > > > > Thanks,
> > > > > Shane.
> > > > >
> > > > >
> > > >
> > > > --
> > > > View this message in context:
> > >
> http://www.nabble.com/Pulling-binary-data-from-a-property-tf2423182.html#a8657674
> > > > Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.
> > > >
> > > >
> > >
> >
> >
>

Re: Pulling binary data from a property

Posted by Stefan Guggisberg <st...@gmail.com>.
On 1/29/07, Shane Preater <sh...@googlemail.com> wrote:
> Hi there,
> Yeah there was an issue but I did not get a chance to add the JIRA at the
> time and then totally forgot about it.
>
> Sorry about that :(

np, thanks for the feedback.

>
> The work around is, as suggested, use a bufferedInputStream around the one
> from the property and all is good.
>
> Are you going to raise the JIRA or would you like me to do so now?

i'd prefer you create the issue. if possible please include a small test case
that demonstrates the issue. and don't forget to mention that the problem
occurs when using rmi.

thanks!
stefan

>
> On 29/01/07, Stefan Guggisberg <st...@gmail.com> wrote:
> >
> > On 1/26/07, JavaJ <po...@yahoo.com> wrote:
> > >
> > > Hi there,
> > >
> > > Were you ever able to resolve this problem?
> >
> > i am not convinced whether there *was* a problem. at least shane did not
> > create
> > a jira issue as suggested.
> >
> > >
> > > I having the same problem and I am not using RMI.   Basically, I am
> > using
> > > almost the exact same code to persist the binary property.  I can verify
> > > that the property is persisted properly because if I retrieve the node
> > back
> > > (in another thread), the property looks fine.  However, after the
> > initial
> > > call of save() on the node, if I try to retrieve the property from the
> > same
> > > instance of the node, the stream has 0 bytes.
> >
> > please create a jira issue if you're able to reproduce the issue. please
> > inlcude a simple test case that demonstrates the issue.
> >
> > however i'm pretty confident that there's an issue with your test code.
> > i did a quick test with the following code, everything worked as expected.
> >
> >             byte[] data = new byte[100000];
> >             ValueFactory factory = session.getValueFactory();
> >             Value value = factory.createValue(new
> > ByteArrayInputStream(data));
> >
> >             Node node = root.addNode("foo");
> >             node.setProperty("bin", new ByteArrayInputStream(data));
> >             root.save();
> >
> >             InputStream in = node.getProperty("bin").getStream();
> >             ByteArrayOutputStream baos = new ByteArrayOutputStream();
> >             try {
> >                 int read = 0;
> >                 while ((read = in.read()) >= 0) {
> >                     baos.write(read);
> >                 }
> >             } finally {
> >                 in.close();
> >             }
> >             byte[] data1 = baos.toByteArray();
> >             System.out.println(Arrays.equals(data, data1));
> >
> >
> >
> > >
> > > Perhaps it's a bug with using ByteArrayInputStream?
> >
> > rather unlikely ;-)
> >
> > cheers
> > stefan
> >
> > >
> > >
> > >
> > >
> > > zagarol wrote:
> > > >
> > > > Hi,
> > > >
> > > > I have a property on a node called 'blobData' this property has been
> > > > loaded
> > > > using the following snippet:
> > > >
> > > > ValueFactory factory = session.getValueFactory();
> > > > Value value = factory.createValue(new ByteArrayInputStream(data));
> > > > node.setProperty(propertyName, value);
> > > >
> > > > Then obviously further on a call to session.save(); is used to persist
> > > > this.
> > > >
> > > > I am now trying to get this binary information back from the property
> > > > using:
> > > >
> > > > InputStream inputStream = node.getProperty(property)
> > > >                             .getStream();
> > > > int readInt = 0;
> > > > while ((readInt = inputStream.read()) >= 0) {
> > > >   outputStream.write(readInt);
> > > >  }
> > > > return outputStream.toByteArray();
> > > >
> > > > However this always returns an empty byte array as the first call to
> > > > inputStream.read() returns -1 indicating the end of the stream.
> > > >
> > > > Could someone point me in the direction of my error.
> > > >
> > > > Thanks,
> > > > Shane.
> > > >
> > > >
> > >
> > > --
> > > View this message in context:
> > http://www.nabble.com/Pulling-binary-data-from-a-property-tf2423182.html#a8657674
> > > Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.
> > >
> > >
> >
>
>

Re: Pulling binary data from a property

Posted by Shane Preater <sh...@googlemail.com>.
Hi there,
Yeah there was an issue but I did not get a chance to add the JIRA at the
time and then totally forgot about it.

Sorry about that :(

The work around is, as suggested, use a bufferedInputStream around the one
from the property and all is good.

Are you going to raise the JIRA or would you like me to do so now?

On 29/01/07, Stefan Guggisberg <st...@gmail.com> wrote:
>
> On 1/26/07, JavaJ <po...@yahoo.com> wrote:
> >
> > Hi there,
> >
> > Were you ever able to resolve this problem?
>
> i am not convinced whether there *was* a problem. at least shane did not
> create
> a jira issue as suggested.
>
> >
> > I having the same problem and I am not using RMI.   Basically, I am
> using
> > almost the exact same code to persist the binary property.  I can verify
> > that the property is persisted properly because if I retrieve the node
> back
> > (in another thread), the property looks fine.  However, after the
> initial
> > call of save() on the node, if I try to retrieve the property from the
> same
> > instance of the node, the stream has 0 bytes.
>
> please create a jira issue if you're able to reproduce the issue. please
> inlcude a simple test case that demonstrates the issue.
>
> however i'm pretty confident that there's an issue with your test code.
> i did a quick test with the following code, everything worked as expected.
>
>             byte[] data = new byte[100000];
>             ValueFactory factory = session.getValueFactory();
>             Value value = factory.createValue(new
> ByteArrayInputStream(data));
>
>             Node node = root.addNode("foo");
>             node.setProperty("bin", new ByteArrayInputStream(data));
>             root.save();
>
>             InputStream in = node.getProperty("bin").getStream();
>             ByteArrayOutputStream baos = new ByteArrayOutputStream();
>             try {
>                 int read = 0;
>                 while ((read = in.read()) >= 0) {
>                     baos.write(read);
>                 }
>             } finally {
>                 in.close();
>             }
>             byte[] data1 = baos.toByteArray();
>             System.out.println(Arrays.equals(data, data1));
>
>
>
> >
> > Perhaps it's a bug with using ByteArrayInputStream?
>
> rather unlikely ;-)
>
> cheers
> stefan
>
> >
> >
> >
> >
> > zagarol wrote:
> > >
> > > Hi,
> > >
> > > I have a property on a node called 'blobData' this property has been
> > > loaded
> > > using the following snippet:
> > >
> > > ValueFactory factory = session.getValueFactory();
> > > Value value = factory.createValue(new ByteArrayInputStream(data));
> > > node.setProperty(propertyName, value);
> > >
> > > Then obviously further on a call to session.save(); is used to persist
> > > this.
> > >
> > > I am now trying to get this binary information back from the property
> > > using:
> > >
> > > InputStream inputStream = node.getProperty(property)
> > >                             .getStream();
> > > int readInt = 0;
> > > while ((readInt = inputStream.read()) >= 0) {
> > >   outputStream.write(readInt);
> > >  }
> > > return outputStream.toByteArray();
> > >
> > > However this always returns an empty byte array as the first call to
> > > inputStream.read() returns -1 indicating the end of the stream.
> > >
> > > Could someone point me in the direction of my error.
> > >
> > > Thanks,
> > > Shane.
> > >
> > >
> >
> > --
> > View this message in context:
> http://www.nabble.com/Pulling-binary-data-from-a-property-tf2423182.html#a8657674
> > Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.
> >
> >
>

Re: Pulling binary data from a property

Posted by Stefan Guggisberg <st...@gmail.com>.
On 1/26/07, JavaJ <po...@yahoo.com> wrote:
>
> Hi there,
>
> Were you ever able to resolve this problem?

i am not convinced whether there *was* a problem. at least shane did not create
a jira issue as suggested.

>
> I having the same problem and I am not using RMI.   Basically, I am using
> almost the exact same code to persist the binary property.  I can verify
> that the property is persisted properly because if I retrieve the node back
> (in another thread), the property looks fine.  However, after the initial
> call of save() on the node, if I try to retrieve the property from the same
> instance of the node, the stream has 0 bytes.

please create a jira issue if you're able to reproduce the issue. please
inlcude a simple test case that demonstrates the issue.

however i'm pretty confident that there's an issue with your test code.
i did a quick test with the following code, everything worked as expected.

            byte[] data = new byte[100000];
            ValueFactory factory = session.getValueFactory();
            Value value = factory.createValue(new ByteArrayInputStream(data));

            Node node = root.addNode("foo");
            node.setProperty("bin", new ByteArrayInputStream(data));
            root.save();

            InputStream in = node.getProperty("bin").getStream();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                int read = 0;
                while ((read = in.read()) >= 0) {
                    baos.write(read);
                }
            } finally {
                in.close();
            }
            byte[] data1 = baos.toByteArray();
            System.out.println(Arrays.equals(data, data1));



>
> Perhaps it's a bug with using ByteArrayInputStream?

rather unlikely ;-)

cheers
stefan

>
>
>
>
> zagarol wrote:
> >
> > Hi,
> >
> > I have a property on a node called 'blobData' this property has been
> > loaded
> > using the following snippet:
> >
> > ValueFactory factory = session.getValueFactory();
> > Value value = factory.createValue(new ByteArrayInputStream(data));
> > node.setProperty(propertyName, value);
> >
> > Then obviously further on a call to session.save(); is used to persist
> > this.
> >
> > I am now trying to get this binary information back from the property
> > using:
> >
> > InputStream inputStream = node.getProperty(property)
> >                             .getStream();
> > int readInt = 0;
> > while ((readInt = inputStream.read()) >= 0) {
> >   outputStream.write(readInt);
> >  }
> > return outputStream.toByteArray();
> >
> > However this always returns an empty byte array as the first call to
> > inputStream.read() returns -1 indicating the end of the stream.
> >
> > Could someone point me in the direction of my error.
> >
> > Thanks,
> > Shane.
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Pulling-binary-data-from-a-property-tf2423182.html#a8657674
> Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.
>
>

Re: Pulling binary data from a property

Posted by JavaJ <po...@yahoo.com>.
Hi there,

Were you ever able to resolve this problem?

I having the same problem and I am not using RMI.   Basically, I am using
almost the exact same code to persist the binary property.  I can verify
that the property is persisted properly because if I retrieve the node back
(in another thread), the property looks fine.  However, after the initial
call of save() on the node, if I try to retrieve the property from the same
instance of the node, the stream has 0 bytes.

Perhaps it's a bug with using ByteArrayInputStream?




zagarol wrote:
> 
> Hi,
> 
> I have a property on a node called 'blobData' this property has been
> loaded
> using the following snippet:
> 
> ValueFactory factory = session.getValueFactory();
> Value value = factory.createValue(new ByteArrayInputStream(data));
> node.setProperty(propertyName, value);
> 
> Then obviously further on a call to session.save(); is used to persist
> this.
> 
> I am now trying to get this binary information back from the property
> using:
> 
> InputStream inputStream = node.getProperty(property)
>                             .getStream();
> int readInt = 0;
> while ((readInt = inputStream.read()) >= 0) {
>   outputStream.write(readInt);
>  }
> return outputStream.toByteArray();
> 
> However this always returns an empty byte array as the first call to
> inputStream.read() returns -1 indicating the end of the stream.
> 
> Could someone point me in the direction of my error.
> 
> Thanks,
> Shane.
> 
> 

-- 
View this message in context: http://www.nabble.com/Pulling-binary-data-from-a-property-tf2423182.html#a8657674
Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.


Re: Pulling binary data from a property

Posted by Tobias Bocanegra <to...@day.com>.
just a guess: try read/write via a buffer and not byte-per-byte ?
maybe theres something wrong in the read() implementation of the
respective inputstream.

regards, toby

On 10/11/06, Shane Preater <sh...@googlemail.com> wrote:
> Hi,
>
> I have a property on a node called 'blobData' this property has been loaded
> using the following snippet:
>
> ValueFactory factory = session.getValueFactory();
> Value value = factory.createValue(new ByteArrayInputStream(data));
> node.setProperty(propertyName, value);
>
> Then obviously further on a call to session.save(); is used to persist this.
>
> I am now trying to get this binary information back from the property using:
>
> InputStream inputStream = node.getProperty(property)
>                             .getStream();
> int readInt = 0;
> while ((readInt = inputStream.read()) >= 0) {
>   outputStream.write(readInt);
>  }
> return outputStream.toByteArray();
>
> However this always returns an empty byte array as the first call to
> inputStream.read() returns -1 indicating the end of the stream.
>
> Could someone point me in the direction of my error.
>
> Thanks,
> Shane.
>
>


-- 
-----------------------------------------< tobias.bocanegra@day.com >---
Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
T +41 61 226 98 98, F +41 61 226 98 97
-----------------------------------------------< http://www.day.com >---