[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/IO FileStream.cs,1.14
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/IO FileStream.cs,1.14,1.15 Stream.cs,1.10,1.11 StringReader.cs,1.1,1.2 StringWriter.cs,1.3,1.4 |
Date: |
Thu, 24 Apr 2003 05:20:38 -0400 |
Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/IO
In directory subversions:/tmp/cvs-serv31949/runtime/System/IO
Modified Files:
FileStream.cs Stream.cs StringReader.cs StringWriter.cs
Log Message:
More improvements to the "System.IO" namespace.
Index: FileStream.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/IO/FileStream.cs,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -r1.14 -r1.15
*** FileStream.cs 23 Apr 2003 06:28:50 -0000 1.14
--- FileStream.cs 24 Apr 2003 09:20:35 -0000 1.15
***************
*** 2,6 ****
* FileStream.cs - Implementation of the "System.IO.FileStream" class.
*
! * Copyright (C) 2001 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
--- 2,6 ----
* FileStream.cs - Implementation of the "System.IO.FileStream" class.
*
! * Copyright (C) 2001, 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
***************
*** 836,839 ****
--- 836,897 ----
return _("IO_UnknownFile");
}
+ }
+ }
+
+ // Lock a region of the file stream.
+ [TODO]
+ public virtual void Lock(long position, long length)
+ {
+ if(position < 0)
+ {
+ throw new ArgumentOutOfRangeException
+ ("position",
_("ArgRange_NonNegative"));
+ }
+ if(length < 0)
+ {
+ throw new ArgumentOutOfRangeException
+ ("position",
_("ArgRange_NonNegative"));
+ }
+ lock(this)
+ {
+ if(handle == invalidHandle)
+ {
+ throw new
ObjectDisposedException(_("IO_StreamClosed"));
+ }
+ // TODO
+ }
+ }
+
+ // Unlock a region of the file stream.
+ [TODO]
+ public virtual void Unlock(long position, long length)
+ {
+ if(position < 0)
+ {
+ throw new ArgumentOutOfRangeException
+ ("position",
_("ArgRange_NonNegative"));
+ }
+ if(length < 0)
+ {
+ throw new ArgumentOutOfRangeException
+ ("position",
_("ArgRange_NonNegative"));
+ }
+ lock(this)
+ {
+ if(handle == invalidHandle)
+ {
+ throw new
ObjectDisposedException(_("IO_StreamClosed"));
+ }
+ // TODO
+ }
+ }
+
+ // Get the underlying file stream handle.
+ public virtual IntPtr Handle
+ {
+ get
+ {
+ Flush();
+ return handle;
}
}
Index: Stream.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/IO/Stream.cs,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** Stream.cs 23 Apr 2003 06:28:50 -0000 1.10
--- Stream.cs 24 Apr 2003 09:20:35 -0000 1.11
***************
*** 339,344 ****
public abstract long Position { get; set; }
! // Helper function for validating buffer arguments.
! internal void ValidateBuffer(byte[] buffer, int offset, int count)
{
if(buffer == null)
--- 339,365 ----
public abstract long Position { get; set; }
! // Helper methods for validating buffer arguments.
! internal static void ValidateBuffer(byte[] buffer, int offset, int
count)
! {
! if(buffer == null)
! {
! throw new
ArgumentNullException("buffer");
! }
! else if(offset < 0 || offset > buffer.Length)
! {
! throw new ArgumentOutOfRangeException
! ("offset", _("ArgRange_Array"));
! }
! else if(count < 0)
! {
! throw new ArgumentOutOfRangeException
! ("count", _("ArgRange_Array"));
! }
! else if((buffer.Length - offset) < count)
! {
! throw new
ArgumentException(_("Arg_InvalidArrayRange"));
! }
! }
! internal static void ValidateBuffer(char[] buffer, int offset, int
count)
{
if(buffer == null)
Index: StringReader.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/IO/StringReader.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** StringReader.cs 21 Apr 2002 19:20:43 -0000 1.1
--- StringReader.cs 24 Apr 2003 09:20:35 -0000 1.2
***************
*** 2,8 ****
* StringReader.cs - Implementation of the "System.IO.StringReader" class.
*
! * Copyright (C) 2002 Free Software Foundation, Inc.
! *
! * Contributed by Stephen Compall <address@hidden>
*
* This program is free software; you can redistribute it and/or modify
--- 2,6 ----
* StringReader.cs - Implementation of the "System.IO.StringReader" class.
*
! * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
***************
*** 19,23 ****
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
*/
--- 17,20 ----
***************
*** 29,158 ****
public class StringReader : TextReader
{
! // state.
!
! // the string to be read from
! private String readfrom;
!
! // index of the next character to be read
! private int position = 0;
!
! private bool streamclosed = false;
!
! // constructor
!
public StringReader(String s)
! {
! if (s == null)
! throw new ArgumentNullException("s");
! else
! this.readfrom = s;
! }
!
! // methods
public override void Close()
! {
! this.Dispose(true);
! }
protected override void Dispose(bool disposing)
! {
! if (disposing)
! {
! this.readfrom = null;
! this.streamclosed = true;
! }
! base.Dispose(disposing);
! }
public override int Peek()
! {
! if (this.streamclosed) // no String
! throw new ObjectDisposedException(null,
_("IO_StreamClosed"));
!
! else if (this.position < this.readfrom.Length) // there are
chars left
! return readfrom[position];
!
! else // out of chars to read
! return -1;
! }
public override int Read(char[] buffer, int index, int count)
! {
! if (this.streamclosed)
! throw new ObjectDisposedException(null,
_("IO_StreamClosed"));
!
! // CopyTo will check if buffer is null
!
! if (this.position == readfrom.Length) // no more chars, not
necessary
! return 0;
!
! if (count > readfrom.Length - position) // count exceeds
remaining chars in stream
! count = readfrom.Length - position;
!
! // CopyTo will do nothing if count-index == 0
!
! try
! {
! readfrom.CopyTo(position, buffer, index, count);
! }
! catch (ArgumentOutOfRangeException badRange)
! {
! // using CopyTo to avoid checking if buffer is null
! if (count > buffer.Length - index) // dest not big
enough
! throw new
ArgumentException(_("Arg_InvalidArrayRange"));
! else
! throw badRange;
! }
! return count;
! }
public override int Read()
! {
! if (this.streamclosed) // no String
! throw new ObjectDisposedException(null,
_("IO_StreamClosed"));
!
! else if (this.position < this.readfrom.Length) // there are
chars left
! return readfrom[position++];
!
! else // out of chars to read
! return -1;
! }
public override String ReadLine()
! {
! if (this.streamclosed) // no String
! throw new ObjectDisposedException(null,
_("IO_StreamClosed"));
! if (this.readfrom.Length == this.position)
! return null;
!
! int newPosition;
! int eolDexWindows = this.readfrom.IndexOf("\r\n", position);
! int eolDex = this.readfrom.IndexOfAny(new char[]{'\n', '\r'},
position);
! if (eolDexWindows == eolDex && eolDexWindows != -1) // CRLF
found, CR also found
! newPosition = eolDex + 2;
! else if (eolDex == -1) // end of line is end of string
! eolDex = newPosition = readfrom.Length;
! else // CR or LF found
! newPosition = eolDex + 1;
!
! String retval = readfrom.Substring(position, eolDex - position);
! position = newPosition;
! return retval;
! }
public override String ReadToEnd()
! {
! if (this.streamclosed) // no String
! throw new ObjectDisposedException(null,
_("IO_StreamClosed"));
!
! String retval = readfrom.Substring(position);
! position = readfrom.Length;
! return retval;
! }
!
! } // class StringReader
! } // namespace System.IO
--- 26,164 ----
public class StringReader : TextReader
{
+ // Internal state.
+ private String str;
+ private int posn;
+ private bool closed;
! // Constructor.
public StringReader(String s)
! {
! if(s == null)
! {
! throw new ArgumentNullException("s");
! }
! this.str = s;
! this.posn = 0;
! this.closed = false;
! }
+ // Close the reader.
public override void Close()
! {
! closed = true;
! }
+ // Dispose of this reader.
protected override void Dispose(bool disposing)
! {
! closed = true;
! }
+ // Peek at the next character in the stream.
public override int Peek()
! {
! if(closed)
! {
! throw new
ObjectDisposedException(_("IO_StreamClosed"));
! }
! else if(posn < str.Length)
! {
! return (int)(str[posn]);
! }
! else
! {
! return -1;
! }
! }
+ // Read a buffer of characters.
public override int Read(char[] buffer, int index, int count)
! {
! Stream.ValidateBuffer(buffer, index, count);
! if(closed)
! {
! throw new
ObjectDisposedException(_("IO_StreamClosed"));
! }
! int left = (str.Length - posn);
! if(count > left)
! {
! count = left;
! }
! if(count > 0)
! {
! str.CopyTo(posn, buffer, index, count);
! posn += count;
! }
! return count;
! }
+ // Read the next character in the stream.
public override int Read()
! {
! if(closed)
! {
! throw new
ObjectDisposedException(_("IO_StreamClosed"));
! }
! else if(posn < str.Length)
! {
! return (int)(str[posn++]);
! }
! else
! {
! return -1;
! }
! }
+ // Read the next line of input.
public override String ReadLine()
! {
! if(closed)
! {
! throw new
ObjectDisposedException(_("IO_StreamClosed"));
! }
! if(posn >= str.Length)
! {
! return null;
! }
! int index1 = str.IndexOf('\n', posn);
! int index2 = str.IndexOf('\r', posn);
! String line;
! if(index1 == -1 && index2 == -1)
! {
! // No end of line marker - return the
rest of the string.
! line = str.Substring(posn);
! posn = str.Length;
! }
! else if(index1 != -1 &&
! (index2 == -1 || index1 <= index2))
! {
! // Line is terminated by LF.
! line = str.Substring(posn, index1 -
posn);
! posn = index1 + 1;
! }
! else
! {
! // Line is terminated by CR or CRLF.
! line = str.Substring(posn, index2 -
posn);
! posn = index2 + 1;
! if(posn < str.Length && str[posn] ==
'\n')
! {
! ++posn;
! }
! }
! return line;
! }
+ // Read the remainder of the input stream.
public override String ReadToEnd()
! {
! if(closed)
! {
! throw new
ObjectDisposedException(_("IO_StreamClosed"));
! }
! return str.Substring(posn);
! }
! }; // class StringReader
! }; // namespace System.IO
Index: StringWriter.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/IO/StringWriter.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** StringWriter.cs 20 Apr 2002 23:56:32 -0000 1.3
--- StringWriter.cs 24 Apr 2003 09:20:35 -0000 1.4
***************
*** 2,8 ****
* StringWriter.cs - Implementation of the "System.IO.StringWriter" class.
*
! * Copyright (C) 2002 Free Software Foundation, Inc.
! *
! * Contributed by Stephen Compall <address@hidden>
*
* This program is free software; you can redistribute it and/or modify
--- 2,6 ----
* StringWriter.cs - Implementation of the "System.IO.StringWriter" class.
*
! * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
***************
*** 19,23 ****
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
*/
--- 17,20 ----
***************
*** 26,155 ****
using System;
- using System.Globalization;
using System.Text;
! public class StringWriter : TextWriter, IDisposable
{
!
! // state
!
! // the System.Text.StringBuilder to work with (like
java.lang.StringBuffer).
! private StringBuilder buffer;
! // closing is very simple...just look at this!
! private bool streamclosed = false;
// Constructors.
! public StringWriter()
! {
! // TODO: consider using the StringBuilder(int) constructor
! // instead, because the default size for that is 16 :(
! this.buffer = new StringBuilder();
! }
!
! public StringWriter(IFormatProvider formatProvider) :
base(formatProvider)
! {
! // hmmmm...gonna let TextWriter handle this one
! this.buffer = new StringBuilder();
! }
!
! public StringWriter(StringBuilder sb)
! {
! if (sb == null) throw new ArgumentNullException("sb");
! this.buffer = sb;
! }
!
! public StringWriter(StringBuilder sb, IFormatProvider formatProvider) :
! base(formatProvider)
! {
! if (sb == null) throw new ArgumentNullException("sb");
! this.buffer = sb;
! }
!
! // methods
public override void Close()
! {
! this.streamclosed = true;
! // still keep the this.buffer, though...norm for streams to
save :)
! // although TextWriter.Close(bool) wants you to get rid of it
! }
protected override void Dispose(bool disposing)
! {
! // however, if you don't need the object anymore (see
! // System.IDisposable), then it can gc the StringBuilder.
! if (disposing)
! {
! this.buffer = null;
! this.streamclosed = true;
! }
! // safe for call multiple times
!
! // I don't know if it automatically chains these, but just in
! // case base.Dispose actually does something...
! base.Dispose(disposing);
! }
public virtual StringBuilder GetStringBuilder()
! {
! return this.buffer;
! }
public override String ToString()
! {
! return this.buffer.ToString();
! }
public override void Write(String value)
! {
! if (this.streamclosed) throw new ObjectDisposedException(null,
_("IO_StreamClosed"));
! this.buffer.Append(value);
! }
!
! public override void Write(char value)
! {
! if (this.streamclosed) throw new ObjectDisposedException(null,
_("IO_StreamClosed"));
! this.buffer.Append(value);
! }
!
public override void Write(char[] buffer, int index, int count)
! {
! if (this.streamclosed) throw new ObjectDisposedException(null,
_("IO_StreamClosed"));
!
! // StringBuilder puts another requirement on this one, but not
us!
! if (buffer == null) throw new ArgumentNullException("buffer");
!
! try
! {
! this.buffer.Append(buffer, index, count);
! }
! catch (ArgumentOutOfRangeException aoore)
! // the definition combines the cases for StringBuilder, and
! // differentiates for StringWriter. Oh well.
! {
! if (index < 0 || count < 0)
! // kind of improper, but faster
! throw aoore;
! else
! throw new
ArgumentException(_("ArgRange_Array"));
! }
!
! }
!
! // Properties.
public override Encoding Encoding
! {
! get
! {
! // Since presumably, StringBuilder is implemented
! // internally as a char[], this being the most efficient
! // method, and programs relying on performance would
! // certainly see this Stream as very efficient,
! return new UnicodeEncoding();
! }
! }
! } // StringWriter
! } // namespace
--- 23,137 ----
using System;
using System.Text;
! public class StringWriter : TextWriter
{
! // Internal state.
! private StringBuilder builder;
! private Encoding encoding;
! private bool closed;
// Constructors.
! public StringWriter() : base()
! {
! builder = new StringBuilder();
! closed = false;
! }
! public StringWriter(IFormatProvider provider) : base(provider)
! {
! builder = new StringBuilder();
! closed = false;
! }
! public StringWriter(StringBuilder sb) : base()
! {
! if(sb == null)
! {
! throw new ArgumentNullException("sb");
! }
! builder = sb;
! closed = false;
! }
! public StringWriter(StringBuilder sb, IFormatProvider provider)
! : base(provider)
! {
! if(sb == null)
! {
! throw new ArgumentNullException("sb");
! }
! builder = sb;
! closed = false;
! }
+ // Close this writer.
public override void Close()
! {
! Dispose(true);
! }
+ // Dispose of this writer.
protected override void Dispose(bool disposing)
! {
! closed = true;
! }
+ // Get the underlying string builder.
public virtual StringBuilder GetStringBuilder()
! {
! return builder;
! }
+ // Convert this object into a string.
public override String ToString()
! {
! return builder.ToString();
! }
+ // Write values to this writer.
public override void Write(String value)
! {
! if(closed)
! {
! throw new
ObjectDisposedException(_("IO_StreamClosed"));
! }
! if(value != null)
! {
! builder.Append(value);
! }
! }
public override void Write(char[] buffer, int index, int count)
! {
! Stream.ValidateBuffer(buffer, index, count);
! if(closed)
! {
! throw new
ObjectDisposedException(_("IO_StreamClosed"));
! }
! if(count > 0)
! {
! builder.Append(buffer, index, count);
! }
! }
! public override void Write(char ch)
! {
! if(closed)
! {
! throw new
ObjectDisposedException(_("IO_StreamClosed"));
! }
! builder.Append(ch);
! }
+ // Get the encoding for this writer.
public override Encoding Encoding
! {
! get
! {
! if(encoding == null)
! {
! encoding = new
UnicodeEncoding(false, false);
! }
! return encoding;
! }
! }
! }; // class StringWriter
! }; // namespace System.IO
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/IO FileStream.cs,1.14,1.15 Stream.cs,1.10,1.11 StringReader.cs,1.1,1.2 StringWriter.cs,1.3,1.4,
Rhys Weatherley <address@hidden> <=