public static unsafe iPhoneFile Open(iPhone phone, string path, FileAccess openmode) { long num2; OpenMode none = OpenMode.None; switch (openmode) { case FileAccess.Read: none = OpenMode.Read; break; case FileAccess.Write: none = OpenMode.Write; break; case FileAccess.ReadWrite: throw new NotImplementedException("Read+Write not (yet) implemented"); } string str = phone.FullPath(phone.CurrentDirectory, path); int num = MobileDevice.AFCFileRefOpen(phone.AFCHandle, str, (int) none, 0, out num2); if (num != 0) { phone.ReConnect(); throw new IOException("AFCFileRefOpen failed with error " + num.ToString()); } return new iPhoneFile(phone, num2, none); }
protected void ValidateAccess(FileAccess access) { if (!_access.HasFlag(access)) { throw new InvalidOperationException($"The current {GetType().Name} does not support {access.ToString("G")} access."); } }
/** * open file. * @param void. * @return void. */ public bool Open(string strFileName, FileMode eMode, FileAccess eAccess) { if (string.IsNullOrEmpty(strFileName)) { return false; } if ((FileMode.Open == eMode) && !File.Exists(strFileName)) { return false; } try { m_cStream = new FileStream(strFileName, eMode, eAccess); } catch (Exception cEx) { Console.Write(cEx.Message); } if (null == m_cStream) { return false; } m_bOpen = true; return true; }
internal FileStream (IntPtr handle, FileAccess access, bool ownsHandle, int bufferSize, bool isAsync, bool isConsoleWrapper) { if (handle == MonoIO.InvalidHandle) throw new ArgumentException ("handle", Locale.GetText ("Invalid.")); Init (new SafeFileHandle (handle, false), access, ownsHandle, bufferSize, isAsync, isConsoleWrapper); }
public static FileStream OpenSequentialStream(string path, FileMode mode, FileAccess access, FileShare share) { var options = FileOptions.SequentialScan; if (concurrency > 0) { options |= FileOptions.Asynchronous; } #if MONO return new FileStream( path, mode, access, share, bufferSize, options ); #else if (unbuffered) { options |= NoBuffering; } else { return new FileStream(path, mode, access, share, bufferSize, options); } SafeFileHandle fileHandle = CreateFile(path, (int)access, share, IntPtr.Zero, mode, (int)options, IntPtr.Zero); if (fileHandle.IsInvalid) { throw new IOException(); } return new UnbufferedFileStream(fileHandle, access, bufferSize, (concurrency > 0)); #endif }
public static Stream CreateFile( string fileName, FileAccess fileAccess, FileShare fileShare, FileMode fileMode, FileAttributes flags) { // TODO: This is not quite right, but it's close. // var nativeAccess = fileAccess; if ((nativeAccess & FileAccess.Read) != 0) { nativeAccess &= ~FileAccess.Read; nativeAccess |= (FileAccess)GENERIC_READ; } if ((nativeAccess & FileAccess.Write) != 0) { nativeAccess &= ~FileAccess.Write; nativeAccess |= (FileAccess)GENERIC_WRITE; } var handle = _CreateFile(fileName, nativeAccess, fileShare, IntPtr.Zero, fileMode, flags, IntPtr.Zero); if (handle.IsInvalid) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } return new SimpleFileStream(handle); }
public StdioFileStream (string path, FileAccess access) { if (path == null) throw new ArgumentNullException ("path"); InitStream (Fopen (path, ToFopenMode (path, access)), true); InitCanReadWrite (access); }
public TransactionFileStream(string path, FileAccess fileAccess) { PATH = path; BACKED_UP_PATH = Path.Combine(new string[] { path + ORIGIN_CONSTANT }); LOG_PATH = Path.Combine(new string[] { path + FILE_FLAG_CONSTANT }); switch (fileAccess) { case FileAccess.Read: { fileStream = new FileStream(PATH, FileMode.OpenOrCreate, fileAccess); break; } case FileAccess.Write: { if (!File.Exists(path)) { File.Create(path); } if (!File.Exists(path) && File.Exists(BACKED_UP_PATH)) { recoverBackup(); } else { fileStream = new FileStream(LOG_PATH, FileMode.OpenOrCreate, fileAccess); } break; } default:{ throw new Exception(); } } }
/// <summary> /// Initializes a new instance of the Disk class. Differencing disks are supported. /// </summary> /// <param name="path">The path to the disk image</param> /// <param name="access">The access requested to the disk</param> public Disk(string path, FileAccess access) { DiskImageFile file = new DiskImageFile(path, access); _files = new List<DiscUtils.Tuple<DiskImageFile, Ownership>>(); _files.Add(new DiscUtils.Tuple<DiskImageFile, Ownership>(file, Ownership.Dispose)); ResolveFileChain(); }
internal ClusterStream(FatFileSystem fileSystem, FileAccess access, uint firstCluster, uint length) { _access = access; _reader = fileSystem.ClusterReader; _fat = fileSystem.Fat; _length = length; _knownClusters = new List<uint>(); if (firstCluster != 0) { _knownClusters.Add(firstCluster); } else { _knownClusters.Add(FatBuffer.EndOfChain); } if (_length == uint.MaxValue) { _length = DetectLength(); } _currentCluster = uint.MaxValue; _clusterBuffer = new byte[_reader.ClusterSize]; }
/// <summary> /// Loads the given file specified by PackagePath and /// returns the serialized UnrealPackage. /// </summary> public static UnrealPackage LoadPackage( string packagePath, IBufferDecoder decoder = null, FileAccess fileAccess = FileAccess.Read ) { var stream = new UPackageStream( packagePath, FileMode.Open, fileAccess ); var package = new UnrealPackage( stream ) {Decoder = decoder}; package.Deserialize( stream ); return package; }
public TableBinding(ScriptHostConfiguration config, TableBindingMetadata metadata, FileAccess access) : base(config, metadata, access) { if (string.IsNullOrEmpty(metadata.TableName)) { throw new ArgumentException("The table name cannot be null or empty."); } TableName = metadata.TableName; PartitionKey = metadata.PartitionKey; if (!string.IsNullOrEmpty(PartitionKey)) { _partitionKeyBindingTemplate = BindingTemplate.FromString(PartitionKey); } RowKey = metadata.RowKey; if (!string.IsNullOrEmpty(RowKey)) { _rowKeyBindingTemplate = BindingTemplate.FromString(RowKey); } _tableQuery = new TableQuery { TakeCount = metadata.Take ?? 50, FilterString = metadata.Filter }; }
/// <summary> /// File might be locked when attempting to open it. This will attempt to open the file the number of times specified by <paramref name="retry"/> /// </summary> /// <param name="filePath">The file to attempt to get a file stream for</param> /// <param name="retry">The number of times a file open should be attempted</param> /// <param name="fileMode">The file mode to use</param> /// <param name="fileAccess">The file access to use</param> /// <param name="fileShare">The file sharing to use</param> /// <returns>A file stream of the file</returns> /// <remarks> /// It attempt to open the file in increasingly longer periods and throw an exception if it cannot open it within the /// specified number of retries. /// </remarks> public Stream OpenFileStream(string filePath, int retry, FileMode fileMode, FileAccess fileAccess, FileShare fileShare) { var delay = 0; for(var i = 0; i < retry; i++) { try { var stream = new FileStream(filePath, fileMode, fileAccess, fileShare); return stream; } catch(DirectoryNotFoundException) { CreateDirectoryStructure(filePath); } catch(FileNotFoundException) { throw; } catch(IOException) { delay += 100; if(i == retry) throw; } Thread.Sleep(delay); } //We will never get here throw new IOException(string.Format("Unable to open file '{0}'", filePath)); }
public Binding(string name, string type, FileAccess fileAccess, bool isTrigger) { Name = name; Type = type; FileAccess = fileAccess; IsTrigger = isTrigger; }
public Stream FileOpen(string filePath, FileMode fileMode, FileAccess fileAccess, FileShare fileShare) { #if WINDOWS_STORE_APP var folder = ApplicationData.Current.LocalFolder; if (fileMode == FileMode.Create || fileMode == FileMode.CreateNew) { return folder.OpenStreamForWriteAsync(filePath, CreationCollisionOption.ReplaceExisting).GetAwaiter().GetResult(); } else if (fileMode == FileMode.OpenOrCreate) { if (fileAccess == FileAccess.Read) return folder.OpenStreamForReadAsync(filePath).GetAwaiter().GetResult(); else { // Not using OpenStreamForReadAsync because the stream position is placed at the end of the file, instead of the beginning var f = folder.CreateFileAsync(filePath, CreationCollisionOption.OpenIfExists).AsTask().GetAwaiter().GetResult(); return f.OpenAsync(FileAccessMode.ReadWrite).AsTask().GetAwaiter().GetResult().AsStream(); } } else if (fileMode == FileMode.Truncate) { return folder.OpenStreamForWriteAsync(filePath, CreationCollisionOption.ReplaceExisting).GetAwaiter().GetResult(); } else { //if (fileMode == FileMode.Append) // Not using OpenStreamForReadAsync because the stream position is placed at the end of the file, instead of the beginning folder.CreateFileAsync(filePath, CreationCollisionOption.OpenIfExists).AsTask().GetAwaiter().GetResult().OpenAsync(FileAccessMode.ReadWrite).AsTask().GetAwaiter().GetResult().AsStream(); var f = folder.CreateFileAsync(filePath, CreationCollisionOption.OpenIfExists).AsTask().GetAwaiter().GetResult(); return f.OpenAsync(FileAccessMode.ReadWrite).AsTask().GetAwaiter().GetResult().AsStream(); } #else return File.Open(filePath, fileMode, fileAccess, fileShare); #endif }
/// <include file='doc\NetworkStream.uex' path='docs/doc[@for="NetworkStream.NetworkStream3"]/*' /> public NetworkStream(Socket socket, FileAccess access, bool ownsSocket) { if (socket == null) { throw new ArgumentNullException("socket"); } InitNetworkStream(socket, access); m_OwnsSocket = ownsSocket; }
private static extern SafeFileHandle CreateFile(string filename, FileAccess desiredAccess, FileShare shareMode, IntPtr attributes, FileMode creationDisposition, uint flagsAndAttributes = 0, IntPtr templateFile = default(IntPtr));
protected ShapefileWriter(string path, ShapefileHeader header, FileMode fileMode, FileAccess fileAccess) { _writerShape = new BinaryWriter(new FileStream(path, fileMode, fileAccess)); _writerIndex = new BinaryWriter(new FileStream(Path.ChangeExtension(path, ".shx"), fileMode, fileAccess)); _header = header; }
public DiskExtent(ExtentDescriptor descriptor, long diskOffset, FileLocator fileLocator, FileAccess access) { _descriptor = descriptor; _diskOffset = diskOffset; _fileLocator = fileLocator; _access = access; }
/// <summary> /// Utility function to update a grfMode value based on FileAccess. /// 6/12/2002: Fixes bug #4938, 4960, 5096, 4858 /// </summary> /// <param name="access">FileAccess we're translating</param> /// <param name="grfMode">Mode flag parameter to modify</param> // <SecurityNote> // SecurityTreatAsSafe: Makes NO call to security suppressed unmanaged code // </SecurityNote> internal static void UpdateModeFlagFromFileAccess( FileAccess access, ref int grfMode ) { // Supporting write-only scenarios container-wide gets tricky and it // is rarely used. Don't support it for now because of poor // cost/benefit ratio. if( FileAccess.Write == access ) throw new NotSupportedException( SR.Get(SRID.WriteOnlyUnsupported)); // Generate STGM from FileAccess // STGM_READ is 0x00, so it's "by default" if( ( FileAccess.ReadWrite == (access & FileAccess.ReadWrite) ) || ( (FileAccess.Read | FileAccess.Write) == (access & (FileAccess.Read | FileAccess.Write))) ) { grfMode |= SafeNativeCompoundFileConstants.STGM_READWRITE; } else if( FileAccess.Write == (access & FileAccess.Write) ) { grfMode |= SafeNativeCompoundFileConstants.STGM_WRITE; } else if( FileAccess.Read != (access & FileAccess.Read)) { throw new ArgumentException( SR.Get(SRID.FileAccessInvalid)); } }
public int CreateFile(string filename, FileAccess access, FileShare share, FileMode mode, FileOptions options, DokanFileInfo info) { Trace.WriteLine(string.Format("CreateFile FILENAME({0}) ACCESS({1}) SHARE({2}) MODE({3})", filename, access, share, mode)); if (mode == FileMode.Create || mode == FileMode.OpenOrCreate || mode == FileMode.CreateNew) { // we want to write a file var fileRef = Extensions.GetFileReference(root, filename.ToFileString()); fileRef.Create(0); return 0; } if (share == FileShare.Delete) { return DeleteFile(filename, info); } if (GetFileInformation(filename, new FileInformation(), new DokanFileInfo(0)) == 0) { return 0; } else { return -DokanNet.ERROR_FILE_NOT_FOUND; } }
public OpenFileEventArgs(VirtualRawPath virtualRawPath, IntPtr handle, FileAccess fileAccess) : base(virtualRawPath) { _handle = handle; _fileAccess = fileAccess; }
/// <summary> /// File might be locked when attempting to open it. This will attempt to open the file the number of times specified by <paramref name="retry"/> /// </summary> /// <param name="fileInfo">The file to attempt to get a file stream for</param> /// <param name="retry">The number of times a file open should be attempted</param> /// <param name="fileMode">The file mode to use</param> /// <param name="fileAccess">The file access to use</param> /// <param name="fileShare">The file sharing to use</param> /// <returns>A file stream of the file</returns> /// <remarks> /// It attempt to open the file in increasingly longer periods and throw an exception if it cannot open it within the /// specified number of retries. /// </remarks> public FileStream OpenFileStream(FileInfo fileInfo, int retry, FileMode fileMode, FileAccess fileAccess, FileShare fileShare) { var delay = 0; for (var i = 0; i < retry; i++) { try { var stream = new FileStream(fileInfo.FullName, fileMode, fileAccess, fileShare); return stream; } catch(FileNotFoundException) { throw; } catch (IOException) { delay += 100; if (i == retry) throw; } Thread.Sleep(delay); } //We will never get here throw new IOException("Unable to open file - " + fileInfo.FullName); }
static internal string ToString(string path, FileMode mode, FileAccess access, FileShare share) { // http://ee.php.net/fopen //'r' Open for reading only; place the file pointer at the beginning of the file. //'r+' Open for reading and writing; place the file pointer at the beginning of the file. //'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. //'w+' Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. //'a' Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it. //'a+' Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it. //'x' Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call. //'x+' Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call. if (mode == FileMode.OpenOrCreate) { if (access == FileAccess.Write) { if (File.Exists(path)) return "r+b"; else return "x+b"; } if (access == FileAccess.Read) { if (File.Exists(path)) return "rb"; else return "xb"; } } var e = new { mode, access, share }; throw new NotImplementedException(e.ToString()); }
internal static void FileAccess(FileMode fileMode, FileAccess fileAccess) { // exception if: // !write && append // !write && create // !write && createNew // !write && truncate var noWrite = (fileAccess & System.IO.FileAccess.Write) == 0; if (noWrite && fileMode == FileMode.CreateNew) throw new ArgumentException(string.Format( "Can only open files in {0} mode when requesting FileAccess.Write access.", fileMode)); if (noWrite && fileMode == FileMode.Truncate) throw new IOException("Cannot truncate a file if file mode doesn't include WRITE."); // or if: // readwrite && append // read && append if (fileAccess == System.IO.FileAccess.Read && fileMode == FileMode.Append) throw new ArgumentException("Cannot open file in read-mode when having FileMode.Append"); //if ( // ((fileMode == FileMode.Append) && fileAccess != FileAccess.Write) || // ((fileMode == FileMode.CreateNew || fileMode == FileMode.Create || fileMode == FileMode.Truncate) // && (fileAccess != FileAccess.Write && fileAccess != FileAccess.ReadWrite)) || // false //((Exists && fileMode == FileMode.OpenOrCreate && fileAccess == FileAccess.Write)) // ) }
/// <summary> /// Represents a single EWF file. /// </summary> /// <param name="path">Path to the ewf file.</param> /// <param name="access">Desired access.</param> public DiskImageFile(string path, FileAccess access) { if (_content == null) { _content = new EWFStream(path); } }
/// <summary> /// Instantiates a non-strict Visio 2003 DatadiagramML (VDX file) adapter for reading from an URI. /// It is possible to load only a selection of pages from the Visio file. /// </summary> /// <remarks> /// Only READ mode is supported! /// </remarks> /// <param name="uriVDX">The URI to read from.</param> /// <param name="mode">The FileAccess mode.</param> /// <param name="pageNames">An optional list of page names.</param> public Visio2003Adapter(string uriVDX, FileAccess mode, params string[] pageNames) { // manually open the file so that we can specify share permissions (thanks Eric Lyons!) using(Stream streamVDX = new FileStream(uriVDX, FileMode.Open, mode, FileShare.ReadWrite)) { Init(new XPathDocument(streamVDX), mode, false, pageNames); } }
public Stream OpenFile(FileSystemPath path, FileAccess access) { var fs = GetFirst(path); if (fs == null) throw new FileNotFoundException(); return fs.OpenFile(path, access); }
public int CreateFile(String filename, FileAccess access, FileShare share, FileMode mode, FileOptions options, DokanFileInfo info) { string path = GetPath(filename); try { if (Directory.Exists(path)) { info.IsDirectory = true; } else { FileStream fs = new FileStream(path, mode, access, share, 8, options); fs.Close(); } //Console.WriteLine("Create file: {0}\t access: {1}", filename, access); return DokanNet.DOKAN_SUCCESS; } catch (Exception e) { return -DokanNet.DOKAN_ERROR; } }
public FileStream(string path, System.IO.FileMode mode, FileAccess access, FileShare share, int bufferSize) : this(path, mode, access, share, bufferSize, DefaultUseAsync) { }
internal SyncWindowsFileStreamStrategy(string path, FileMode mode, FileAccess access, FileShare share, FileOptions options, long preallocationSize) : base(path, mode, access, share, options, preallocationSize) { }
public FileStream(string name, FileMode mode, FileAccess access, FileShare share) : this(name, mode, access, share, DefaultBufferSize, false, FileOptions.None) { }
public FileStream(string name, FileMode mode, FileAccess access) : this(name, mode, access, access == FileAccess.Write ? FileShare.None : FileShare.Read, DefaultBufferSize, false, false) { }
public static FileStream Open(String path, FileMode mode, FileAccess access, FileShare share) { return(new FileStream(path, mode, access, share)); }
public static FileStream Open(String path, FileMode mode, FileAccess access) { return(Open(path, mode, access, FileShare.None)); }
internal SyncWindowsFileStreamStrategy(SafeFileHandle handle, FileAccess access) : base(handle, access) { }
public Viewer(System.Windows.Threading.Dispatcher dispatcher) { ViewerEventer = new Eventer(dispatcher); FileInfo = new FileAccess(); }
/// <summary> /// Creates a stream over a SafeBuffer. /// </summary> public UnmanagedMemoryStream(SafeBuffer buffer, long offset, long length, FileAccess access) { Initialize(buffer, offset, length, access); }
/// <summary> /// Creates a pair of connected NetworkStreams and invokes the provided <paramref name="func"/> /// with them as arguments. /// </summary> private static async Task RunWithConnectedNetworkStreamsAsync(Func <NetworkStream, NetworkStream, Task> func, FileAccess serverAccess = FileAccess.ReadWrite, FileAccess clientAccess = FileAccess.ReadWrite) { var listener = new TcpListener(IPAddress.Loopback, 0); try { listener.Start(1); var clientEndpoint = (IPEndPoint)listener.LocalEndpoint; using (var client = new TcpClient(clientEndpoint.AddressFamily)) { Task <TcpClient> remoteTask = listener.AcceptTcpClientAsync(); Task clientConnectTask = client.ConnectAsync(clientEndpoint.Address, clientEndpoint.Port); await Task.WhenAll(remoteTask, clientConnectTask); using (TcpClient remote = remoteTask.Result) using (NetworkStream serverStream = new NetworkStream(remote.Client, serverAccess, ownsSocket: true)) using (NetworkStream clientStream = new NetworkStream(client.Client, clientAccess, ownsSocket: true)) { await func(serverStream, clientStream); } } } finally { listener.Stop(); } }
public static unsafe UnmanagedMemoryStream OpenBuffer(IntPtr buffer, int length, FileAccess access) { return(new UnmanagedMemoryStream((byte *)buffer, length, length, access)); }
public override FileStream Open(string fullPath, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options, FileStream parent) { return(new FileStream(fullPath, mode, access, share, bufferSize, options)); }
public Stream Open(string path, FileAccess access) { return(Open(path, FileMode.OpenOrCreate, access)); }
public unsafe UnmanagedMemoryStream(byte *pointer, long length, long capacity, FileAccess access) { Initialize(pointer, length, capacity, access); }
public Stream GetFileStream(string path, FileMode mode, FileAccess access, FileShare share) { return(new FileStream(path, mode, access, share)); }
public Stream Open(string path, FileMode mode, FileAccess access) { DirInfo di = FindInfo(path); if (di != null && !(di is FileInfo)) { throw new FileNotFoundException(string.Format("Could not find file '{0}'.", path)); } switch (mode) { case FileMode.Append: if (access == FileAccess.Read) { throw new IOException("Appending requires writing access."); } if (di == null) { goto case FileMode.CreateNew; } break; case FileMode.Create: if (di == null) { goto case FileMode.CreateNew; } else { goto case FileMode.Truncate; } case FileMode.CreateNew: if (di != null) { throw new IOException("File already exists."); } StringCollection sa = new StringCollection(ResolvePath(path)); string s = sa[sa.Count - 1]; sa.RemoveAt(sa.Count - 1); di = FindInfo("\\" + string.Join("\\", sa.ToArray())); if (di == null) { throw new IOException("Path does not exist."); } di = new FileInfo(this, s, Reserve(), di.Index); entries.Add(di); break; case FileMode.Open: if (di == null) { throw new FileNotFoundException(string.Format("Could not find file '{0}'.", path)); } break; case FileMode.OpenOrCreate: if (di == null) { goto case FileMode.CreateNew; } else { break; } case FileMode.Truncate: ((FileInfo)di).Length = 0; break; } Stream st = new AStream((FileInfo)di, access); if (mode == FileMode.Append) { st.Position = st.Length; } return(st); }
public GptContext(string device, FileAccess fileAccess, uint bytesPerSector = DefaultBytesPerSector, uint chunkSize = DefaultChunkSize) : this( new DeviceStream(device, fileAccess), bytesPerSector) { }
public override Stream OpenStream(FileAccess access) { return(new FileStream(_file, access.HasFlag(FileAccess.Read) ? FileMode.Open : FileMode.Create, access, FileShare.None)); }
public static extern IntPtr CreateFile(string lpFileName, FileAccess dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, CreationDisposition dwCreationDisposition, FileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile);
public UnbufferedFileStream(SafeFileHandle fileHandle, FileAccess access, int bufferSize, bool isAsync) : base(fileHandle, access, bufferSize, isAsync) => this.fileHandle = fileHandle;
public Stream Open(FileMode fileMode, FileAccess fileAccess, FileShare fileShare) { return(new MemoryStream(Encoding.UTF8.GetBytes(content))); }
public static FileStream CreateFile(string filePath, FileAccess fileAccess, FileShare fileShare) { CreateDirectoryIfNotExist(Path.GetDirectoryName(filePath)); return(File.Open(filePath, FileMode.Create, fileAccess, fileShare)); }
public FileStream(string path, System.IO.FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options) { Init(path, mode, access, share, bufferSize, options); }
public Stream CreateFileStream(string filename, FileMode mode, FileAccess access, FileShare share) { return(new FileStream(filename, mode, access, share)); }
public FileStream(Microsoft.Win32.SafeHandles.SafeFileHandle handle, FileAccess access) : this(handle, access, DefaultBufferSize) { }
private void Init(String path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options) { if (path == null) { throw new ArgumentNullException(nameof(path), SR.ArgumentNull_Path); } if (path.Length == 0) { throw new ArgumentException(SR.Argument_EmptyPath, nameof(path)); } // don't include inheritable in our bounds check for share FileShare tempshare = share & ~FileShare.Inheritable; String badArg = null; if (mode < FileMode.CreateNew || mode > FileMode.Append) { badArg = "mode"; } else if (access < FileAccess.Read || access > FileAccess.ReadWrite) { badArg = "access"; } else if (tempshare < FileShare.None || tempshare > (FileShare.ReadWrite | FileShare.Delete)) { badArg = "share"; } if (badArg != null) { throw new ArgumentOutOfRangeException(badArg, SR.ArgumentOutOfRange_Enum); } // NOTE: any change to FileOptions enum needs to be matched here in the error validation if (options != FileOptions.None && (options & ~(FileOptions.WriteThrough | FileOptions.Asynchronous | FileOptions.RandomAccess | FileOptions.DeleteOnClose | FileOptions.SequentialScan | FileOptions.Encrypted | (FileOptions)0x20000000 /* NoBuffering */)) != 0) { throw new ArgumentOutOfRangeException(nameof(options), SR.ArgumentOutOfRange_Enum); } if (bufferSize <= 0) { throw new ArgumentOutOfRangeException(nameof(bufferSize), SR.ArgumentOutOfRange_NeedPosNum); } // Write access validation if ((access & FileAccess.Write) == 0) { if (mode == FileMode.Truncate || mode == FileMode.CreateNew || mode == FileMode.Create || mode == FileMode.Append) { // No write access, mode and access disagree but flag access since mode comes first throw new ArgumentException(SR.Format(SR.Argument_InvalidFileModeAndAccessCombo, mode, access), nameof(access)); } } string fullPath = Path.GetFullPath(path); if ((access & FileAccess.Read) != 0 && mode == FileMode.Append) { throw new ArgumentException(SR.Argument_InvalidAppendMode, nameof(access)); } this._innerStream = FileSystem.Current.Open(fullPath, mode, access, share, bufferSize, options, this); }
public FileStream(string name, FileMode mode, FileAccess access, FileShare share, int bufferSize, bool isAsync) : this(name, mode, access, share, bufferSize, isAsync, FileOptions.None) { }
public FileStream(string path, System.IO.FileMode mode, FileAccess access, FileShare share, int bufferSize, bool useAsync) : this(path, mode, access, share, bufferSize, useAsync ? FileOptions.Asynchronous : FileOptions.None) { }
public FakeFileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options) : base(path, mode, access, share, bufferSize, options) { }
public FileStream(string path, System.IO.FileMode mode, FileAccess access) : this(path, mode, access, DefaultShare, DefaultBufferSize, DefaultUseAsync) { }
/// <summary> /// Initialize a filestream from and input and/or output stream. /// </summary> private FileStream(RandomAccessFile file, FileAccess access) { if (file == null) throw new ArgumentNullException("file"); this.file = file; this.access = access; }