Skip to content

Commit

Permalink
Merge pull request mono#14 from bl8/gio-merges
Browse files Browse the repository at this point in the history
  • Loading branch information
mkestner committed Jul 17, 2011
2 parents d90fae8 + bcf4218 commit 86cd963
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions gio/Gio.metadata
Expand Up @@ -30,6 +30,8 @@
<attr path="/api/namespace/interface[@cname='GIcon']" name="consume_only">1</attr>
<attr path="/api/namespace/interface[@cname='GMount']" name="consume_only">1</attr>
<attr path="/api/namespace/interface[@cname='GMount']/method[@name='CanUnmount']" name="name">GetCanUnmount</attr>
<attr path="/api/namespace/interface[@cname='GMount']/method[@name='GuessContentTypeFinish']/return-type" name="null_term_array">1</attr>
<attr path="/api/namespace/interface[@cname='GMount']/method[@name='GuessContentTypeSync']/return-type" name="null_term_array">1</attr>
<attr path="/api/namespace/interface[@cname='GSeekable']/method[@cname='g_seekable_can_seek']" name="name">GetCanSeek</attr>
<attr path="/api/namespace/interface[@cname='GSeekable']/method[@cname='g_seekable_tell']" name="name">GetPosition</attr>
<attr path="/api/namespace/interface[@cname='GTlsServerConnection']/property[@cname='authentication-mode']" name="hidden">1</attr>
Expand Down
35 changes: 32 additions & 3 deletions gio/GioStream.cs
Expand Up @@ -63,6 +63,14 @@ public GioStream (OutputStream stream)
can_seek = stream is Seekable && (stream as Seekable).CanSeek;
}

public GioStream (IOStream stream)
{
this.stream = stream;
can_read = true;
can_write = true;
can_seek = stream is Seekable && (stream as Seekable).CanSeek;
}

public override bool CanSeek {
get { return can_seek; }
}
Expand Down Expand Up @@ -90,6 +98,10 @@ public GioStream (OutputStream stream)
FileInfo info = (stream as FileOutputStream).QueryInfo ("standard::size", null);
return info.Size;
}
if (stream is FileIOStream) {
FileInfo info = (stream as FileIOStream).QueryInfo ("standard::size", null);
return info.Size;
}
throw new NotImplementedException (String.Format ("not implemented for {0} streams", stream.GetType()));
}
}
Expand Down Expand Up @@ -127,7 +139,11 @@ public override int Read (byte[] buffer, int offset, int count)
throw new NotSupportedException ("The stream does not support reading");
if (is_disposed)
throw new ObjectDisposedException ("The stream is closed");
InputStream input_stream = stream as InputStream;
InputStream input_stream = null;
if (stream is InputStream)
input_stream = stream as InputStream;
else if (stream is IOStream)
input_stream = (stream as IOStream).InputStream;
if (input_stream == null)
throw new System.Exception ("this shouldn't happen");

Expand Down Expand Up @@ -155,7 +171,11 @@ public override void Write (byte[] buffer, int offset, int count)
throw new NotSupportedException ("The stream does not support writing");
if (is_disposed)
throw new ObjectDisposedException ("The stream is closed");
OutputStream output_stream = stream as OutputStream;
OutputStream output_stream = null;
if (stream is OutputStream)
output_stream = stream as OutputStream;
else if (stream is IOStream)
output_stream = (stream as IOStream).OutputStream;
if (output_stream == null)
throw new System.Exception ("this shouldn't happen");
if (offset == 0) {
Expand Down Expand Up @@ -198,9 +218,16 @@ public override void SetLength (long value)
{
if (!CanSeek || !CanWrite)
throw new NotSupportedException ("This stream doesn't support seeking");

var seekable = stream as Seekable;

if (!seekable.CanTruncate ())
throw new NotSupportedException ("This stream doesn't support truncating");

if (is_disposed)
throw new ObjectDisposedException ("The stream is closed");
throw new NotImplementedException ();

seekable.Truncate (value, null);
}

public override void Close ()
Expand All @@ -209,6 +236,8 @@ public override void Close ()
(stream as InputStream).Close (null);
if (stream is OutputStream)
(stream as OutputStream).Close (null);
if (stream is IOStream)
(stream as IOStream).Close (null);
is_disposed = true;
}
}
Expand Down

0 comments on commit 86cd963

Please sign in to comment.