Imported Upstream version 4.2.0.179

Former-commit-id: 4610231f55806d2a05ed69e5ff3faa7336cc1479
This commit is contained in:
Xamarin Public Jenkins
2015-08-26 07:17:56 -04:00
committed by Jo Shields
parent aa7da660d6
commit c042cd0c52
7507 changed files with 90259 additions and 657307 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,360 +0,0 @@
//
// System.IO.BinaryWriter
//
// Authors:
// Matt Kimball (matt@kimball.net)
// Marek Safar (marek.safar@gmail.com)
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
// Copyright 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Text;
using System.Globalization;
using Mono.Security;
using System.Runtime.InteropServices;
namespace System.IO {
[Serializable]
[ComVisible (true)]
public class BinaryWriter : IDisposable {
// Null is a BinaryWriter with no backing store.
public static readonly BinaryWriter Null = new BinaryWriter ();
protected Stream OutStream;
private Encoding m_encoding;
private byte [] buffer;
byte [] stringBuffer;
int maxCharsPerRound;
bool disposed;
protected BinaryWriter() : this (Stream.Null, EncodingHelper.UTF8UnmarkedUnsafe)
{
}
public BinaryWriter(Stream output) : this(output, EncodingHelper.UTF8UnmarkedUnsafe)
{
}
readonly bool leave_open;
public BinaryWriter(Stream output, Encoding encoding)
: this (output, encoding, false)
{
}
public BinaryWriter(Stream output, Encoding encoding, bool leaveOpen)
{
if (output == null)
throw new ArgumentNullException("output");
if (encoding == null)
throw new ArgumentNullException("encoding");
if (!output.CanWrite)
throw new ArgumentException(Locale.GetText ("Stream does not support writing or already closed."));
leave_open = leaveOpen;
OutStream = output;
m_encoding = encoding;
buffer = new byte [16];
}
public virtual Stream BaseStream {
get {
Flush ();
return OutStream;
}
}
public virtual void Close() {
Dispose (true);
}
public void Dispose ()
{
Dispose (true);
}
protected virtual void Dispose (bool disposing)
{
if (disposing && OutStream != null && !leave_open)
OutStream.Close();
buffer = null;
m_encoding = null;
disposed = true;
}
public virtual void Flush() {
OutStream.Flush();
}
public virtual long Seek(int offset, SeekOrigin origin) {
return OutStream.Seek(offset, origin);
}
public virtual void Write(bool value) {
if (disposed)
throw new ObjectDisposedException ("BinaryWriter", "Cannot write to a closed BinaryWriter");
buffer [0] = (byte) (value ? 1 : 0);
OutStream.Write(buffer, 0, 1);
}
public virtual void Write(byte value) {
if (disposed)
throw new ObjectDisposedException ("BinaryWriter", "Cannot write to a closed BinaryWriter");
OutStream.WriteByte(value);
}
public virtual void Write(byte[] buffer) {
if (disposed)
throw new ObjectDisposedException ("BinaryWriter", "Cannot write to a closed BinaryWriter");
if (buffer == null)
throw new ArgumentNullException("buffer");
OutStream.Write(buffer, 0, buffer.Length);
}
public virtual void Write(byte[] buffer, int index, int count) {
if (disposed)
throw new ObjectDisposedException ("BinaryWriter", "Cannot write to a closed BinaryWriter");
if (buffer == null)
throw new ArgumentNullException("buffer");
OutStream.Write(buffer, index, count);
}
public virtual void Write(char ch) {
if (disposed)
throw new ObjectDisposedException ("BinaryWriter", "Cannot write to a closed BinaryWriter");
char[] dec = new char[1];
dec[0] = ch;
byte[] enc = m_encoding.GetBytes(dec, 0, 1);
OutStream.Write(enc, 0, enc.Length);
}
public virtual void Write(char[] chars) {
if (disposed)
throw new ObjectDisposedException ("BinaryWriter", "Cannot write to a closed BinaryWriter");
if (chars == null)
throw new ArgumentNullException("chars");
byte[] enc = m_encoding.GetBytes(chars, 0, chars.Length);
OutStream.Write(enc, 0, enc.Length);
}
public virtual void Write(char[] chars, int index, int count) {
if (disposed)
throw new ObjectDisposedException ("BinaryWriter", "Cannot write to a closed BinaryWriter");
if (chars == null)
throw new ArgumentNullException("chars");
byte[] enc = m_encoding.GetBytes(chars, index, count);
OutStream.Write(enc, 0, enc.Length);
}
unsafe public virtual void Write(decimal value) {
if (disposed)
throw new ObjectDisposedException ("BinaryWriter", "Cannot write to a closed BinaryWriter");
byte* value_ptr = (byte *)&value;
/*
* decimal in stream is lo32, mi32, hi32, ss32
* but its internal structure si ss32, hi32, lo32, mi32
*/
if (BitConverter.IsLittleEndian) {
for (int i = 0; i < 16; i++) {
if (i < 4)
buffer [i + 12] = value_ptr [i];
else if (i < 8)
buffer [i + 4] = value_ptr [i];
else if (i < 12)
buffer [i - 8] = value_ptr [i];
else
buffer [i - 8] = value_ptr [i];
}
} else {
for (int i = 0; i < 16; i++) {
if (i < 4)
buffer [15 - i] = value_ptr [i];
else if (i < 8)
buffer [15 - i] = value_ptr [i];
else if (i < 12)
buffer [11 - i] = value_ptr [i];
else
buffer [19 - i] = value_ptr [i];
}
}
OutStream.Write(buffer, 0, 16);
}
public virtual void Write(double value) {
if (disposed)
throw new ObjectDisposedException ("BinaryWriter", "Cannot write to a closed BinaryWriter");
OutStream.Write(BitConverterLE.GetBytes(value), 0, 8);
}
public virtual void Write(short value) {
if (disposed)
throw new ObjectDisposedException ("BinaryWriter", "Cannot write to a closed BinaryWriter");
buffer [0] = (byte) value;
buffer [1] = (byte) (value >> 8);
OutStream.Write(buffer, 0, 2);
}
public virtual void Write(int value) {
if (disposed)
throw new ObjectDisposedException ("BinaryWriter", "Cannot write to a closed BinaryWriter");
buffer [0] = (byte) value;
buffer [1] = (byte) (value >> 8);
buffer [2] = (byte) (value >> 16);
buffer [3] = (byte) (value >> 24);
OutStream.Write(buffer, 0, 4);
}
public virtual void Write(long value) {
if (disposed)
throw new ObjectDisposedException ("BinaryWriter", "Cannot write to a closed BinaryWriter");
for (int i = 0, sh = 0; i < 8; i++, sh += 8)
buffer [i] = (byte) (value >> sh);
OutStream.Write(buffer, 0, 8);
}
[CLSCompliant(false)]
public virtual void Write(sbyte value) {
if (disposed)
throw new ObjectDisposedException ("BinaryWriter", "Cannot write to a closed BinaryWriter");
buffer [0] = (byte) value;
OutStream.Write(buffer, 0, 1);
}
public virtual void Write(float value) {
if (disposed)
throw new ObjectDisposedException ("BinaryWriter", "Cannot write to a closed BinaryWriter");
OutStream.Write(BitConverterLE.GetBytes(value), 0, 4);
}
public virtual void Write(string value) {
if (disposed)
throw new ObjectDisposedException ("BinaryWriter", "Cannot write to a closed BinaryWriter");
int len = m_encoding.GetByteCount (value);
Write7BitEncodedInt (len);
if (stringBuffer == null) {
stringBuffer = new byte [512];
maxCharsPerRound = 512 / m_encoding.GetMaxByteCount (1);
}
int chpos = 0;
int chrem = value.Length;
while (chrem > 0) {
int cch = (chrem > maxCharsPerRound) ? maxCharsPerRound : chrem;
int blen = m_encoding.GetBytes (value, chpos, cch, stringBuffer, 0);
OutStream.Write (stringBuffer, 0, blen);
chpos += cch;
chrem -= cch;
}
}
[CLSCompliant(false)]
public virtual void Write(ushort value) {
if (disposed)
throw new ObjectDisposedException ("BinaryWriter", "Cannot write to a closed BinaryWriter");
buffer [0] = (byte) value;
buffer [1] = (byte) (value >> 8);
OutStream.Write(buffer, 0, 2);
}
[CLSCompliant(false)]
public virtual void Write(uint value) {
if (disposed)
throw new ObjectDisposedException ("BinaryWriter", "Cannot write to a closed BinaryWriter");
buffer [0] = (byte) value;
buffer [1] = (byte) (value >> 8);
buffer [2] = (byte) (value >> 16);
buffer [3] = (byte) (value >> 24);
OutStream.Write(buffer, 0, 4);
}
[CLSCompliant(false)]
public virtual void Write(ulong value) {
if (disposed)
throw new ObjectDisposedException ("BinaryWriter", "Cannot write to a closed BinaryWriter");
for (int i = 0, sh = 0; i < 8; i++, sh += 8)
buffer [i] = (byte) (value >> sh);
OutStream.Write(buffer, 0, 8);
}
protected void Write7BitEncodedInt(int value) {
do {
int high = (value >> 7) & 0x01ffffff;
byte b = (byte)(value & 0x7f);
if (high != 0) {
b = (byte)(b | 0x80);
}
Write(b);
value = high;
} while(value != 0);
}
}
}

View File

@@ -1,66 +0,0 @@
//
// System.IO.DriveNotFoundException.cs
//
// Author:
// Kornél Pál <http://www.kornelpal.hu/>
//
// Copyright (C) 2006 Kornél Pál
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
namespace System.IO
{
[Serializable]
[ComVisible (true)]
public class DriveNotFoundException : IOException
{
private const int ErrorCode = unchecked((int)0x80070003);
// Constructors
public DriveNotFoundException ()
: base ("Attempted to access a drive that is not available.")
{
this.HResult = ErrorCode;
}
public DriveNotFoundException (string message)
: base (message)
{
this.HResult = ErrorCode;
}
public DriveNotFoundException (string message, Exception innerException)
: base (message, innerException)
{
this.HResult = ErrorCode;
}
protected DriveNotFoundException (SerializationInfo info, StreamingContext context)
: base (info, context)
{
}
}
}

View File

@@ -1,68 +0,0 @@
//
// System.IO.EndOfStreamException.cs
//
// Author:
// Duncan Mak (duncan@ximian.com)
//
// 2002 (C) Ximian, Inc. http://www.ximian.com
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Globalization;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
namespace System.IO
{
[Serializable]
[ComVisible (true)]
public class EndOfStreamException : IOException
{
// Constructors
public EndOfStreamException ()
: base (Locale.GetText ("Failed to read past end of stream."))
{
}
public EndOfStreamException (string message)
: base (message)
{
}
protected EndOfStreamException (SerializationInfo info,
StreamingContext context)
: base (info, context)
{
}
public EndOfStreamException (string message, Exception innerException)
:base (message, innerException)
{
}
}
}

View File

@@ -1,139 +0,0 @@
//
// System.IO.FileLoadException.cs
//
// Author:
// Paolo Molaro (lupus@ximian.com)
// Duncan Mak (duncan@ximian.com)
//
// (C) 2001 Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Globalization;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Runtime.InteropServices;
namespace System.IO {
[Serializable]
[ComVisible (true)]
public class FileLoadException : IOException {
// Fields
const int Result = unchecked ((int)0x80070002);
string msg;
string fileName;
string fusionLog;
// Constructors
public FileLoadException ()
: base (Locale.GetText ("I/O Error"))
{
HResult = Result;
msg = Locale.GetText ("I/O Error");
}
public FileLoadException (string message)
: base (message)
{
HResult = Result;
msg = message;
}
public FileLoadException (string message, string fileName)
: base (message)
{
HResult = Result;
this.msg = message;
this.fileName = fileName;
}
public FileLoadException (string message, Exception inner)
: base (message, inner)
{
HResult = Result;
msg = message;
}
public FileLoadException (string message, string fileName, Exception inner)
: base (message, inner)
{
HResult = Result;
this.msg = message;
this.fileName = fileName;
}
protected FileLoadException (SerializationInfo info, StreamingContext context)
{
fileName = info.GetString ("FileLoad_FileName");
fusionLog = info.GetString ("FileLoad_FusionLog");
}
// Properties
public override string Message {
get { return msg; }
}
public string FileName
{
get { return fileName; }
}
public string FusionLog {
// note: MS runtime throws a SecurityException when the Exception is created
// but a FileLoadException once the exception as been thrown. Mono always
// throw a SecurityException in both case (anyway fusionLog is currently empty)
[SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
get { return fusionLog; }
}
// Methods
public override void GetObjectData (SerializationInfo info, StreamingContext context)
{
base.GetObjectData (info, context);
info.AddValue ("FileLoad_FileName", fileName);
info.AddValue ("FileLoad_FusionLog", fusionLog);
}
public override string ToString ()
{
StringBuilder sb = new StringBuilder (GetType ().FullName);
sb.AppendFormat (": {0}", msg);
if (fileName != null)
sb.AppendFormat (" : {0}", fileName);
if (this.InnerException != null)
sb.AppendFormat (" ----> {0}", InnerException);
if (this.StackTrace != null) {
sb.Append (Environment.NewLine);
sb.Append (StackTrace);
}
return sb.ToString ();
}
}
}

View File

@@ -1,144 +0,0 @@
//
// System.IO.FileNotFoundException.cs
//
// Author:
// Paolo Molaro (lupus@ximian.com)
// Duncan Mak (duncan@ximian.com)
//
// (C) 2001 Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Globalization;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Text;
using System.Runtime.InteropServices;
namespace System.IO {
[Serializable]
[ComVisible (true)]
public class FileNotFoundException : IOException {
const int Result = unchecked ((int)0x80131621);
private string fileName;
private string fusionLog;
// Constructors
public FileNotFoundException ()
: base (Locale.GetText ("Unable to find the specified file."))
{
HResult = Result;
}
public FileNotFoundException (string message)
: base (message)
{
HResult = Result;
}
public FileNotFoundException (string message, Exception innerException)
: base (message, innerException)
{
HResult = Result;
}
public FileNotFoundException (string message, string fileName)
: base (message)
{
HResult = Result;
this.fileName = fileName;
}
public FileNotFoundException (string message, string fileName, Exception innerException)
: base (message, innerException)
{
HResult = Result;
this.fileName = fileName;
}
protected FileNotFoundException (SerializationInfo info, StreamingContext context)
: base (info, context)
{
fileName = info.GetString ("FileNotFound_FileName");
fusionLog = info.GetString ("FileNotFound_FusionLog");
}
public string FileName
{
get { return fileName; }
}
public string FusionLog {
// note: MS runtime throws a SecurityException when the Exception is created
// but a FileLoadException once the exception as been thrown. Mono always
// throw a SecurityException in both case (anyway fusionLog is currently empty)
[SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
get { return fusionLog; }
}
public override string Message {
get {
if (base.message == null) {
if (fileName != null) {
string message = string.Format (
"Could not load file or assembly '{0}' or one of"
+ " its dependencies. The system cannot find the"
+ " file specified.", fileName);
return message;
}
}
return base.message;
}
}
public override void GetObjectData (SerializationInfo info, StreamingContext context)
{
base.GetObjectData (info, context);
info.AddValue ("FileNotFound_FileName", fileName);
info.AddValue ("FileNotFound_FusionLog", fusionLog);
}
public override string ToString ()
{
StringBuilder sb = new StringBuilder (GetType ().FullName);
sb.AppendFormat (": {0}", Message);
if (fileName != null && fileName.Length > 0) {
sb.Append (Environment.NewLine);
sb.AppendFormat ("File name: '{0}'", fileName);
}
if (this.InnerException != null)
sb.AppendFormat (" ---> {0}", InnerException);
if (this.StackTrace != null) {
sb.Append (Environment.NewLine);
sb.Append (StackTrace);
}
return sb.ToString ();
}
}
}

View File

@@ -148,7 +148,7 @@ namespace System.IO
}
#endif
internal FileStream (string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options, string msgPath, bool bFromProxy, bool useLongPath, bool checkHost)
internal FileStream (string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options, string msgPath, bool bFromProxy, bool useLongPath = false, bool checkHost = false)
: this (path, mode, access, share, bufferSize, false, options)
{
}
@@ -988,7 +988,7 @@ namespace System.IO
if (count > 0) {
// Use the fastest method, all range checks has been done
Buffer.BlockCopyInternal (buf, buf_offset, dest, dest_offset, count);
Buffer.InternalBlockCopy (buf, buf_offset, dest, dest_offset, count);
buf_offset += count;
}

View File

@@ -1,14 +1,10 @@
//
// System.IO.DirectoryNotFoundException.cs
// HGlobalUnmanagedMemoryStream.cs
//
// Author:
// Paolo Molaro (lupus@ximian.com)
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// (C) 2001 Ximian, Inc. http://www.ximian.com
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
// Copyright (C) 2015 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -17,10 +13,10 @@
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -30,34 +26,27 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
namespace System.IO {
namespace System.IO
{
unsafe class HGlobalUnmanagedMemoryStream : UnmanagedMemoryStream
{
IntPtr ptr;
[Serializable]
[ComVisible (true)]
public class DirectoryNotFoundException : IOException {
// Constructors
public DirectoryNotFoundException ()
: base ("Directory not found")
public HGlobalUnmanagedMemoryStream (byte* pointer, long length, IntPtr ptr)
: base (pointer, length, length, FileAccess.ReadWrite)
{
this.ptr = ptr;
}
public DirectoryNotFoundException (string message)
: base (message)
protected override void Dispose (bool disposing)
{
}
if (_isOpen) {
Marshal.FreeHGlobal (ptr);
}
public DirectoryNotFoundException (string message, Exception innerException)
: base (message, innerException)
{
base.Dispose (disposing);
}
protected DirectoryNotFoundException (SerializationInfo info, StreamingContext context)
: base (info, context)
{
}
}
}
}
}

View File

@@ -1,68 +0,0 @@
//
// System.IO.IOException.cs
//
// Author:
// Paolo Molaro (lupus@ximian.com)
//
// (C) 2001 Ximian, Inc. http://www.ximian.com
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
namespace System.IO {
[Serializable]
[ComVisible (true)]
public class IOException : SystemException {
// Constructors
public IOException ()
: base ("I/O Error")
{
}
public IOException (string message)
: base (message)
{
}
public IOException (string message, Exception innerException)
: base (message, innerException)
{
}
protected IOException (SerializationInfo info, StreamingContext context)
: base (info, context)
{
}
public IOException (string message, int hresult)
: base (message)
{
this.HResult = hresult;
}
}
}

View File

@@ -396,7 +396,7 @@ namespace System.IO {
if (current [1] == VolumeSeparatorChar)
path = current.Substring (0, 2) + path;
else
path = current.Substring (0, current.IndexOf ('\\', current.IndexOfOrdinalUnchecked ("\\\\") + 1));
path = current.Substring (0, current.IndexOf ('\\', current.IndexOfUnchecked ("\\\\", 0, current.Length) + 1));
}
}

View File

@@ -1,68 +0,0 @@
//
// System.IO.PathTooLongException.cs
//
// Author:
// Duncan Mak (duncan@ximian.com)
//
// 2002 (C) Ximian, Inc. http://www.ximian.com
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Globalization;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
namespace System.IO
{
[Serializable]
[ComVisible (true)]
public class PathTooLongException : IOException
{
// Constructors
public PathTooLongException ()
: base (Locale.GetText ("Pathname is longer than the maximum length"))
{
}
public PathTooLongException (string message)
: base (message)
{
}
protected PathTooLongException (SerializationInfo info,
StreamingContext context)
: base (info, context)
{
}
public PathTooLongException (string message, Exception innerException)
:base (message, innerException)
{
}
}
}

View File

@@ -1,477 +0,0 @@
//
// System.IO.UnmanagedMemoryAccessor.cs
//
// Author:
// Zoltan Varga (vargaz@gmail.com)
// Marek Safar (marek.safar@gmail.com)
//
// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
namespace System.IO
{
[MonoTODO ("Offset is ignored")]
public class UnmanagedMemoryAccessor : IDisposable {
SafeBuffer buffer;
#pragma warning disable 414
long offset;
#pragma warning restore
long capacity;
bool canwrite, canread;
protected UnmanagedMemoryAccessor ()
{
}
public UnmanagedMemoryAccessor (SafeBuffer buffer, long offset, long capacity)
{
Initialize (buffer, offset, capacity, FileAccess.ReadWrite);
}
public UnmanagedMemoryAccessor (SafeBuffer buffer, long offset, long capacity, FileAccess access)
{
Initialize (buffer, offset, capacity, access);
}
[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
protected void Initialize(SafeBuffer buffer, long offset, long capacity, FileAccess access)
{
if (buffer == null)
throw new ArgumentNullException ("buffer");
if (offset < 0)
throw new ArgumentOutOfRangeException ("offset");
if (capacity < 0)
throw new ArgumentOutOfRangeException ("capacity");
if (access == FileAccess.Read || access == FileAccess.ReadWrite)
canread = true;
if (access == FileAccess.Write || access == FileAccess.ReadWrite)
canwrite = true;
if (this.buffer != null)
Dispose (true);
this.buffer = buffer;
this.offset = offset;
this.capacity = capacity;
}
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}
protected virtual void Dispose (bool disposing)
{
if (buffer != null){
if (disposing){
buffer.Dispose ();
}
}
buffer = null;
}
public byte ReadByte (long position)
{
if (!canread)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
return buffer.Read<byte> ((ulong) position);
}
public bool ReadBoolean (long position)
{
if (!canread)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
return buffer.Read<bool> ((ulong) position);
}
public char ReadChar (long position)
{
if (!canread)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
return buffer.Read<char> ((ulong) position);
}
public decimal ReadDecimal (long position)
{
if (!canread)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
return buffer.Read<decimal> ((ulong) position);
}
public double ReadDouble (long position)
{
if (!canread)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
return buffer.Read<double> ((ulong) position);
}
public short ReadInt16 (long position)
{
if (!canread)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
return buffer.Read<short> ((ulong) position);
}
public int ReadInt32 (long position)
{
if (!canread)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
return buffer.Read<int> ((ulong) position);
}
public long ReadInt64 (long position)
{
if (!canread)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
return buffer.Read<long> ((ulong) position);
}
[CLSCompliant (false)]
public sbyte ReadSByte (long position)
{
if (!canread)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
return buffer.Read<sbyte> ((ulong) position);
}
public float ReadSingle (long position)
{
if (!canread)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
return buffer.Read<float> ((ulong) position);
}
[CLSCompliant (false)]
public ushort ReadUInt16 (long position)
{
if (!canread)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
return buffer.Read<ushort> ((ulong) position);
}
[CLSCompliant (false)]
public uint ReadUInt32 (long position)
{
if (!canread)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
return buffer.Read<uint> ((ulong) position);
}
[CLSCompliant (false)]
public ulong ReadUInt64 (long position)
{
if (!canread)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
return buffer.Read<ulong> ((ulong) position);
}
public void Read<T> (long position, out T structure) where T : struct
{
if (!canread)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
structure = buffer.Read<T> ((ulong) position);
}
public int ReadArray<T> (long position, T [] array, int offset, int count) where T : struct
{
if (position < 0)
throw new ArgumentOutOfRangeException ();
long left = capacity - position;
var slots = Math.Min (count, (int)(left / Marshal.SizeOf (typeof (T))));
buffer.ReadArray ((ulong) position, array, offset, slots);
return slots;
}
public void Write (long position, bool value)
{
if (!canwrite)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
buffer.Write ((ulong)position, value);
}
public void Write (long position, byte value)
{
if (!canwrite)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
buffer.Write ((ulong)position, value);
}
public void Write (long position, char value)
{
if (!canwrite)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
buffer.Write ((ulong)position, value);
}
public void Write (long position, decimal value)
{
if (!canwrite)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
buffer.Write ((ulong)position, value);
}
public void Write (long position, double value)
{
if (!canwrite)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
buffer.Write ((ulong)position, value);
}
public void Write (long position, short value)
{
if (!canwrite)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
buffer.Write ((ulong)position, value);
}
public void Write (long position, int value)
{
if (!canwrite)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
buffer.Write ((ulong)position, value);
}
public void Write (long position, long value)
{
if (!canwrite)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
buffer.Write ((ulong)position, value);
}
[CLSCompliant (false)]
public void Write (long position, sbyte value)
{
if (!canwrite)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
buffer.Write ((ulong)position, value);
}
public void Write (long position, float value)
{
if (!canwrite)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
buffer.Write ((ulong)position, value);
}
[CLSCompliant (false)]
public void Write (long position, ushort value)
{
if (!canwrite)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
buffer.Write ((ulong)position, value);
}
[CLSCompliant (false)]
public void Write (long position, uint value)
{
if (!canwrite)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
buffer.Write ((ulong)position, value);
}
[CLSCompliant (false)]
public void Write (long position, ulong value)
{
if (!canwrite)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
buffer.Write ((ulong)position, value);
}
public void Write<T> (long position, ref T structure) where T : struct
{
if (!canwrite)
throw new NotSupportedException ();
if (buffer == null)
throw new ObjectDisposedException ("buffer");
if (position < 0)
throw new ArgumentOutOfRangeException ();
buffer.Write<T> ((ulong)position, structure);
}
public void WriteArray<T> (long position, T [] array, int offset, int count) where T : struct
{
buffer.WriteArray ((ulong)position, array, offset, count);
}
public bool CanRead {
get { return canread; }
}
public bool CanWrite {
get { return canwrite; }
}
public long Capacity {
get { return capacity; }
}
protected bool IsOpen {
get { return buffer != null; }
}
}
}

View File

@@ -1,497 +0,0 @@
//
// System.IO.UnmanagedMemoryStream.cs
//
// Copyright (C) 2006 Sridhar Kulkarni, All Rights Reserved
//
// Authors:
// Sridhar Kulkarni (sridharkulkarni@gmail.com)
// Gert Driesen (drieseng@users.sourceforge.net)
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005-2006, 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
namespace System.IO
{
public class UnmanagedMemoryStream : Stream
{
long length;
internal bool closed;
long capacity;
FileAccess fileaccess;
IntPtr initial_pointer;
long initial_position;
long current_position;
SafeBuffer safebuffer;
Task<int> read_task;
internal event EventHandler Closed;
#region Constructor
protected UnmanagedMemoryStream()
{
closed = true;
}
[CLSCompliantAttribute(false)]
public unsafe UnmanagedMemoryStream (byte *pointer, long length) :
this (pointer, length, length, FileAccess.Read)
{
}
[CLSCompliantAttribute(false)]
public unsafe UnmanagedMemoryStream (byte *pointer, long length, long capacity, FileAccess access)
{
closed = true;
Initialize (pointer, length, capacity, access);
}
public UnmanagedMemoryStream (SafeBuffer buffer, long offset, long length) :
this (buffer, offset, length, FileAccess.Read)
{
}
public UnmanagedMemoryStream (SafeBuffer buffer, long offset, long length, FileAccess access)
{
closed = true;
Initialize (buffer, offset, length, access);
}
#endregion
#region Properties
public override bool CanRead {
get {
return (!closed && (fileaccess != FileAccess.Write));
}
}
public override bool CanSeek {
get {
return !closed;
}
}
public override bool CanWrite {
get {
return (!closed && (fileaccess != FileAccess.Read));
}
}
public long Capacity {
get {
if (closed)
throw new ObjectDisposedException("The stream is closed");
else
return (capacity);
}
}
public override long Length {
get {
if (closed)
throw new ObjectDisposedException("The stream is closed");
else
return (length);
}
}
public override long Position {
get {
if (closed)
throw new ObjectDisposedException("The stream is closed");
return (current_position);
}
set {
if (closed)
throw new ObjectDisposedException("The stream is closed");
if (value < 0)
throw new ArgumentOutOfRangeException("value", "Non-negative number required.");
if (value > (long)Int32.MaxValue)
throw new ArgumentOutOfRangeException("value", "The position is larger than Int32.MaxValue.");
current_position = value;
}
}
[CLSCompliantAttribute (false)]
public unsafe byte* PositionPointer {
get {
if (safebuffer != null)
throw new NotSupportedException ("Not supported when using SafeBuffer");
if (closed)
throw new ObjectDisposedException("The stream is closed");
if (current_position >= length)
throw new IndexOutOfRangeException ("value");
return (byte *) initial_pointer + current_position;
}
set {
if (safebuffer != null)
throw new NotSupportedException ("Not supported when using SafeBuffer");
if (closed)
throw new ObjectDisposedException("The stream is closed");
if (value < (byte *)initial_pointer)
throw new IOException ("Address is below the inital address");
Position = value - (byte*) initial_pointer;
}
}
#endregion
#region Methods
public override int Read ([InAttribute] [OutAttribute] byte[] buffer, int offset, int count)
{
if (closed)
throw new ObjectDisposedException("The stream is closed");
if (buffer == null)
throw new ArgumentNullException("buffer");
if (offset < 0)
throw new ArgumentOutOfRangeException("offset", "Non-negative number required.");
if (count < 0)
throw new ArgumentOutOfRangeException("count", "Non-negative number required.");
if ((buffer.Length - offset) < count)
throw new ArgumentException("The length of the buffer array minus the offset parameter is less than the count parameter");
if (fileaccess == FileAccess.Write)
throw new NotSupportedException("Stream does not support reading");
if (current_position >= length)
return 0;
int progress = current_position + count < length ? count : (int) (length - current_position);
if (safebuffer != null) {
unsafe {
byte *ptr = null;
try {
safebuffer.AcquirePointer (ref ptr);
Marshal.Copy (new IntPtr (ptr + current_position), buffer, offset, progress);
} finally {
if (ptr != null)
safebuffer.ReleasePointer ();
}
}
} else
{
Marshal.Copy (new IntPtr (initial_pointer.ToInt64 () + current_position), buffer, offset, progress);
}
current_position += progress;
return progress;
}
public override Task<int> ReadAsync (byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
if (buffer == null)
throw new ArgumentNullException("buffer");
if (offset < 0)
throw new ArgumentOutOfRangeException("offset", "Non-negative number required.");
if (count < 0)
throw new ArgumentOutOfRangeException("count", "Non-negative number required.");
if ((buffer.Length - offset) < count)
throw new ArgumentException("The length of the buffer array minus the offset parameter is less than the count parameter");
if (cancellationToken.IsCancellationRequested)
return TaskConstants<int>.Canceled;
try {
count = Read (buffer, offset, count);
// Try not to allocate a new task for every buffer read
if (read_task == null || read_task.Result != count)
read_task = Task<int>.FromResult (count);
return read_task;
} catch (Exception ex) {
return Task.FromException<int> (ex);
}
}
public override int ReadByte ()
{
if (closed)
throw new ObjectDisposedException("The stream is closed");
if (fileaccess== FileAccess.Write)
throw new NotSupportedException("Stream does not support reading");
if (current_position >= length)
return (-1);
if (safebuffer != null) {
unsafe {
byte *ptr = null;
try {
safebuffer.AcquirePointer (ref ptr);
return (int) Marshal.ReadByte (new IntPtr (ptr), (int) current_position++);
} finally {
if (ptr != null)
safebuffer.ReleasePointer ();
}
}
} else
{
return (int) Marshal.ReadByte(initial_pointer, (int) current_position++);
}
}
public override long Seek (long offset, SeekOrigin loc)
{
if (closed)
throw new ObjectDisposedException("The stream is closed");
long refpoint;
switch(loc) {
case SeekOrigin.Begin:
if (offset < 0)
throw new IOException("An attempt was made to seek before the beginning of the stream");
refpoint = initial_position;
break;
case SeekOrigin.Current:
refpoint = current_position;
break;
case SeekOrigin.End:
refpoint = length;
break;
default:
throw new ArgumentException("Invalid SeekOrigin option");
}
refpoint += offset;
if (refpoint < initial_position)
throw new IOException("An attempt was made to seek before the beginning of the stream");
current_position = refpoint;
return(current_position);
}
public override void SetLength (long value)
{
if (safebuffer != null)
throw new NotSupportedException ("Not supported when using SafeBuffer");
if (closed)
throw new ObjectDisposedException("The stream is closed");
if (value < 0)
throw new ArgumentOutOfRangeException("length", "Non-negative number required.");
if (value > capacity)
throw new IOException ("Unable to expand length of this stream beyond its capacity.");
if (fileaccess == FileAccess.Read)
throw new NotSupportedException ("Stream does not support writing.");
length = value;
if (length < current_position)
current_position = length;
}
public override void Flush ()
{
if (closed)
throw new ObjectDisposedException("The stream is closed");
//This method performs no action for this class
//but is included as part of the Stream base class
}
public override Task FlushAsync (CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
return TaskConstants.Canceled;
try {
Flush ();
return TaskConstants.Finished;
} catch (Exception ex) {
return Task.FromException<object> (ex);
}
}
protected override void Dispose (bool disposing)
{
if (closed)
return;
closed = true;
if (Closed != null)
Closed (this, null);
}
public override void Write (byte[] buffer, int offset, int count)
{
if (closed)
throw new ObjectDisposedException("The stream is closed");
if (buffer == null)
throw new ArgumentNullException("The buffer parameter is a null reference");
if (offset < 0)
throw new ArgumentOutOfRangeException("offset", "Non-negative number required.");
if (count < 0)
throw new ArgumentOutOfRangeException("count", "Non-negative number required.");
if ((buffer.Length - offset) < count)
throw new ArgumentException("The length of the buffer array minus the offset parameter is less than the count parameter");
if (current_position > capacity - count)
throw new NotSupportedException ("Unable to expand length of this stream beyond its capacity.");
if (fileaccess == FileAccess.Read)
throw new NotSupportedException ("Stream does not support writing.");
if (safebuffer != null) {
unsafe {
byte *dest = null;
try {
safebuffer.AcquirePointer (ref dest);
fixed (byte *src = buffer) {
dest += current_position;
String.memcpy (dest, src + offset, count);
}
} finally {
if (dest != null)
safebuffer.ReleasePointer ();
}
}
} else
{
unsafe {
fixed (byte *src = buffer) {
byte *dest = (byte *) initial_pointer + current_position;
String.memcpy (dest, src + offset, count);
}
}
}
current_position += count;
if (current_position > length)
length = current_position;
}
public override Task WriteAsync (byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
if (buffer == null)
throw new ArgumentNullException("The buffer parameter is a null reference");
if (offset < 0)
throw new ArgumentOutOfRangeException("offset", "Non-negative number required.");
if (count < 0)
throw new ArgumentOutOfRangeException("count", "Non-negative number required.");
if ((buffer.Length - offset) < count)
throw new ArgumentException("The length of the buffer array minus the offset parameter is less than the count parameter");
if (current_position > capacity - count)
throw new NotSupportedException ("Unable to expand length of this stream beyond its capacity.");
if (cancellationToken.IsCancellationRequested)
return TaskConstants.Canceled;
try {
Write (buffer, offset, count);
return TaskConstants.Finished;
} catch (Exception ex) {
return Task.FromException<object> (ex);
}
}
public override void WriteByte (byte value)
{
if (closed)
throw new ObjectDisposedException("The stream is closed");
if (current_position == capacity)
throw new NotSupportedException("The current position is at the end of the capacity of the stream");
if (fileaccess == FileAccess.Read)
throw new NotSupportedException("Stream does not support writing.");
if (safebuffer != null) {
unsafe {
byte *dest = null;
try {
safebuffer.AcquirePointer (ref dest);
dest += current_position++;
*dest = value;
} finally {
if (dest != null)
safebuffer.ReleasePointer ();
}
}
} else
{
unsafe {
byte *dest = (byte *) initial_pointer + (int) current_position++;
*dest = value;
}
}
if (current_position > length)
length = current_position;
}
[CLSCompliant (false)]
protected unsafe void Initialize (byte* pointer, long length,
long capacity,
FileAccess access)
{
if (pointer == null)
throw new ArgumentNullException("pointer");
if (length < 0)
throw new ArgumentOutOfRangeException("length", "Non-negative number required.");
if (capacity < 0)
throw new ArgumentOutOfRangeException("capacity", "Non-negative number required.");
if (length > capacity)
throw new ArgumentOutOfRangeException("length", "The length cannot be greater than the capacity.");
if ((access < FileAccess.Read) || (access > FileAccess.ReadWrite))
throw new ArgumentOutOfRangeException ("access", "Enum value was out of legal range.");
if (!closed)
throw new InvalidOperationException ("Called Initialize twice");
fileaccess = access;
this.length = length;
this.capacity = capacity;
initial_position = 0;
current_position = initial_position;
initial_pointer = new IntPtr ((void*)pointer);
closed = false;
}
protected void Initialize (SafeBuffer buffer, long offset, long length, FileAccess access)
{
if (buffer == null)
throw new ArgumentNullException ("buffer");
if (offset < 0)
throw new ArgumentOutOfRangeException ("offset");
if (length < 0)
throw new ArgumentOutOfRangeException ("length");
ulong blength = buffer.ByteLength;
if ((blength - (ulong) length) < (ulong) offset)
throw new ArgumentException ("Invalid offset and/or length");
if (access < FileAccess.Read || access > FileAccess.ReadWrite)
throw new ArgumentOutOfRangeException ("access");
if (!closed)
throw new InvalidOperationException ("Called Initialize twice");
this.length = length;
this.capacity = length;
this.fileaccess = access;
this.safebuffer = buffer;
initial_position = offset;
current_position = offset;
closed = false;
}
#endregion
}
}