jellyfin-server/Emby.Server.Implementations/IO/SharpCifs/Util/Sharpen/WrappedSystemStream.cs

140 lines
2.6 KiB
C#
Raw Normal View History

2017-04-02 00:36:06 +00:00
using System;
using System.IO;
namespace SharpCifs.Util.Sharpen
{
internal class WrappedSystemStream : Stream
2017-07-08 03:12:21 +00:00
{
private InputStream _ist;
private OutputStream _ost;
int _position;
int _markedPosition;
public WrappedSystemStream (InputStream ist)
{
this._ist = ist;
}
public WrappedSystemStream (OutputStream ost)
{
this._ost = ost;
}
public InputStream InputStream {
get { return _ist; }
}
public OutputStream OutputStream {
get { return _ost; }
}
2017-04-02 00:36:06 +00:00
public void Close() //remove `override`
{
2017-07-08 03:12:21 +00:00
if (_ist != null) {
2017-04-02 00:36:06 +00:00
//Stream.`Close` method deleted
2017-07-08 03:12:21 +00:00
//_ist.Close ();
2017-04-02 00:36:06 +00:00
_ist.Dispose();
2017-07-08 03:12:21 +00:00
}
if (_ost != null) {
2017-04-02 00:36:06 +00:00
//Stream.`Close` method deleted
2017-07-08 03:12:21 +00:00
//_ost.Close ();
2017-04-02 00:36:06 +00:00
_ost.Dispose();
2017-07-08 03:12:21 +00:00
}
}
public override void Flush ()
{
_ost.Flush ();
}
public override int Read (byte[] buffer, int offset, int count)
{
int res = _ist.Read (buffer, offset, count);
if (res != -1) {
_position += res;
return res;
}
return 0;
}
public override int ReadByte ()
{
int res = _ist.Read ();
if (res != -1)
_position++;
return res;
}
public override long Seek (long offset, SeekOrigin origin)
{
if (origin == SeekOrigin.Begin)
Position = offset;
else if (origin == SeekOrigin.Current)
Position = Position + offset;
else if (origin == SeekOrigin.End)
Position = Length + offset;
return Position;
}
public override void SetLength (long value)
{
throw new NotSupportedException ();
}
public override void Write (byte[] buffer, int offset, int count)
{
_ost.Write (buffer, offset, count);
_position += count;
}
public override void WriteByte (byte value)
{
_ost.Write (value);
_position++;
}
public override bool CanRead {
get { return (_ist != null); }
}
public override bool CanSeek {
get { return true; }
}
public override bool CanWrite {
get { return (_ost != null); }
}
public override long Length {
get { return _ist.Length; }
}
internal void OnMark (int nb)
{
_markedPosition = _position;
_ist.Mark (nb);
}
public override long Position {
get
{
if (_ist != null && _ist.CanSeek ())
return _ist.Position;
return _position;
}
set
{
if (value == _position)
return;
if (value == _markedPosition)
_ist.Reset ();
else if (_ist != null && _ist.CanSeek ()) {
_ist.Position = value;
}
else
throw new NotSupportedException ();
}
}
}
2017-04-02 00:36:06 +00:00
}