dotgnu-libs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-libs-commits] CVS: dotgnu-base/DotGNU/IO FileStream.cs,NONE,1.1


From: Peter Minten <address@hidden>
Subject: [Dotgnu-libs-commits] CVS: dotgnu-base/DotGNU/IO FileStream.cs,NONE,1.1 IStream.cs,NONE,1.1 Stream.cs,1.1.1.1,1.2
Date: Sat, 27 Jul 2002 06:36:03 -0400

Update of /cvsroot/dotgnu-libs/dotgnu-base/DotGNU/IO
In directory subversions:/tmp/cvs-serv12452/DotGNU/IO

Modified Files:
        Stream.cs 
Added Files:
        FileStream.cs IStream.cs 
Log Message:
Weekly update


--- NEW FILE ---
/*
 * FileStream.cs - DotGNU FileStream, support String read/write 
 *                    and stream operators
 *
 * Copyright (C) 2002  Peter Minten
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser 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
 */

namespace DotGNU.IO
{

using System;
using System.Net.Sockets;
using System.Text;

///<remarks>DotGNU FileStream, support String read/write and 
///  stream operators.</remarks>
public class FileStream : System.IO.FileStream, IStream
{
        //For the String stuff the number of chars received/send is 
buffer.Length
        //I keep the return type void so that programmers don't get confused
        //between bytes received and chars received

        //Methods

        /// <summary>Read method using unicode, 
        ///   reads until no more data is available.</summary>
        /// <param name="buffer">The buffer to place the data in.</param>
        public void Read (String buffer)
        {
                return Stream.Read(this, buffer);
        }
        
        /// <summary>Read method using the specified encoding, 
        ///   reads until no more data is available.</summary>
        /// <param name="buffer">The buffer to place the data in.</param>
        /// <param name="encoding">The encoding to use.</param>
        public void Read (String buffer, Encoding encoding)
        {
                return Stream.Read(this, buffer, encoding);
        }

        /// <summary>Write method using unicode, 
        ///   writes all data in the buffer.</summary>
        /// <param name="buffer">The buffer to get the data from.</param>
        public void Write(String buffer)
        {
                return Stream.Write(this, buffer);
        }

        /// <summary>Write method using the specified encoding, 
        ///   writes all data in the buffer.</summary>
        /// <param name="buffer">The buffer to get the data from.</param>
        /// <param name="encoding">The encoding to use.</param>
        public void Write(String buffer, Encoding encoding)
        {
                return Stream.Write(this, buffer, encoding);
        }

        //Operators
        //The easiest way to implement these is 
        //simply copying them from DotGNU Stream
        
        /// <summary>Read operator for byte[], reads until b is full.</summary>
        /// <param name="a">The stream to work on.</param>
        /// <param name="b">The buffer to put the data in.</param>
        public static Stream operator>> (System.IO.Stream a, byte[] b)
        {
                a.Read(b, 0, b.Length);
        }
                                  
        /// <summary>Read operator for String, 
        ///   reads until no more data is available.</summary>
        /// <param name="a">The stream to work on.</param>
        /// <param name="b">The buffer to put the data in.</param>      
        public static Stream operator>> (System.IO.Stream a, String b)
        {
                Read(a, b);
        }
        
        /// <summary>Write operator for byte[].</summary>
        /// <param name="a">The stream to work on.</param>
        /// <param name="b">The buffer to get the data from.</param>
        public static Stream operator<< (System.IO.Stream a, byte[] b)
        {
                a.Write(b, 0, b.Length);
        }

        /// <summary>Write operator for String.</summary>
        /// <param name="a">The stream to work on.</param>
        /// <param name="b">The buffer to get the data from.</param>    
        public static Stream operator<< (System.IO.Stream a, String b)
        {
                Write(a, b);
        }        
                
}; // class FileStream


}; // namespace DotGNU.IO

--- NEW FILE ---
/*
 * IStream.cs - DotGNU IStream, interface for DotGNU Streams
 *
 * Copyright (C) 2002  Peter Minten
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser 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
 */

namespace DotGNU.IO
{

using System;
using System.Net.Sockets;
using System.Text;

///<remarks>DotGNU IStream, Stream inteface for DotGNU streams.</remarks>
public interface IStream
{
        /// <summary>Read method using unicode, 
        ///   reads until no more data is available.</summary>
        /// <param name="buffer">The buffer to place the data in.</param>
        void Read (String buffer);
        
        /// <summary>Read method using the specified encoding, 
        ///   reads until no more data is available.</summary>
        /// <param name="buffer">The buffer to place the data in.</param>
        /// <param name="encoding">The encoding to use.</param>
        void Read (String buffer, Encoding encoding);
        
        /// <summary>Write method using unicode, 
        ///   writes all data in the buffer.</summary>
        /// <param name="buffer">The buffer to get the data from.</param>
        void Write(String buffer);

        /// <summary>Write method using the specified encoding, 
        ///   writes all data in the buffer.</summary>
        /// <param name="buffer">The buffer to get the data from.</param>
        /// <param name="encoding">The encoding to use.</param>
        void Write(String buffer, Encoding encoding);
                
}; // interface IStream

}; // namespace DotGNU.IO

Index: Stream.cs
===================================================================
RCS file: /cvsroot/dotgnu-libs/dotgnu-base/DotGNU/IO/Stream.cs,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** Stream.cs   21 Jul 2002 08:04:19 -0000      1.1.1.1
--- Stream.cs   27 Jul 2002 10:36:01 -0000      1.2
***************
*** 26,34 ****
  using System.Text;
  
- using DotGNU.Text;
- 
  //Most of the time we can't reference to Stream (no double class inheritance)
  //so this Stream consists purely of static methods and doesn't inherit from
! //pnetlib Stream                         
  public abstract class Stream
  {
--- 26,34 ----
  using System.Text;
  
  //Most of the time we can't reference to Stream (no double class inheritance)
  //so this Stream consists purely of static methods and doesn't inherit from
! //pnetlib Stream         
! ///<remarks>DotGNU Stream, support String read/write and 
! ///  stream operators.</remarks>                
  public abstract class Stream
  {
***************
*** 39,52 ****
        //String read methods
  
!       //Uses unicode encoding
        public static void Read (System.IO.Stream stream, String buffer)
        {
!               Read(stream, buffer, Encodings.Unicode);
        }
  
!       //Reads until no more data is available
!       //Encoding can be specified     
        public static void Read (System.IO.Stream stream, String buffer, 
!               Encodings encoding)
        {
                buffer = ""; //Clean buffer
--- 39,58 ----
        //String read methods
  
!       /// <summary>Read method using unicode, 
!       ///   reads until no more data is available.</summary>
!       /// <param name="stream">The stream to work on.</param>
!       /// <param name="buffer">The buffer to place the data in.</param>
        public static void Read (System.IO.Stream stream, String buffer)
        {
!               Read(stream, buffer, Encoding.Unicode);
        }
  
!       /// <summary>Read method using the specified encoding, 
!       ///   reads until no more data is available.</summary>
!       /// <param name="stream">The stream to work on.</param>
!       /// <param name="buffer">The buffer to place the data in.</param>
!       /// <param name="encoding">The encoding to use.</param>
        public static void Read (System.IO.Stream stream, String buffer, 
!               Encoding encoding)
        {
                buffer = ""; //Clean buffer
***************
*** 60,85 ****
                        int bytesreceived = stream.Read(bbuf);
                                
!                       switch (encoding)
!                       {
!                               case Encodings.ASCII:
!                                       ASCIIEncoding.GetChars(bbuf, 0, 
bytesread, cbuf, 0);
!                                       break;
! 
!                               case Encodings.UTF7:
!                                       UTF7Encoding.GetChars(bbuf, 0, 
bytesread, cbuf, 0);
!                                       break;
! 
!                               case Encodings.UTF8:
!                                       UTF8Encoding.GetChars(bbuf, 0, 
bytesread, cbuf, 0);
!                                       break;
! 
!                               case Encodings.Unicode:
!                                       UnicodeEncoding.GetChars(bbuf, 0, 
bytesread, cbuf, 0);
!                                       break;
! 
!                               case Default:
!                                       throw new 
ArgumentException(S._("InvalidEnumValue"));
!                                       break;
!                       }
                        
                        tbuffer = new String(cbuf);
--- 66,70 ----
                        int bytesreceived = stream.Read(bbuf);
                                
!                       encoding.GetChars(bbuf, 0, bytesread, cbuf, 0);
                        
                        tbuffer = new String(cbuf);
***************
*** 95,141 ****
        }
  
!       //String write methods
!       //Uses unicode encoding
        public static void Write(System.IO.Stream stream, String buffer)
        {
!               Write(stream, buffer, Encodings.Unicode);
        }
        
!       //Encoding can be specified
!       public static void Write(System.IO.Stream stream, String buffer, 
Encodings encoding)
        {
!               switch (encoding)
!               {
!                       case Encodings.ASCII:
!                               stream.Send(ASCIIEncoding.GetBytes(buffer));
!                               return;
! 
!                       case Encodings.UTF7:
!                               stream.Send(UTF7Encoding.GetBytes(buffer));
!                               return;
! 
!                       case Encodings.UTF8:
!                               stream.Send(UTF8Encoding.GetBytes(buffer));
!                               return;
! 
!                       case Encodings.Unicode:
!                               stream.Send(UnicodeEncoding.GetBytes(buffer));
!                               return;
! 
!                       case Default:
!                               throw new 
ArgumentException(S._("InvalidEnumValue"));
!                               break;
!               }
        }
        
        //Operators
        
!       //Read operator for byte[]
        public static Stream operator>> (System.IO.Stream a, byte[] b)
        {
                a.Read(b, 0, b.Length);
        }
! 
!       //Read operator for String (uses unicode)       
        public static Stream operator>> (System.IO.Stream a, String b)
        {
--- 80,117 ----
        }
  
!       /// <summary>Write method using unicode, 
!       ///   writes all data in the buffer.</summary>
!       /// <param name="stream">The stream to work on.</param>
!       /// <param name="buffer">The buffer to get the data from.</param>
        public static void Write(System.IO.Stream stream, String buffer)
        {
!               Write(stream, buffer, Encoding.Unicode);
        }
        
!       /// <summary>Write method using the specified encoding, 
!       ///   writes all data in the buffer.</summary>
!       /// <param name="stream">The stream to work on.</param>
!       /// <param name="buffer">The buffer to get the data from.</param>
!       /// <param name="encoding">The encoding to use.</param>
!       public static void Write(System.IO.Stream stream, String buffer, 
!               Encoding encoding)
        {
!               stream.Write(encoding.GetBytes(buffer));
        }
        
        //Operators
        
!       /// <summary>Read operator for byte[], reads until b is full.</summary>
!       /// <param name="a">The stream to work on.</param>
!       /// <param name="b">The buffer to put the data in.</param>
        public static Stream operator>> (System.IO.Stream a, byte[] b)
        {
                a.Read(b, 0, b.Length);
        }
!       
!       /// <summary>Read operator for String, 
!       ///   reads until no more data is available.</summary>
!       /// <param name="a">The stream to work on.</param>
!       /// <param name="b">The buffer to put the data in.</param>
        public static Stream operator>> (System.IO.Stream a, String b)
        {
***************
*** 143,147 ****
        }
        
!       //Write operator for byte
        public static Stream operator<< (System.IO.Stream a, byte[] b)
        {
--- 119,125 ----
        }
        
!       /// <summary>Write operator for byte[].</summary>
!       /// <param name="a">The stream to work on.</param>
!       /// <param name="b">The buffer to get the data from.</param>
        public static Stream operator<< (System.IO.Stream a, byte[] b)
        {
***************
*** 149,153 ****
        }
  
!       //Write operator for String (uses unicode)      
        public static Stream operator<< (System.IO.Stream a, String b)
        {
--- 127,133 ----
        }
  
!       /// <summary>Write operator for String.</summary>
!       /// <param name="a">The stream to work on.</param>
!       /// <param name="b">The buffer to get the data from.</param>    
        public static Stream operator<< (System.IO.Stream a, String b)
        {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]