示例#1
0
 /// <summary>
 /// Close this stream and dispose the underlying source. If dispose is not explicitly called then the underlying source will stay allocated until the GC gets this object
 /// </summary>
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         AssetRep.Dispose();
         AssetRep = null;
         Lib.Dispose();
         Lib = null;
     }
 }
示例#2
0
        /// <summary>
        /// Read into the specified buffer from offset, the count number of bytes.
        /// see http://msdn.microsoft.com/en-us/library/system.io.stream.read.aspx
        /// </summary>
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", offset, "offset is negative");
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", count, "count is negative");
            }
            if (AssetRep == null)
            {
                throw new ObjectDisposedException("AssetLibraryReadStream", "Can not call methods on the stream after it is closed");
            }

            NSError error;
            int     bytesRead;

            // Using a fixed pointer to stop buffer being moved by the GC during the copy
            unsafe
            {
                fixed(byte *pointer = buffer)
                {
                    bytesRead = (int)AssetRep.GetBytes((IntPtr)(pointer + offset), (long)Position, (uint)count, out error);
                }
            }
            if (error != null)
            {
                throw new IOException(string.Format
                                      (
                                          "Error reading bytes from: {1}{0}offset:{2}{0}count:{3}{0}message:{4}",
                                          Environment.NewLine,
                                          AssetRep.Url.AbsoluteString,
                                          offset,
                                          count,
                                          error.LocalizedDescription
                                      ));
            }

            Position += bytesRead;

            return(bytesRead);
        }