// CvsStream.cs
// Copyright (C) 2001 Mike Krueger
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// As a special exception, if you link this library with other files to
// produce an executable, this library does not by itself cause the
// resulting executable to be covered by the GNU General Public License.
// This exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
using System;
using System.IO;
using System.Text;
using System.Threading;
namespace CVS{
public class CvsStream : Stream
{
Stream baseStream;
public Stream BaseStream {
get {
return baseStream;
}
set {
baseStream = value;
}
}
public CvsStream(Stream baseStream)
{
this.baseStream = baseStream;
}
/// <summary>
/// I needed to implement the abstract member.
/// </summary>
public override bool CanRead {
get {
return baseStream.CanRead;
}
}
/// <summary>
/// I needed to implement the abstract member.
/// </summary>
public override bool CanSeek {
get {
return baseStream.CanSeek;
}
}
/// <summary>
/// I needed to implement the abstract member.
/// </summary>
public override bool CanWrite {
get {
return baseStream.CanWrite;
}
}
/// <summary>
/// I needed to implement the abstract member.
/// </summary>
public override long Length {
get {
return baseStream.Length;
}
}
/// <summary>
/// I needed to implement the abstract member.
/// </summary>
public override long Position {
get {
return baseStream.Position;
}
set {
baseStream.Position = value;
}
}
/// <summary>
/// Flushes the baseInputStream
/// </summary>
public override void Flush()
{
baseStream.Flush();
}
/// <summary>
/// I needed to implement the abstract member.
/// </summary>
public override long Seek(long offset, SeekOrigin origin)
{
return baseStream.Seek(offset, origin);
}
/// <summary>
/// I needed to implement the abstract member.
/// </summary>
public override void SetLength(long val)
{
baseStream.SetLength(val);
}
public void Write(byte[] array)
{
baseStream.Write(array, 0, array.Length);
}
/// <summary>
/// I needed to implement the abstract member.
/// </summary>
public override void Write(byte[] array, int offset, int count)
{
baseStream.Write(array, offset, count);
}
/// <summary>
/// I needed to implement the abstract member.
/// </summary>
public override void WriteByte(byte val)
{
baseStream.WriteByte(val);
}
/// <summary>
/// Closes the base stream
/// </summary>
public override void Close()
{
baseStream.Close();
}
/// <summary>
/// Reads one byte of decompressed data.
///
/// The byte is baseInputStream the lower 8 bits of the int.
/// </summary>
public override int ReadByte()
{
return baseStream.ReadByte();
}
/// <summary>
/// Decompresses data into the byte array
/// </summary>
/// <param name ="b">
/// the array to read and decompress data into
/// </param>
/// <param name ="off">
/// the offset indicating where the data should be placed
/// </param>
/// <param name ="len">
/// the number of bytes to decompress
/// </param>
public override int Read(byte[] b, int off, int len)
{
return baseStream.Read(b, off, len);
}
public int Read(byte[] b)
{
return baseStream.Read(b, 0, b.Length);
}
string ReadLineBlock()
{
StringBuilder builder = new StringBuilder(1024);
while (true) {
int i = ReadByte();
if (i == '\n' || i == -1) {
break;
}
builder.Append((char)i);
}
return builder.ToString();
}
public string ReadLine()
{
string line = "";
int x = 0;
while (line.Length == 0 && ++x < 10) {
line = ReadLineBlock();
if (line.Length == 0) {
Thread.Sleep(10);
}
}
return line;
}
public string ReadToFirstWS()
{
StringBuilder builder = new StringBuilder(1024);
while (true) {
int i = ReadByte();
builder.Append((char)i);
if (i == '\n' || i ==' ' || i == -1) {
break;
}
}
return builder.ToString();
}
public void ReadBlock(byte[] buffer, int size)
{
for (int i = 0; i < size;) {
int back = Read(buffer, i, size - i);
i += back;
if (i < size) {
Thread.Sleep(10);
}
}
}
public void SendString(string dataStr)
{
byte[] buff = System.Text.Encoding.ASCII.GetBytes(dataStr);
baseStream.Write(buff, 0, buff.Length);
Flush();
}
}
}
|