chemistry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Denis Andreev (JIRA)" <j...@apache.org>
Subject [jira] [Created] (CMIS-619) Wrong stream reading in DotCMIS.Binding.AtomPub.AtomEntryWriter.WriteContent()
Date Tue, 15 Jan 2013 11:58:12 GMT
Denis Andreev created CMIS-619:
----------------------------------

             Summary: Wrong stream reading in DotCMIS.Binding.AtomPub.AtomEntryWriter.WriteContent()
                 Key: CMIS-619
                 URL: https://issues.apache.org/jira/browse/CMIS-619
             Project: Chemistry
          Issue Type: Bug
          Components: dotcmis
            Reporter: Denis Andreev


The problem is that the method "Stream.Read() or BinaryReader.Read()" may read less amount
of bytes than the provided buffer size when the end of the stream has not been reached yet.
For example.
The file "File1.txt" of size 30K is requested by HttpWebRequest to download from a server
and transfer it to Alfresco.
HttpWebRequest returns System.Net.ConnectStream.
The  buffer size to read from stream is 65K.

In the current code the first read operation returns 4K from the stream and the condition
"while (BufferSize <= readBytes)" finishes the read cycle.

The problem can be fixed by the code below:
using (var br = new BinaryReader(stream))
{
   var buffer = new byte[BufferSize];
   int readBytes = 0;
   while ((readBytes = br.Read(buffer, 0, BufferSize)) != 0)
   {
      writer.WriteBase64(buffer, 0, readBytes);
   }
}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message