C# Class System.IO.FileStream

Inheritance: Stream
显示文件 Open project: dotnet/corefx Class Usage Examples

Private Properties

Property Type Description
AssertBufferInvariants void
AssertCanRead void
AsyncModeCopyToAsync Task
CheckFileCall int
CheckFileCall long
CompareExchangeCurrentOverlappedOwner FileStreamCompletionSource
FlushAsyncInternal Task
FlushInternalBuffer void
FlushOSBuffer void
FlushReadBuffer void
FlushWriteAsync Task
FlushWriteBuffer void
FlushWriteBuffer void
GetBuffer byte[]
GetDefaultIsAsync bool
GetLastWin32ErrorAndDisposeHandleIfInvalid int
GetLengthInternal long
GetSecAttrs Interop.Kernel32.SECURITY_ATTRIBUTES
GetSuppressBindHandle bool
Init void
InitFromHandle void
InternalAppend FileStream
InternalCreate FileStream
InternalOpen FileStream
LockInternal void
OnBufferAllocated void
OpenHandle System.IO.SafeFileHandle
PreOpenConfigurationFromOptions Interop.Sys.OpenFlags
PrepareForReading void
PrepareForWriting void
ReadAsyncInternal Task
ReadByteCore int
ReadCore int
ReadFileNative int
ReadNative int
ReadNativeAsync Task
SeekCore long
SetLengthCore void
SetLengthInternal void
TaskFromResultOrCache Task
UnlockInternal void
ValidateReadWriteArgs void
VerifyHandleIsSync void
VerifyOSHandlePosition void
WriteAsyncInternal Task
WriteByteCore void
WriteCore void
WriteFileNative int
WriteInternalCoreAsync Task
WriteNative void

Public Methods

Method Description
BeginRead ( byte array, int offset, int numBytes, AsyncCallback callback, object state ) : IAsyncResult
BeginWrite ( byte array, int offset, int numBytes, AsyncCallback callback, object state ) : IAsyncResult
CopyToAsync ( Stream destination, int bufferSize, CancellationToken cancellationToken ) : Task
EndRead ( IAsyncResult asyncResult ) : int
EndWrite ( IAsyncResult asyncResult ) : void
FileStream ( System.IO.SafeFileHandle handle, FileAccess access ) : System.Threading
FileStream ( System.IO.SafeFileHandle handle, FileAccess access, int bufferSize ) : System.Threading
FileStream ( System.IO.SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync ) : System.Threading
FileStream ( string path, FileMode mode ) : System.Threading
FileStream ( string path, FileMode mode, FileAccess access ) : System.Threading
FileStream ( string path, FileMode mode, FileAccess access, FileShare share ) : System.Threading
FileStream ( string path, FileMode mode, FileAccess access, FileShare share, int bufferSize ) : System.Threading
FileStream ( string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options ) : System.Threading
FileStream ( string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, bool useAsync ) : System.Threading
Flush ( ) : void

Clears buffers for this stream and causes any buffered data to be written to the file.

Flush ( bool flushToDisk ) : void

Clears buffers for this stream, and if is true, causes any buffered data to be written to the file.

FlushAsync ( CancellationToken cancellationToken ) : Task
Lock ( long position, long length ) : void
Read ( byte array, int offset, int count ) : int
ReadAsync ( byte buffer, int offset, int count, CancellationToken cancellationToken ) : Task
ReadByte ( ) : int
Seek ( long offset, SeekOrigin origin ) : long
SetLength ( long value ) : void

Sets the length of this stream to the given value.

Unlock ( long position, long length ) : void
Write ( byte array, int offset, int count ) : void
WriteAsync ( byte buffer, int offset, int count, CancellationToken cancellationToken ) : Task
WriteByte ( byte value ) : void

Protected Methods

Method Description
Dispose ( bool disposing ) : void

Private Methods

Method Description
AssertBufferInvariants ( ) : void
AssertCanRead ( byte buffer, int offset, int count ) : void
AsyncModeCopyToAsync ( Stream destination, int bufferSize, CancellationToken cancellationToken ) : Task
CheckFileCall ( int result, bool ignoreNotSupported = false ) : int
CheckFileCall ( long result, bool ignoreNotSupported = false ) : long
CompareExchangeCurrentOverlappedOwner ( FileStreamCompletionSource newSource, FileStreamCompletionSource existingSource ) : FileStreamCompletionSource
FlushAsyncInternal ( CancellationToken cancellationToken ) : Task
FlushInternalBuffer ( ) : void

Flushes the internal read/write buffer for this stream. If write data has been buffered, that data is written out to the underlying file. Or if data has been buffered for reading from the stream, the data is dumped and our position in the underlying file is rewound as necessary. This does not flush the OS buffer.

FlushOSBuffer ( ) : void
FlushReadBuffer ( ) : void

Dumps any read data in the buffer and rewinds our position in the stream, accordingly, as necessary.

FlushWriteAsync ( CancellationToken cancellationToken ) : Task
FlushWriteBuffer ( ) : void

Writes any data in the write buffer to the underlying stream and resets the buffer.

FlushWriteBuffer ( bool calledFromFinalizer = false ) : void
GetBuffer ( ) : byte[]

Gets the array used for buffering reading and writing. If the array hasn't been allocated, this will lazily allocate it.

GetDefaultIsAsync ( System.IO.SafeFileHandle handle ) : bool
GetLastWin32ErrorAndDisposeHandleIfInvalid ( bool throwIfInvalidHandle = false ) : int
GetLengthInternal ( ) : long
GetSecAttrs ( FileShare share ) : Interop.Kernel32.SECURITY_ATTRIBUTES
GetSuppressBindHandle ( System.IO.SafeFileHandle handle ) : bool
Init ( FileMode mode, FileShare share ) : void
InitFromHandle ( System.IO.SafeFileHandle handle ) : void
InternalAppend ( string path, int bufferSize = DefaultBufferSize, bool useAsync = DefaultIsAsync ) : FileStream
InternalCreate ( string path, int bufferSize = DefaultBufferSize, bool useAsync = DefaultIsAsync ) : FileStream
InternalOpen ( string path, int bufferSize = DefaultBufferSize, bool useAsync = DefaultIsAsync ) : FileStream
LockInternal ( long position, long length ) : void
OnBufferAllocated ( ) : void
OpenHandle ( FileMode mode, FileShare share, FileOptions options ) : System.IO.SafeFileHandle
PreOpenConfigurationFromOptions ( FileMode mode, FileAccess access, FileOptions options ) : Interop.Sys.OpenFlags

Translates the FileMode, FileAccess, and FileOptions values into flags to be passed when opening the file.

PrepareForReading ( ) : void

Validates that we're ready to read from the stream.

PrepareForWriting ( ) : void

Validates that we're ready to write to the stream, including flushing a read buffer if necessary.

ReadAsyncInternal ( byte array, int offset, int numBytes, CancellationToken cancellationToken ) : Task
ReadByteCore ( ) : int
ReadCore ( byte array, int offset, int count ) : int
ReadFileNative ( System.IO.SafeFileHandle handle, byte bytes, int offset, int count, NativeOverlapped overlapped, int &errorCode ) : int
ReadNative ( byte buffer, int offset, int count ) : int
ReadNativeAsync ( byte bytes, int offset, int numBytes, int numBufferedBytesRead, CancellationToken cancellationToken ) : Task
SeekCore ( long offset, SeekOrigin origin ) : long
SetLengthCore ( long value ) : void
SetLengthInternal ( long value ) : void
TaskFromResultOrCache ( int result ) : Task
UnlockInternal ( long position, long length ) : void
ValidateReadWriteArgs ( byte array, int offset, int count ) : void

Validates arguments to Read and Write and throws resulting exceptions.

VerifyHandleIsSync ( ) : void
VerifyOSHandlePosition ( ) : void

Verify that the actual position of the OS's handle equals what we expect it to. This will fail if someone else moved the UnixFileStream's handle or if our position updating code is incorrect.

WriteAsyncInternal ( byte array, int offset, int numBytes, CancellationToken cancellationToken ) : Task
WriteByteCore ( byte value ) : void
WriteCore ( byte buffer, int offset, int count ) : void
WriteFileNative ( System.IO.SafeFileHandle handle, byte bytes, int offset, int count, NativeOverlapped overlapped, int &errorCode ) : int
WriteInternalCoreAsync ( byte bytes, int offset, int numBytes, CancellationToken cancellationToken ) : Task
WriteNative ( byte array, int offset, int count ) : void

Unbuffered, writes a block of bytes to the file stream.

Method Details

BeginRead() public method

public BeginRead ( byte array, int offset, int numBytes, AsyncCallback callback, object state ) : IAsyncResult
array byte
offset int
numBytes int
callback AsyncCallback
state object
return IAsyncResult

BeginWrite() public method

public BeginWrite ( byte array, int offset, int numBytes, AsyncCallback callback, object state ) : IAsyncResult
array byte
offset int
numBytes int
callback AsyncCallback
state object
return IAsyncResult

CopyToAsync() public method

public CopyToAsync ( Stream destination, int bufferSize, CancellationToken cancellationToken ) : Task
destination Stream
bufferSize int
cancellationToken CancellationToken
return Task

Dispose() protected method

protected Dispose ( bool disposing ) : void
disposing bool
return void

EndRead() public method

public EndRead ( IAsyncResult asyncResult ) : int
asyncResult IAsyncResult
return int

EndWrite() public method

public EndWrite ( IAsyncResult asyncResult ) : void
asyncResult IAsyncResult
return void

FileStream() public method

public FileStream ( System.IO.SafeFileHandle handle, FileAccess access ) : System.Threading
handle System.IO.SafeFileHandle
access FileAccess
return System.Threading

FileStream() public method

public FileStream ( System.IO.SafeFileHandle handle, FileAccess access, int bufferSize ) : System.Threading
handle System.IO.SafeFileHandle
access FileAccess
bufferSize int
return System.Threading

FileStream() public method

public FileStream ( System.IO.SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync ) : System.Threading
handle System.IO.SafeFileHandle
access FileAccess
bufferSize int
isAsync bool
return System.Threading

FileStream() public method

public FileStream ( string path, FileMode mode ) : System.Threading
path string
mode FileMode
return System.Threading

FileStream() public method

public FileStream ( string path, FileMode mode, FileAccess access ) : System.Threading
path string
mode FileMode
access FileAccess
return System.Threading

FileStream() public method

public FileStream ( string path, FileMode mode, FileAccess access, FileShare share ) : System.Threading
path string
mode FileMode
access FileAccess
share FileShare
return System.Threading

FileStream() public method

public FileStream ( string path, FileMode mode, FileAccess access, FileShare share, int bufferSize ) : System.Threading
path string
mode FileMode
access FileAccess
share FileShare
bufferSize int
return System.Threading

FileStream() public method

public FileStream ( string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options ) : System.Threading
path string
mode FileMode
access FileAccess
share FileShare
bufferSize int
options FileOptions
return System.Threading

FileStream() public method

public FileStream ( string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, bool useAsync ) : System.Threading
path string
mode FileMode
access FileAccess
share FileShare
bufferSize int
useAsync bool
return System.Threading

Flush() public method

Clears buffers for this stream and causes any buffered data to be written to the file.
public Flush ( ) : void
return void

Flush() public method

Clears buffers for this stream, and if is true, causes any buffered data to be written to the file.
public Flush ( bool flushToDisk ) : void
flushToDisk bool
return void

FlushAsync() public method

public FlushAsync ( CancellationToken cancellationToken ) : Task
cancellationToken CancellationToken
return Task

Lock() public method

public Lock ( long position, long length ) : void
position long
length long
return void

Read() public method

public Read ( byte array, int offset, int count ) : int
array byte
offset int
count int
return int

ReadAsync() public method

public ReadAsync ( byte buffer, int offset, int count, CancellationToken cancellationToken ) : Task
buffer byte
offset int
count int
cancellationToken CancellationToken
return Task

ReadByte() public method

public ReadByte ( ) : int
return int

Seek() public method

public Seek ( long offset, SeekOrigin origin ) : long
offset long
origin SeekOrigin
return long

SetLength() public method

Sets the length of this stream to the given value.
public SetLength ( long value ) : void
value long The new length of the stream.
return void

Unlock() public method

public Unlock ( long position, long length ) : void
position long
length long
return void

Write() public method

public Write ( byte array, int offset, int count ) : void
array byte
offset int
count int
return void

WriteAsync() public method

public WriteAsync ( byte buffer, int offset, int count, CancellationToken cancellationToken ) : Task
buffer byte
offset int
count int
cancellationToken CancellationToken
return Task

WriteByte() public method

public WriteByte ( byte value ) : void
value byte
return void