Amazon.Runtime.Internal.Util.WrapperStream.SearchWrappedStream C# (CSharp) Метод

SearchWrappedStream() публичный Метод

public SearchWrappedStream ( bool>.Func condition ) : Stream
condition bool>.Func
Результат Stream
        public Stream SearchWrappedStream(Func<Stream, bool> condition)
        {
            Stream baseStream = this;
            do
            {
                if (condition(baseStream))
                    return baseStream;

                if (!(baseStream is WrapperStream))
                    return null;

                baseStream = (baseStream as WrapperStream).BaseStream;
            } while (baseStream != null);

            return baseStream;
        }

Same methods

WrapperStream::SearchWrappedStream ( Stream stream, bool>.Func condition ) : Stream

Usage Example

Пример #1
0
 /// <summary>
 /// Calculates the given checksum for a marshalled request
 /// </summary>
 /// <param name="algorithm">Checksum algorithm to calculate</param>
 /// <param name="request">Request whose content to calculate the checksum for</param>
 /// <returns>Calculated checksum for the given request</returns>
 private static string CalculateChecksumForRequest(HashAlgorithm algorithm, IRequest request)
 {
     if (request.ContentStream != null)
     {
         var seekableStream = WrapperStream.SearchWrappedStream(request.ContentStream, s => s.CanSeek);
         if (seekableStream != null)
         {
             var position      = seekableStream.Position;
             var checksumBytes = algorithm.ComputeHash(seekableStream);
             seekableStream.Seek(position, SeekOrigin.Begin);
             return(Convert.ToBase64String(checksumBytes));
         }
         else
         {
             throw new ArgumentException("Request must have a seekable content stream to calculate checksum");
         }
     }
     else if (request.Content != null)
     {
         var checksumBytes = algorithm.ComputeHash(request.Content);
         return(Convert.ToBase64String(checksumBytes));
     }
     else // request doesn't have content
     {
         return(string.Empty);
     }
 }
All Usage Examples Of Amazon.Runtime.Internal.Util.WrapperStream::SearchWrappedStream