chemistry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Denis Andreev" <andr...@elilink.com>
Subject DotCMIS issue in DotCMIS.Binding.AtomPub.AtomEntryWriter.WriteContent()
Date Tue, 15 Jan 2013 10:59:19 GMT
Hi Everyone

There is an issue in the method
DotCMIS.Binding.AtomPub.AtomEntryWriter.WriteContent()

 

        private void WriteContent(XmlWriter writer)

        {

            using (var br = new BinaryReader(stream))

            {

                var buffer = new byte[BufferSize];

                int readBytes = 0;

                do

                {

                    readBytes = br.Read(buffer, 0, BufferSize);

                    writer.WriteBase64(buffer, 0, readBytes);

                } while (BufferSize <= readBytes);

            }

        }

 

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 code above the first read operation returns 4K from the stream and
the condition "while (BufferSize <= readBytes)" finishes the read cycle. 

 

I've fixed the problem with the code below. The read cycle should continue
working unit Read returns the value != 0:

 

        private void WriteContent(XmlWriter writer)

        {

            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);

                }

 

                /*

                do

                {

                    readBytes = br.Read(buffer, 0, BufferSize);

                    writer.WriteBase64(buffer, 0, readBytes);

                } while (BufferSize <= readBytes);

                */

            }

        }

 

Would you please consider this code and update DotCMIS library.

 

Best regards,

Denis Andreev

 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message