[gmime] Implemented StreamWrapper.Write()
- From: Jeffrey Stedfast <fejj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gmime] Implemented StreamWrapper.Write()
- Date: Thu, 17 Mar 2011 03:14:44 +0000 (UTC)
commit d109d8d5d685fcafbb7890081049f5a8b25b8f32
Author: Jeffrey Stedfast <fejj gnome org>
Date: Wed Mar 16 23:14:20 2011 -0400
Implemented StreamWrapper.Write()
2011-03-16 Jeffrey Stedfast <fejj novell com>
* mono/StreamWrapper.cs (Write): Implemented.
ChangeLog | 2 +
mono/StreamWrapper.cs | 61 ++++++++++++++++++++++++++++++++++++++----------
2 files changed, 50 insertions(+), 13 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1889ff3..83a47c6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
2011-03-16 Jeffrey Stedfast <fejj novell com>
+ * mono/StreamWrapper.cs (Write): Implemented.
+
* mono/CryptoRecipientCollection.cs:
* mono/SignerCollection.cs: New collections for Signers and
CryptoRecipients.
diff --git a/mono/StreamWrapper.cs b/mono/StreamWrapper.cs
index ed348f8..e393a2d 100644
--- a/mono/StreamWrapper.cs
+++ b/mono/StreamWrapper.cs
@@ -41,9 +41,8 @@ namespace GMime {
get { return stream == null || stream is StreamFilter ? false : true; }
}
- // FIXME: Support writing?
public override bool CanWrite {
- get { return false; }
+ get { return stream == null ? false : true; }
}
public override long Length {
@@ -85,24 +84,65 @@ namespace GMime {
public override int Read (byte[] buffer, int offset, int count)
{
+ byte[] buf;
+ int nread;
+
if (stream == null)
- throw new ObjectDisposedException ("GMimeStream", "The stream has been closed");
+ throw new ObjectDisposedException ("GMimeStream", "The backing stream has been closed.");
- if (offset != 0)
- throw new ArgumentOutOfRangeException ("offset must be 0");
+ if (offset > buffer.Length)
+ throw new ArgumentOutOfRangeException ("offset");
- int nread = (int) stream.Read (buffer, (uint) count);
+ if (offset + count > buffer.Length)
+ throw new ArgumentOutOfRangeException ("count");
+
+ if (offset != 0)
+ buf = new byte [count];
+ else
+ buf = buffer;
+
+ nread = (int) stream.Read (buf, (uint) count);
if (nread < 0)
- return 0;
+ throw new IOException ();
+
+ if (buf != buffer && nread > 0)
+ Array.Copy (buf, 0, buffer, offset, nread);
return nread;
}
+ public override void Write (byte[] buffer, int offset, int count)
+ {
+ int nwritten;
+ byte[] buf;
+
+ if (stream == null)
+ throw new ObjectDisposedException ("GMimeStream", "The backing stream has been closed.");
+
+ if (offset > buffer.Length)
+ throw new ArgumentOutOfRangeException ("offset");
+
+ if (offset + count > buffer.Length)
+ throw new ArgumentOutOfRangeException ("count");
+
+ if (offset != 0) {
+ buf = new byte [count];
+ Array.Copy (buffer, offset, buf, 0, count);
+ } else {
+ buf = buffer;
+ }
+
+ nwritten = (int) stream.Write (buf, (uint) count);
+
+ if (nwritten < 0)
+ throw new IOException ();
+ }
+
public override long Seek (long offset, SeekOrigin origin)
{
if (stream == null)
- throw new ObjectDisposedException ("GMimeStream", "The stream has been closed");
+ throw new ObjectDisposedException ("GMimeStream", "The backing stream has been closed.");
if (stream is StreamFilter) {
if (offset != 0 || origin != SeekOrigin.Begin)
@@ -143,10 +183,5 @@ namespace GMime {
{
throw new NotSupportedException ();
}
-
- public override void Write (byte[] buffer, int offset, int count)
- {
- throw new NotSupportedException ();
- }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]