8 Replies Latest reply on Oct 11, 2013 8:00 AM by hchiorean

    Problem with reading binary stream from file

    m.jawwad

      Hi,

       

          I managed to configure modeshape with infinispan to store both metadata and binaries for modeshape content. Now the problem is I can write data (content) into the repository but when I try to read the binary stream from the repository, it does not work. When I try to write the extracted input stream to an outstream, the stream ended unexpectedly. The stream returned from modeshape is "org.modeshape.jcr.value.binary.infinispan.ChunkInputStream"

       

      Here is my code to read stream from modeshape:

       

      InputStream is = null;

      ServletOutputStream outs = response.getOutputStream();

      if(binaryStream!=null){

                is=binaryStream.getStream();           //the stream is Not null and return a org.modeshape.jcr.value.binary.infinispan.ChunkInputStream object

                contentLength=Math.round(binaryStream.getSize());

      }

       

      Now here is the code to write data onto the output stream:

       

      int bit = 256;

      byte[] buffer = new byte[4096];

            while ((bit = is.read(buffer, 0, 4096)) != -1) {

                     outs.write(buffer, 0, bit);

           }

       

      Here no eception is thrown but the code inside the while loop never executes.

       

      Can anybody tell me what am I missing ?

       

      Regards.