C# 클래스 NetworkCommsDotNet.Tools.StreamTools.ThreadSafeStream

A wrapper around a stream to ensure it can be accessed in a thread safe way. The .net implementation of Stream.Synchronized is not suitable on its own.
상속: Stream, IDisposable
파일 보기 프로젝트 열기: MarcFletcher/NetworkComms.Net 1 사용 예제들

공개 메소드들

메소드 설명
CopyTo ( Stream destinationStream, long startPosition, long length, int writeBufferSize, double timeoutMSPerKBWrite = 1000, int minTimeoutMS = 500 ) : double

Copies data specified by start and length properties from internal stream to the provided stream.

Dispose ( ) : void

Disposes the internal stream if DiposeInnerStreamOnDispose is true. Use Close() to close the inner stream regardless of DiposeInnerStreamOnDispose.

Dispose ( bool forceDispose ) : void

Disposes the internal stream. If DiposeInnerStreamOnDispose is false, forceDispose must be true to dispose of the internal stream.

Flush ( ) : void
GetBuffer ( ) : byte[]

Attempts to return the buffer associated with the internal stream. In certain circumstances this is more efficient than copying the stream contents into a new buffer using ToArray. If the internal stream is not a memory stream will throw InvalidCastException. If access to the buffer is not allowed will throw an UnauthorizedAccessException.

MD5 ( ) : string

Return the MD5 hash of the current ThreadSafeStream as a string

MD5 ( long start, int length ) : string

Return the MD5 hash of part of the current ThreadSafeStream as a string

Read ( byte buffer, int offset, int count ) : int
Seek ( long offset, SeekOrigin origin ) : long
SetLength ( long value ) : void
ThreadSafeStream ( Stream stream ) : System

Create a thread safe stream. Once any actions are complete the stream must be correctly disposed by the user.

ThreadSafeStream ( Stream stream, bool closeStreamAfterSend ) : System

Create a thread safe stream.

ToArray ( int numberZeroBytesPrefex ) : byte[]

Returns data from entire Stream

ToArray ( long start, long length, int numberZeroBytesPrefix, int numberZeroBytesAppend ) : byte[]

Returns data from the specified portion of Stream

Write ( byte buffer, int offset, int count ) : void
Write ( byte buffer, long startPosition ) : void

Writes the provided buffer to the internal stream starting at the provided position within the internal stream

메소드 상세

CopyTo() 공개 메소드

Copies data specified by start and length properties from internal stream to the provided stream.
public CopyTo ( Stream destinationStream, long startPosition, long length, int writeBufferSize, double timeoutMSPerKBWrite = 1000, int minTimeoutMS = 500 ) : double
destinationStream Stream The destination stream to write to
startPosition long
length long
writeBufferSize int The buffer size to use for copying stream contents
timeoutMSPerKBWrite double The timouts in milliseconds per KB to write
minTimeoutMS int The minimum time allowed for any sized copy
리턴 double

Dispose() 공개 메소드

Disposes the internal stream if DiposeInnerStreamOnDispose is true. Use Close() to close the inner stream regardless of DiposeInnerStreamOnDispose.
public Dispose ( ) : void
리턴 void

Dispose() 공개 메소드

Disposes the internal stream. If DiposeInnerStreamOnDispose is false, forceDispose must be true to dispose of the internal stream.
public Dispose ( bool forceDispose ) : void
forceDispose bool If true the internal stream will be disposed regardless of value.
리턴 void

Flush() 공개 메소드

public Flush ( ) : void
리턴 void

GetBuffer() 공개 메소드

Attempts to return the buffer associated with the internal stream. In certain circumstances this is more efficient than copying the stream contents into a new buffer using ToArray. If the internal stream is not a memory stream will throw InvalidCastException. If access to the buffer is not allowed will throw an UnauthorizedAccessException.
public GetBuffer ( ) : byte[]
리턴 byte[]

MD5() 공개 메소드

Return the MD5 hash of the current ThreadSafeStream as a string
public MD5 ( ) : string
리턴 string

MD5() 공개 메소드

Return the MD5 hash of part of the current ThreadSafeStream as a string
public MD5 ( long start, int length ) : string
start long The start position in the stream
length int The length of stream to MD5
리턴 string

Read() 공개 메소드

public Read ( byte buffer, int offset, int count ) : int
buffer byte
offset int
count int
리턴 int

Seek() 공개 메소드

public Seek ( long offset, SeekOrigin origin ) : long
offset long
origin SeekOrigin
리턴 long

SetLength() 공개 메소드

public SetLength ( long value ) : void
value long
리턴 void

ThreadSafeStream() 공개 메소드

Create a thread safe stream. Once any actions are complete the stream must be correctly disposed by the user.
public ThreadSafeStream ( Stream stream ) : System
stream Stream The stream to make thread safe
리턴 System

ThreadSafeStream() 공개 메소드

Create a thread safe stream.
public ThreadSafeStream ( Stream stream, bool closeStreamAfterSend ) : System
stream Stream The stream to make thread safe.
closeStreamAfterSend bool If true the provided stream will be disposed once data has been written to the network. If false the stream must be disposed of correctly by the user
리턴 System

ToArray() 공개 메소드

Returns data from entire Stream
public ToArray ( int numberZeroBytesPrefex ) : byte[]
numberZeroBytesPrefex int If non zero will append N 0 value bytes to the start of the returned array
리턴 byte[]

ToArray() 공개 메소드

Returns data from the specified portion of Stream
public ToArray ( long start, long length, int numberZeroBytesPrefix, int numberZeroBytesAppend ) : byte[]
start long The start position of the desired bytes
length long The total number of desired bytes, not including the zero byte prefix and append parameters
numberZeroBytesPrefix int If non zero will append N 0 value bytes to the start of the returned array
numberZeroBytesAppend int If non zero will append N 0 value bytes to the end of the returned array
리턴 byte[]

Write() 공개 메소드

public Write ( byte buffer, int offset, int count ) : void
buffer byte
offset int
count int
리턴 void

Write() 공개 메소드

Writes the provided buffer to the internal stream starting at the provided position within the internal stream
public Write ( byte buffer, long startPosition ) : void
buffer byte
startPosition long
리턴 void