mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-13 05:25:00 +00:00
Especially for streams, it is more appropriate to throw NotSupportedException instead of NotImplementedException. Usually consumers of streams expect NotSupportedException to handle errors. There are other places that also use NotImplementedException but I didn't examine them for now. I only modified stream classes in SharpCompress.IO. For reference about this best practise, please see these articles: http://blogs.msdn.com/b/brada/archive/2004/07/29/201354.aspx http://blogs.msdn.com/b/jaredpar/archive/2008/12/12/notimplementedexception-vs-notsupportedexception.aspx
68 lines
1.6 KiB
C#
68 lines
1.6 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace SharpCompress.IO
|
|
{
|
|
internal class CountingWritableSubStream : Stream
|
|
{
|
|
private Stream writableStream;
|
|
|
|
internal CountingWritableSubStream(Stream stream)
|
|
{
|
|
writableStream = stream;
|
|
}
|
|
|
|
public uint Count { get; private set; }
|
|
|
|
public override bool CanRead
|
|
{
|
|
get { return false; }
|
|
}
|
|
|
|
public override bool CanSeek
|
|
{
|
|
get { return false; }
|
|
}
|
|
|
|
public override bool CanWrite
|
|
{
|
|
get { return true; }
|
|
}
|
|
|
|
public override void Flush()
|
|
{
|
|
}
|
|
|
|
public override long Length
|
|
{
|
|
get { throw new NotSupportedException(); }
|
|
}
|
|
|
|
public override long Position
|
|
{
|
|
get { throw new NotSupportedException(); }
|
|
set { throw new NotSupportedException(); }
|
|
}
|
|
|
|
public override int Read(byte[] buffer, int offset, int count)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
public override long Seek(long offset, SeekOrigin origin)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
public override void SetLength(long value)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
public override void Write(byte[] buffer, int offset, int count)
|
|
{
|
|
writableStream.Write(buffer, offset, count);
|
|
Count += (uint) count;
|
|
}
|
|
}
|
|
} |