///<summary> /// Load the buffer with a file ///</summary> public void Load(string filename) { if (reader != null) { reader.Close(); } OperatingSystem os = Environment.OSVersion; PlatformID pid = os.Platform; if (pid == PlatformID.Unix) { UnixFileInfo fsInfo = new UnixFileInfo(filename); if (!fsInfo.Exists) { throw new FileNotFoundException(fsInfo.FullName); } // get the size of the file or device if (fsInfo.IsRegularFile) { FileLength = fsInfo.Length; isResizable = true; } else if (fsInfo.IsBlockDevice) { UnixStream unixStream = fsInfo.OpenRead(); ioctl(unixStream.Handle, BLKGETSIZE64, ref FileLength); unixStream.Close(); isResizable = false; } else { throw new NotSupportedException("File object isn't a regular or block device."); } } Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read); if (stream.CanSeek == false) { throw new NotSupportedException("File object doesn't support seeking."); } if (pid != PlatformID.Unix) { FileLength = stream.Seek(0, SeekOrigin.End); stream.Seek(0, SeekOrigin.Begin); isResizable = false; } reader = new BinaryReader(stream); winOccupied = reader.Read(window, 0, window.Length); winOffset = 0; }
public override void Close() { if (_file == null) { return; } InternalLogger.Trace("Closing '{0}'", FileName); _file.Close(); _file = null; FileTouched(); }
protected override void OnClose() { //this never happens.... System.Diagnostics.Debug.Assert(_socket != null); if (orig_mtu != 0) { OpenSocket(orig_mtu); } _socket.Close(); _socket = null; }
///<summary> /// Load the buffer with a file ///</summary> public void Load(string filename) { if (reader != null) { reader.Close(); } #if ENABLE_UNIX_SPECIFIC UnixFileInfo fsInfo = new UnixFileInfo(filename); if (!fsInfo.Exists) { throw new FileNotFoundException(fsInfo.FullName); } // get the size of the file or device if (fsInfo.IsRegularFile) { FileLength = fsInfo.Length; isResizable = true; } else if (fsInfo.IsBlockDevice) { UnixStream unixStream = fsInfo.OpenRead(); ioctl(unixStream.Handle, BLKGETSIZE64, ref FileLength); unixStream.Close(); isResizable = false; } else { throw new NotSupportedException("File object isn't a regular or block device."); } #endif Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); if (stream.CanSeek == false) { throw new NotSupportedException("File object doesn't support seeking."); } #if !ENABLE_UNIX_SPECIFIC FileLength = stream.Seek(0, SeekOrigin.End); stream.Seek(0, SeekOrigin.Begin); isResizable = false; #endif reader = new BinaryReader(stream); winOccupied = reader.Read(window, 0, window.Length); winOffset = 0; }
public void Close() { lock (this) { if (closed) { return; } closed = true; Cancel.Cancel(); Input.Close(); Output.Close(); Error.Close(); } }
public void Close() { if (stdin_stream != null) { stdin_stream.Close(); } if (stdout_stream != null) { stdout_stream.Close(); } if (stderr_stream != null) { stderr_stream.Close(); } }
/// <summary> /// Closes this instance. /// </summary> public override void Close() { if (_file == null) { return; } InternalLogger.Trace("Closing '{0}'", FileName); try { _file?.Close(); } catch (Exception ex) { // Swallow exception as the file-stream now is in final state (broken instead of closed) InternalLogger.Warn(ex, "Failed to close file '{0}'", FileName); System.Threading.Thread.Sleep(1); // Artificial delay to avoid hammering a bad file location } finally { _file = null; } }