fCraft.BufferUtil.ReadAll C# (CSharp) 메소드

ReadAll() 공개 정적인 메소드

Reads a number of bytes from source that matches the length of destination byte array.
source or destination is null. The end of stream is reached before destination array was filled.
public static ReadAll ( [ source, [ destination ) : void
source [ Stream to read from.
destination [ Byte array to write to. Length of this array is used.
리턴 void
        public static void ReadAll( [NotNull] Stream source, [NotNull] byte[] destination ) {
            if( source == null ) throw new ArgumentNullException( "source" );
            if( destination == null ) throw new ArgumentNullException( "destination" );
            int bytesRead = 0;
            int bytesLeft = destination.Length;
            while( bytesLeft > 0 ) {
                int readPass = source.Read( destination, bytesRead, bytesLeft );
                if( readPass == 0 ) throw new EndOfStreamException();
                bytesRead += readPass;
                bytesLeft -= readPass;
            }
        }
    }