Deveel.Data.Store.ObjectStream.Read C# (CSharp) Méthode

Read() public méthode

public Read ( byte buffer, int offset, int count ) : int
buffer byte
offset int
count int
Résultat int
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (!largeObject.IsComplete)
                throw new IOException("The underlying object is not complete.");

            if (count <= 0) {
                return 0;
            }

            if (readBufferPos == -1) {
                FillBuffer(position);
            }

            int p = (int) (position - readBufferPos);
            long bufferEnd = System.Math.Min(readBufferPos + BufferSize, largeObject.RawSize);
            int toRead = (int) System.Math.Min((long) count, bufferEnd - position);
            if (toRead <= 0) {
                return 0;
            }
            int hasRead = 0;
            while (toRead > 0) {
                Array.Copy(readBuf, p, buffer, offset, toRead);
                hasRead += toRead;
                p += toRead;
                offset += toRead;
                count -= toRead;
                position += toRead;
                if (p >= BufferSize) {
                    FillBuffer(readBufferPos + BufferSize);
                    p -= BufferSize;
                }
                bufferEnd = System.Math.Min(readBufferPos + BufferSize, largeObject.RawSize);
                toRead = (int) System.Math.Min((long)count, bufferEnd - position);
            }

            return hasRead;
        }