[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/IO StreamWriter.cs,1.4
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/IO StreamWriter.cs,1.4,1.5 |
Date: |
Thu, 28 Nov 2002 01:59:44 -0500 |
Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/IO
In directory subversions:/tmp/cvs-serv22064/runtime/System/IO
Modified Files:
StreamWriter.cs
Log Message:
Convert the stream contents using the prevailing Encoding instance.
Index: StreamWriter.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/IO/StreamWriter.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** StreamWriter.cs 12 Nov 2002 14:09:10 -0000 1.4
--- StreamWriter.cs 28 Nov 2002 06:59:40 -0000 1.5
***************
*** 42,52 ****
private Stream stream;
private Encoding encoding;
private int bufferSize;
private char[] inBuffer;
- private int inBufferPosn;
private int inBufferLen;
private byte[] outBuffer;
- private int outBufferPosn;
- private int outBufferLen;
private bool autoFlush;
--- 42,50 ----
private Stream stream;
private Encoding encoding;
+ private Encoder encoder;
private int bufferSize;
private char[] inBuffer;
private int inBufferLen;
private byte[] outBuffer;
private bool autoFlush;
***************
*** 84,94 ****
this.stream = stream;
this.encoding = encoding;
this.bufferSize = bufferSize;
this.inBuffer = new char [bufferSize];
- this.inBufferPosn = 0;
this.inBufferLen = 0;
! this.outBuffer = new byte [bufferSize];
! this.outBufferPosn = 0;
! this.outBufferLen = 0;
this.autoFlush = false;
--- 82,91 ----
this.stream = stream;
this.encoding = encoding;
+ this.encoder = encoding.GetEncoder();
this.bufferSize = bufferSize;
this.inBuffer = new char [bufferSize];
this.inBufferLen = 0;
! this.outBuffer = new byte
! [encoding.GetMaxByteCount(bufferSize)];
this.autoFlush = false;
***************
*** 137,147 ****
this.stream = stream;
this.encoding = encoding;
this.bufferSize = bufferSize;
this.inBuffer = new char [bufferSize];
- this.inBufferPosn = 0;
this.inBufferLen = 0;
! this.outBuffer = new byte [bufferSize];
! this.outBufferPosn = 0;
! this.outBufferLen = 0;
this.autoFlush = false;
--- 134,143 ----
this.stream = stream;
this.encoding = encoding;
+ this.encoder = encoding.GetEncoder();
this.bufferSize = bufferSize;
this.inBuffer = new char [bufferSize];
this.inBufferLen = 0;
! this.outBuffer = new byte
! [encoding.GetMaxByteCount(bufferSize)];
this.autoFlush = false;
***************
*** 177,198 ****
if(stream != null)
{
! if(outBufferPosn < outBufferLen)
! {
! stream.Write(outBuffer,
outBufferPosn,
!
outBufferLen - outBufferPosn);
! }
stream.Close();
stream = null;
}
inBuffer = null;
- inBufferPosn = 0;
inBufferLen = 0;
outBuffer = null;
- outBufferPosn = 0;
- outBufferLen = 0;
bufferSize = 0;
base.Dispose(disposing);
}
// Flush the contents of the writer's buffer to the underlying stream.
public override void Flush()
--- 173,203 ----
if(stream != null)
{
! Convert(true);
! stream.Flush();
stream.Close();
stream = null;
}
inBuffer = null;
inBufferLen = 0;
outBuffer = null;
bufferSize = 0;
base.Dispose(disposing);
}
+ // Convert the contents of the input buffer and write them.
+ private void Convert(bool flush)
+ {
+ if(inBufferLen > 0)
+ {
+ int len = encoder.GetBytes(inBuffer, 0,
inBufferLen,
+
outBuffer, 0, flush);
+ if(len > 0)
+ {
+ stream.Write(outBuffer, 0, len);
+ }
+ inBufferLen = 0;
+ }
+ }
+
// Flush the contents of the writer's buffer to the underlying stream.
public override void Flush()
***************
*** 202,212 ****
throw new
ObjectDisposedException(_("IO_StreamClosed"));
}
! if(outBufferPosn < outBufferLen)
! {
! stream.Write(outBuffer, outBufferPosn,
! outBufferLen -
outBufferPosn);
! outBufferPosn = 0;
! outBufferLen = 0;
! }
stream.Flush();
}
--- 207,211 ----
throw new
ObjectDisposedException(_("IO_StreamClosed"));
}
! Convert(true);
stream.Flush();
}
***************
*** 215,226 ****
public override void Write(String value)
{
- char[] chars;
-
if(value == null)
{
throw new
ArgumentNullException("value");
}
! chars = value.ToCharArray();
! Write(chars, 0, chars.Length);
}
--- 214,245 ----
public override void Write(String value)
{
if(value == null)
{
throw new
ArgumentNullException("value");
}
! int temp;
! int index = 0;
! int count = value.Length;
! while(count > 0)
! {
! temp = bufferSize - inBufferLen;
! if(temp > count)
! {
! temp = count;
! }
! value.CopyTo(index, inBuffer,
inBufferLen, temp);
! index += temp;
! count -= temp;
! inBufferLen += temp;
! if(inBufferLen >= bufferSize)
! {
! Convert(false);
! }
! }
! if(autoFlush)
! {
! Convert(false);
! stream.Flush();
! }
}
***************
*** 228,231 ****
--- 247,251 ----
public override void Write(char[] buffer, int index, int count)
{
+ // Validate the parameters.
if(buffer == null)
{
***************
*** 248,263 ****
}
! while (count > 0)
{
! if (this.outBufferLen >=
this.bufferSize - 1)
{
! stream.Write(outBuffer,
outBufferPosn,
!
outBufferLen - outBufferPosn);
! outBufferPosn = 0;
! outBufferLen = 0;
! stream.Flush();
}
! this.outBuffer[this.outBufferLen++] =
(byte) buffer[index++];
! --count;
}
}
--- 268,293 ----
}
! // Copy the characters to the input buffer.
! int temp;
! while(count > 0)
{
! temp = bufferSize - inBufferLen;
! if(temp > count)
! {
! temp = count;
! }
! Array.Copy(buffer, index, inBuffer,
inBufferLen, temp);
! index += temp;
! count -= temp;
! inBufferLen += temp;
! if(inBufferLen >= bufferSize)
{
! Convert(false);
}
! }
! if(autoFlush)
! {
! Convert(false);
! stream.Flush();
}
}
***************
*** 274,278 ****
public override void Write(char value)
{
! Write(new char[]{value}, 0, 1);
}
--- 304,317 ----
public override void Write(char value)
{
! inBuffer[inBufferLen++] = value;
! if(inBufferLen >= bufferSize)
! {
! Convert(false);
! }
! if(autoFlush)
! {
! Convert(false);
! stream.Flush();
! }
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/IO StreamWriter.cs,1.4,1.5,
Rhys Weatherley <address@hidden> <=