using System;
using System.IO;

namespace bareFTP.Protocol.Sftp.Streams
{
	
	public abstract class InputStream : Stream
	{
		
		public virtual int Read(byte[] buffer)
		{
			return this.Read(buffer, 0, buffer.Length);
		}
		
		
		public override void WriteByte(byte value)
		{
		}

		public override void Write(byte[] buffer, int offset, int count)
		{
		}

		public override bool CanRead
		{
			get
			{
				return true;
			}
		}
		public override bool CanWrite
		{
			get
			{
				return false;
			}
		}
		
		public override bool CanSeek
		{
			get
			{
				return false;
			}
		}
		public override void Flush()
		{
			
		}
		public override long Length
		{
			get
			{
				return 0;
			}
		}
		public override long Position
		{
			get
			{
				return this.Position;
			}
			set
			{
			}
		}
		public override void SetLength(long value)
		{			
		}
		public override long Seek(long offset, SeekOrigin origin)
		{
			return 0;
		}

		public long skip(long len)
		{
			//Seek doesn't work
			//return Seek(offset, IO.SeekOrigin.Current);
			
			//Console.WriteLine("HHAAAAALOOOOOOOOOOO!!!");
			
			//this.Position = this.Position + len;
			//return len;
			
			
			
			
			int i=0;
			int count = 0;
			byte[] buf = new byte[len];
			while(len>0)
			{
				i=Read(buf, count, (int)len);//tamir: possible lost of pressision
				if(i<=0)
				{
					throw new Exception("inputstream is closed");
					//return (s-foo)==0 ? i : s-foo;
				}
				count+=i;
				len-=i;
			}
			return count;
			
		}
	}
}
