/* Copyright 2016-present MongoDB Inc.
*
* 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.
*/
using System;
using System.IO;
#if NET452
using System.Runtime.Remoting;
#endif
using System.Threading;
using System.Threading.Tasks;
namespace MongoDB.Driver.GridFS
{
///
/// Represents a Stream that delegates all of its operations to a wrapped Stream.
///
///
public class DelegatingStream : Stream
{
// private fields
private readonly Stream _wrappedStream;
// constructors
///
/// Initializes a new instance of the class.
///
/// The wrapped stream.
internal DelegatingStream(Stream wrappedStream)
{
_wrappedStream = wrappedStream;
}
// properties
///
public override bool CanRead
{
get { return _wrappedStream.CanRead; }
}
///
public override bool CanSeek
{
get { return _wrappedStream.CanSeek; }
}
///
public override bool CanTimeout
{
get { return _wrappedStream.CanTimeout; }
}
///
public override bool CanWrite
{
get { return _wrappedStream.CanWrite; }
}
///
public override long Length
{
get { return _wrappedStream.Length; }
}
///
public override long Position
{
get { return _wrappedStream.Position; }
set { _wrappedStream.Position = value; }
}
///
public override int ReadTimeout
{
get { return _wrappedStream.ReadTimeout; }
set { _wrappedStream.ReadTimeout = value; }
}
///
public override int WriteTimeout
{
get { return _wrappedStream.WriteTimeout; }
set { _wrappedStream.WriteTimeout = value; }
}
// methods
#if NET452
///
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
return _wrappedStream.BeginRead(buffer, offset, count, callback, state);
}
#endif
#if NET452
///
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
return _wrappedStream.BeginWrite(buffer, offset, count, callback, state);
}
#endif
#if NET452
///
public override void Close()
{
_wrappedStream.Close();
}
#endif
///
public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
{
return _wrappedStream.CopyToAsync(destination, bufferSize, cancellationToken);
}
#if NET452
///
public override ObjRef CreateObjRef(Type requestedType)
{
return _wrappedStream.CreateObjRef(requestedType);
}
#endif
#if NET452
///
[Obsolete("Not supported by DelegatingStream.")]
protected override WaitHandle CreateWaitHandle()
{
throw new NotSupportedException();
}
#endif
///
protected override void Dispose(bool disposing)
{
if (disposing)
{
_wrappedStream.Dispose();
}
}
#if NET452
///
public override int EndRead(IAsyncResult asyncResult)
{
return _wrappedStream.EndRead(asyncResult);
}
#endif
#if NET452
///
public override void EndWrite(IAsyncResult asyncResult)
{
_wrappedStream.EndWrite(asyncResult);
}
#endif
///
public override bool Equals(object obj)
{
return _wrappedStream.Equals(obj);
}
///
public override void Flush()
{
_wrappedStream.Flush();
}
///
public override Task FlushAsync(CancellationToken cancellationToken)
{
return _wrappedStream.FlushAsync(cancellationToken);
}
///
public override int GetHashCode()
{
return _wrappedStream.GetHashCode();
}
#if NET452
///
public override object InitializeLifetimeService()
{
return _wrappedStream.InitializeLifetimeService();
}
#endif
#if NET452
///
[Obsolete("Not supported by DelegatingStream.")]
protected override void ObjectInvariant()
{
throw new NotSupportedException();
}
#endif
///
public override int Read(byte[] buffer, int offset, int count)
{
return _wrappedStream.Read(buffer, offset, count);
}
///
public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
return _wrappedStream.ReadAsync(buffer, offset, count, cancellationToken);
}
///
public override int ReadByte()
{
return _wrappedStream.ReadByte();
}
///
public override long Seek(long offset, SeekOrigin origin)
{
return _wrappedStream.Seek(offset, origin);
}
///
public override void SetLength(long value)
{
_wrappedStream.SetLength(value);
}
///
public override string ToString()
{
return _wrappedStream.ToString();
}
///
public override void Write(byte[] buffer, int offset, int count)
{
_wrappedStream.Write(buffer, offset, count);
}
///
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
return _wrappedStream.WriteAsync(buffer, offset, count, cancellationToken);
}
///
public override void WriteByte(byte value)
{
_wrappedStream.WriteByte(value);
}
}
}