#region Copyright 2010-2014 by Roger Knapp, Licensed under the Apache License, Version 2.0 /* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #endregion using System; using System.Collections.Generic; using System.IO; namespace CSharpTest.Net.IO { /// /// Provides a base-class for a stream object that is neither readable or writable /// [System.Diagnostics.DebuggerNonUserCode] public abstract class BaseStream : Stream { /// /// When overridden in a derived class, gets a value indicating whether the current stream supports reading. /// public override bool CanRead { get { return false; } } /// /// When overridden in a derived class, gets a value indicating whether the current stream supports seeking. /// public override bool CanSeek { get { return false; } } /// /// When overridden in a derived class, gets a value indicating whether the current stream supports writing. /// public override bool CanWrite { get { return false; } } /// /// When overridden in a derived class, gets the length in bytes of the stream. /// public override long Length { get { throw new NotSupportedException(); } } /// /// When overridden in a derived class, gets or sets the position within the current stream. /// public override long Position { get { throw new NotSupportedException(); } set { throw new NotSupportedException(); } } /// /// When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device. /// public override void Flush() { } /// /// When overridden in a derived class, sets the position within the current stream. /// public override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException(); } /// /// When overridden in a derived class, sets the length of the current stream. /// public override void SetLength(long value) { throw new NotSupportedException(); } /// /// When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read. /// public override int Read(byte[] buffer, int offset, int count) { throw new NotSupportedException(); } /// /// When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. /// public override void Write(byte[] buffer, int offset, int count) { throw new NotSupportedException(); } /// /// Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream. /// public override int ReadByte() { byte[] bytes = new byte[1]; return Read(bytes, 0, 1) == 1 ? bytes[0] : -1; } /// /// Writes a byte to the current position in the stream and advances the position within the stream by one byte. /// public override void WriteByte(byte value) { Write(new byte[] { value }, 0, 1); } } }