Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -58,11 +58,10 @@ namespace System.IO {
private bool m_disposed;
public BinaryReader(Stream input)
: this(input, Encoding.UTF8UnmarkedUnsafe)
: this(input, EncodingHelper.UTF8UnmarkedUnsafe)
{
}
#if NET_4_5
readonly bool leave_open;
public BinaryReader(Stream input, Encoding encoding)
@@ -71,11 +70,6 @@ namespace System.IO {
}
public BinaryReader(Stream input, Encoding encoding, bool leaveOpen)
#else
const bool leave_open = false;
public BinaryReader(Stream input, Encoding encoding)
#endif
{
if (input == null || encoding == null)
throw new ArgumentNullException(Locale.GetText ("Input or Encoding is a null reference."));
@@ -84,9 +78,7 @@ namespace System.IO {
m_stream = input;
m_encoding = encoding;
#if NET_4_5
leave_open = leaveOpen;
#endif
decoder = encoding.GetDecoder ();
// internal buffer size is documented to be between 16 and the value
@@ -117,11 +109,7 @@ namespace System.IO {
charBuffer = null;
}
#if NET_4_0
public void Dispose ()
#else
void IDisposable.Dispose()
#endif
{
Dispose (true);
}

View File

@@ -51,15 +51,14 @@ namespace System.IO {
int maxCharsPerRound;
bool disposed;
protected BinaryWriter() : this (Stream.Null, Encoding.UTF8UnmarkedUnsafe)
protected BinaryWriter() : this (Stream.Null, EncodingHelper.UTF8UnmarkedUnsafe)
{
}
public BinaryWriter(Stream output) : this(output, Encoding.UTF8UnmarkedUnsafe)
public BinaryWriter(Stream output) : this(output, EncodingHelper.UTF8UnmarkedUnsafe)
{
}
#if NET_4_5
readonly bool leave_open;
public BinaryWriter(Stream output, Encoding encoding)
@@ -68,11 +67,6 @@ namespace System.IO {
}
public BinaryWriter(Stream output, Encoding encoding, bool leaveOpen)
#else
const bool leave_open = false;
public BinaryWriter(Stream output, Encoding encoding)
#endif
{
if (output == null)
throw new ArgumentNullException("output");
@@ -81,9 +75,7 @@ namespace System.IO {
if (!output.CanWrite)
throw new ArgumentException(Locale.GetText ("Stream does not support writing or already closed."));
#if NET_4_5
leave_open = leaveOpen;
#endif
OutStream = output;
m_encoding = encoding;
buffer = new byte [16];
@@ -100,11 +92,7 @@ namespace System.IO {
Dispose (true);
}
#if NET_4_0
public void Dispose ()
#else
void IDisposable.Dispose()
#endif
{
Dispose (true);
}

View File

@@ -1,323 +0,0 @@
//
// System.IO.BufferedStream
//
// Author:
// Matt Kimball (matt@kimball.net)
// Ville Palo <vi64pa@kolumbus.fi>
//
// Copyright (C) 2004 Novell (http://www.novell.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.Globalization;
using System.Runtime.InteropServices;
namespace System.IO {
[ComVisible (true)]
public sealed class BufferedStream : Stream {
Stream m_stream;
byte[] m_buffer;
int m_buffer_pos;
int m_buffer_read_ahead;
bool m_buffer_reading;
private bool disposed = false;
public BufferedStream (Stream stream) : this (stream, 4096)
{
}
public BufferedStream (Stream stream, int bufferSize)
{
if (stream == null)
throw new ArgumentNullException ("stream");
// LAMESPEC: documented as < 0
if (bufferSize <= 0)
throw new ArgumentOutOfRangeException ("bufferSize", "<= 0");
if (!stream.CanRead && !stream.CanWrite) {
throw new ObjectDisposedException (
Locale.GetText ("Cannot access a closed Stream."));
}
m_stream = stream;
m_buffer = new byte [bufferSize];
}
public override bool CanRead {
get {
return m_stream.CanRead;
}
}
public override bool CanWrite {
get {
return m_stream.CanWrite;
}
}
public override bool CanSeek {
get {
return m_stream.CanSeek;
}
}
public override long Length {
get {
Flush ();
return m_stream.Length;
}
}
public override long Position {
get {
CheckObjectDisposedException ();
return m_stream.Position - m_buffer_read_ahead + m_buffer_pos;
}
set {
if (value < Position && (Position - value <= m_buffer_pos) && m_buffer_reading) {
m_buffer_pos -= (int) (Position - value);
}
else if (value > Position && (value - Position < m_buffer_read_ahead - m_buffer_pos) && m_buffer_reading) {
m_buffer_pos += (int) (value - Position);
}
else {
Flush();
m_stream.Position = value;
}
}
}
protected override void Dispose (bool disposing)
{
if (disposed)
return;
if (m_buffer != null)
Flush();
m_stream.Close();
m_buffer = null;
disposed = true;
}
public override void Flush ()
{
CheckObjectDisposedException ();
if (m_buffer_reading) {
if (CanSeek)
m_stream.Position = Position;
} else if (m_buffer_pos > 0) {
m_stream.Write(m_buffer, 0, m_buffer_pos);
}
m_buffer_read_ahead = 0;
m_buffer_pos = 0;
}
public override long Seek (long offset, SeekOrigin origin)
{
CheckObjectDisposedException ();
if (!CanSeek) {
throw new NotSupportedException (
Locale.GetText ("Non seekable stream."));
}
Flush ();
return m_stream.Seek (offset, origin);
}
public override void SetLength (long value)
{
CheckObjectDisposedException ();
if (value < 0)
throw new ArgumentOutOfRangeException ("value must be positive");
if (!m_stream.CanWrite && !m_stream.CanSeek)
throw new NotSupportedException ("the stream cannot seek nor write.");
if ((m_stream == null) || (!m_stream.CanRead && !m_stream.CanWrite))
throw new IOException ("the stream is not open");
m_stream.SetLength(value);
if (Position > value)
Position = value;
}
public override int ReadByte ()
{
CheckObjectDisposedException ();
if (!m_stream.CanRead) {
throw new NotSupportedException (
Locale.GetText ("Cannot read from stream"));
}
if (!m_buffer_reading) {
Flush ();
m_buffer_reading = true;
}
if (1 <= m_buffer_read_ahead - m_buffer_pos) {
return m_buffer [m_buffer_pos++];
}
else
{
if (m_buffer_pos >= m_buffer_read_ahead) {
m_buffer_pos = 0;
m_buffer_read_ahead = 0;
}
m_buffer_read_ahead = m_stream.Read (m_buffer, 0, m_buffer.Length);
if (1 <= m_buffer_read_ahead) {
return m_buffer [m_buffer_pos++];
} else {
return -1;
}
}
}
public override void WriteByte (byte value)
{
CheckObjectDisposedException ();
if (!m_stream.CanWrite) {
throw new NotSupportedException (
Locale.GetText ("Cannot write to stream"));
}
if (m_buffer_reading) {
Flush ();
m_buffer_reading = false;
}
else
// reordered to avoid possible integer overflow
if (m_buffer_pos >= m_buffer.Length - 1) {
Flush ();
}
m_buffer [m_buffer_pos++] = value;
}
public override int Read ([In,Out] byte[] array, int offset, int count)
{
if (array == null)
throw new ArgumentNullException ("array");
CheckObjectDisposedException ();
if (!m_stream.CanRead) {
throw new NotSupportedException (
Locale.GetText ("Cannot read from stream"));
}
if (offset < 0)
throw new ArgumentOutOfRangeException ("offset", "< 0");
if (count < 0)
throw new ArgumentOutOfRangeException ("count", "< 0");
// re-ordered to avoid possible integer overflow
if (array.Length - offset < count)
throw new ArgumentException ("array.Length - offset < count");
if (!m_buffer_reading) {
Flush();
m_buffer_reading = true;
}
if (count <= m_buffer_read_ahead - m_buffer_pos) {
Buffer.BlockCopyInternal (m_buffer, m_buffer_pos, array, offset, count);
m_buffer_pos += count;
if (m_buffer_pos == m_buffer_read_ahead) {
m_buffer_pos = 0;
m_buffer_read_ahead = 0;
}
return count;
}
int ret = m_buffer_read_ahead - m_buffer_pos;
Buffer.BlockCopyInternal (m_buffer, m_buffer_pos, array, offset, ret);
m_buffer_pos = 0;
m_buffer_read_ahead = 0;
offset += ret;
count -= ret;
if (count >= m_buffer.Length) {
ret += m_stream.Read (array, offset, count);
} else {
m_buffer_read_ahead = m_stream.Read (m_buffer, 0, m_buffer.Length);
if (count < m_buffer_read_ahead) {
Buffer.BlockCopyInternal (m_buffer, 0, array, offset, count);
m_buffer_pos = count;
ret += count;
} else {
Buffer.BlockCopyInternal (m_buffer, 0, array, offset, m_buffer_read_ahead);
ret += m_buffer_read_ahead;
m_buffer_read_ahead = 0;
}
}
return ret;
}
public override void Write (byte[] array, int offset, int count)
{
if (array == null)
throw new ArgumentNullException ("array");
CheckObjectDisposedException ();
if (!m_stream.CanWrite) {
throw new NotSupportedException (
Locale.GetText ("Cannot write to stream"));
}
if (offset < 0)
throw new ArgumentOutOfRangeException ("offset", "< 0");
if (count < 0)
throw new ArgumentOutOfRangeException ("count", "< 0");
// avoid possible integer overflow
if (array.Length - offset < count)
throw new ArgumentException ("array.Length - offset < count");
if (m_buffer_reading) {
Flush();
m_buffer_reading = false;
}
// reordered to avoid possible integer overflow
if (m_buffer_pos >= m_buffer.Length - count) {
Flush ();
m_stream.Write (array, offset, count);
}
else {
Buffer.BlockCopyInternal (array, offset, m_buffer, m_buffer_pos, count);
m_buffer_pos += count;
}
}
private void CheckObjectDisposedException ()
{
if (disposed) {
throw new ObjectDisposedException ("BufferedStream",
Locale.GetText ("Stream is closed"));
}
}
}
}

View File

@@ -498,7 +498,6 @@ namespace System.IO
return result;
}
#if NET_4_0
public static string[] GetFileSystemEntries (string path, string searchPattern, SearchOption searchOption)
{
// Take the simple way home:
@@ -632,7 +631,6 @@ namespace System.IO
return EnumerateKind (path, "*", SearchOption.TopDirectoryOnly, FileAttributes.Normal | FileAttributes.Directory);
}
#endif
public static DirectorySecurity GetAccessControl (string path, AccessControlSections includeSections)
{

View File

@@ -204,9 +204,7 @@ namespace System.IO {
return GetFileSystemInfos (searchPattern, SearchOption.TopDirectoryOnly);
}
#if NET_4_0
public
#endif
FileSystemInfo [] GetFileSystemInfos (string searchPattern, SearchOption searchOption)
{
if (searchPattern == null)
@@ -356,7 +354,6 @@ namespace System.IO {
Directory.SetAccessControl (FullPath, directorySecurity);
}
#if NET_4_0
public IEnumerable<DirectoryInfo> EnumerateDirectories ()
{
@@ -462,6 +459,5 @@ namespace System.IO {
}
#endif
}
}

View File

@@ -575,7 +575,7 @@ namespace System.IO
public static void WriteAllText (string path, string contents)
{
WriteAllText (path, contents, Encoding.UTF8Unmarked);
WriteAllText (path, contents, EncodingHelper.UTF8Unmarked);
}
public static void WriteAllText (string path, string contents, Encoding encoding)
@@ -616,7 +616,6 @@ namespace System.IO
throw new NotSupportedException (Locale.GetText ("File encryption isn't supported on any file system."));
}
#if NET_4_0
public static IEnumerable<string> ReadLines (string path)
{
return ReadLines (File.OpenText (path));
@@ -689,6 +688,5 @@ namespace System.IO
w.WriteLine (line);
}
}
#endif
}
}

View File

@@ -55,10 +55,8 @@ namespace System.IO
SparseFile = 0x00200,
System = 0x00004,
Temporary = 0x00100,
#if NET_4_5
IntegrityStream = 0x8000,
NoScrubData = 0x20000,
#endif
//
// This flag is used internall by Mono to make it Executable
//

File diff suppressed because it is too large Load Diff

View File

@@ -10,6 +10,7 @@ namespace System.IO {
class LogcatTextWriter : TextWriter {
const string LibLog = "/system/lib/liblog.so";
const string LibLog64 = "/system/lib64/liblog.so";
TextWriter stdout;
readonly string appname;
@@ -63,10 +64,10 @@ namespace System.IO {
public static bool IsRunningOnAndroid ()
{
return File.Exists (LibLog);
return File.Exists (LibLog) || File.Exists (LibLog64);
}
[DllImport (LibLog)]
[DllImport ("liblog")]
static extern void __android_log_print (LogLevel level, string appname, string format, string args, IntPtr zero);
static void Log (LogLevel level, string appname, string log)

File diff suppressed because it is too large Load Diff

View File

@@ -35,6 +35,7 @@ using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.Win32.SafeHandles;
#if NET_2_1
using System.IO.IsolatedStorage;
#endif
@@ -203,7 +204,19 @@ namespace System.IO
public extern static bool SetFileAttributes (string path, FileAttributes attrs, out MonoIOError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static MonoFileType GetFileType (IntPtr handle, out MonoIOError error);
private extern static MonoFileType GetFileType (IntPtr handle, out MonoIOError error);
public static MonoFileType GetFileType (SafeHandle safeHandle, out MonoIOError error)
{
bool release = false;
try {
safeHandle.DangerousAddRef (ref release);
return GetFileType (safeHandle.DangerousGetHandle (), out error);
} finally {
if (release)
safeHandle.DangerousRelease ();
}
}
//
// Find file methods
@@ -288,46 +301,144 @@ namespace System.IO
FileShare share,
FileOptions options,
out MonoIOError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static bool Close (IntPtr handle,
out MonoIOError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static int Read (IntPtr handle, byte [] dest,
private extern static int Read (IntPtr handle, byte [] dest,
int dest_offset, int count,
out MonoIOError error);
public static int Read (SafeHandle safeHandle, byte [] dest,
int dest_offset, int count,
out MonoIOError error)
{
bool release = false;
try {
safeHandle.DangerousAddRef (ref release);
return Read (safeHandle.DangerousGetHandle (), dest, dest_offset, count, out error);
} finally {
if (release)
safeHandle.DangerousRelease ();
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static int Write (IntPtr handle, [In] byte [] src,
private extern static int Write (IntPtr handle, [In] byte [] src,
int src_offset, int count,
out MonoIOError error);
public static int Write (SafeHandle safeHandle, byte [] src,
int src_offset, int count,
out MonoIOError error)
{
bool release = false;
try {
safeHandle.DangerousAddRef (ref release);
return Write (safeHandle.DangerousGetHandle (), src, src_offset, count, out error);
} finally {
if (release)
safeHandle.DangerousRelease ();
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static long Seek (IntPtr handle, long offset,
private extern static long Seek (IntPtr handle, long offset,
SeekOrigin origin,
out MonoIOError error);
public static long Seek (SafeHandle safeHandle, long offset,
SeekOrigin origin,
out MonoIOError error)
{
bool release = false;
try {
safeHandle.DangerousAddRef (ref release);
return Seek (safeHandle.DangerousGetHandle (), offset, origin, out error);
} finally {
if (release)
safeHandle.DangerousRelease ();
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static bool Flush (IntPtr handle,
private extern static bool Flush (IntPtr handle,
out MonoIOError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static long GetLength (IntPtr handle,
out MonoIOError error);
public static bool Flush (SafeHandle safeHandle,
out MonoIOError error)
{
bool release = false;
try {
safeHandle.DangerousAddRef (ref release);
return Flush (safeHandle.DangerousGetHandle (), out error);
} finally {
if (release)
safeHandle.DangerousRelease ();
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static bool SetLength (IntPtr handle,
private extern static long GetLength (IntPtr handle,
out MonoIOError error);
public static long GetLength (SafeHandle safeHandle,
out MonoIOError error)
{
bool release = false;
try {
safeHandle.DangerousAddRef (ref release);
return GetLength (safeHandle.DangerousGetHandle (), out error);
} finally {
if (release)
safeHandle.DangerousRelease ();
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern static bool SetLength (IntPtr handle,
long length,
out MonoIOError error);
public static bool SetLength (SafeHandle safeHandle,
long length,
out MonoIOError error)
{
bool release = false;
try {
safeHandle.DangerousAddRef (ref release);
return SetLength (safeHandle.DangerousGetHandle (), length, out error);
} finally {
if (release)
safeHandle.DangerousRelease ();
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static bool SetFileTime (IntPtr handle,
private extern static bool SetFileTime (IntPtr handle,
long creation_time,
long last_access_time,
long last_write_time,
out MonoIOError error);
public static bool SetFileTime (SafeHandle safeHandle,
long creation_time,
long last_access_time,
long last_write_time,
out MonoIOError error)
{
bool release = false;
try {
safeHandle.DangerousAddRef (ref release);
return SetFileTime (safeHandle.DangerousGetHandle (), creation_time, last_access_time, last_write_time, out error);
} finally {
if (release)
safeHandle.DangerousRelease ();
}
}
public static bool SetFileTime (string path,
long creation_time,
long last_access_time,
@@ -393,7 +504,7 @@ namespace System.IO
break;
}
result = SetFileTime (handle, creation_time,
result = SetFileTime (new SafeFileHandle(handle, false), creation_time,
last_access_time,
last_write_time, out error);
@@ -404,15 +515,43 @@ namespace System.IO
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static void Lock (IntPtr handle,
private extern static void Lock (IntPtr handle,
long position, long length,
out MonoIOError error);
public static void Lock (SafeHandle safeHandle,
long position, long length,
out MonoIOError error)
{
bool release = false;
try {
safeHandle.DangerousAddRef (ref release);
Lock (safeHandle.DangerousGetHandle (), position, length, out error);
} finally {
if (release)
safeHandle.DangerousRelease ();
}
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static void Unlock (IntPtr handle,
private extern static void Unlock (IntPtr handle,
long position, long length,
out MonoIOError error);
public static void Unlock (SafeHandle safeHandle,
long position, long length,
out MonoIOError error)
{
bool release = false;
try {
safeHandle.DangerousAddRef (ref release);
Unlock (safeHandle.DangerousGetHandle (), position, length, out error);
} finally {
if (release)
safeHandle.DangerousRelease ();
}
}
// console handles
public extern static IntPtr ConsoleOutput {

View File

@@ -362,8 +362,8 @@ namespace System.IO {
var canonicalize = true;
if (path.Length >= 2 &&
IsDsc (path [0]) &&
IsDsc (path [1])) {
IsDirectorySeparator (path [0]) &&
IsDirectorySeparator (path [1])) {
if (path.Length == 2 || path.IndexOf (path [0], 2) < 0)
throw new ArgumentException ("UNC paths should be of the form \\\\server\\share.");
@@ -390,8 +390,8 @@ namespace System.IO {
path = cwd + DirectorySeparatorChar + path;
} else if (DirectorySeparatorChar == '\\' &&
path.Length >= 2 &&
IsDsc (path [0]) &&
!IsDsc (path [1])) { // like `\abc\def'
IsDirectorySeparator (path [0]) &&
!IsDirectorySeparator (path [1])) { // like `\abc\def'
string current = Directory.InsecureGetCurrentDirectory();
if (current [1] == VolumeSeparatorChar)
path = current.Substring (0, 2) + path;
@@ -404,16 +404,16 @@ namespace System.IO {
path = CanonicalizePath (path);
// if the original ended with a [Alt]DirectorySeparatorChar then ensure the full path also ends with one
if (IsDsc (end) && (path [path.Length - 1] != DirectorySeparatorChar))
if (IsDirectorySeparator (end) && (path [path.Length - 1] != DirectorySeparatorChar))
path += DirectorySeparatorChar;
return path;
}
static bool IsDsc (char c) {
internal static bool IsDirectorySeparator (char c) {
return c == DirectorySeparatorChar || c == AltDirectorySeparatorChar;
}
public static string GetPathRoot (string path)
{
if (path == null)
@@ -427,36 +427,36 @@ namespace System.IO {
if (DirectorySeparatorChar == '/') {
// UNIX
return IsDsc (path [0]) ? DirectorySeparatorStr : String.Empty;
return IsDirectorySeparator (path [0]) ? DirectorySeparatorStr : String.Empty;
} else {
// Windows
int len = 2;
if (path.Length == 1 && IsDsc (path [0]))
if (path.Length == 1 && IsDirectorySeparator (path [0]))
return DirectorySeparatorStr;
else if (path.Length < 2)
return String.Empty;
if (IsDsc (path [0]) && IsDsc (path[1])) {
if (IsDirectorySeparator (path [0]) && IsDirectorySeparator (path[1])) {
// UNC: \\server or \\server\share
// Get server
while (len < path.Length && !IsDsc (path [len])) len++;
while (len < path.Length && !IsDirectorySeparator (path [len])) len++;
// Get share
if (len < path.Length) {
len++;
while (len < path.Length && !IsDsc (path [len])) len++;
while (len < path.Length && !IsDirectorySeparator (path [len])) len++;
}
return DirectorySeparatorStr +
DirectorySeparatorStr +
path.Substring (2, len - 2).Replace (AltDirectorySeparatorChar, DirectorySeparatorChar);
} else if (IsDsc (path [0])) {
} else if (IsDirectorySeparator (path [0])) {
// path starts with '\' or '/'
return DirectorySeparatorStr;
} else if (path[1] == VolumeSeparatorChar) {
// C:\folder
if (path.Length >= 3 && (IsDsc (path [2]))) len++;
if (path.Length >= 3 && (IsDirectorySeparator (path [2]))) len++;
} else
return Directory.GetCurrentDirectory ().Substring (0, 2);// + path.Substring (0, len);
return path.Substring (0, len);
@@ -628,11 +628,11 @@ namespace System.IO {
static string GetServerAndShare (string path)
{
int len = 2;
while (len < path.Length && !IsDsc (path [len])) len++;
while (len < path.Length && !IsDirectorySeparator (path [len])) len++;
if (len < path.Length) {
len++;
while (len < path.Length && !IsDsc (path [len])) len++;
while (len < path.Length && !IsDirectorySeparator (path [len])) len++;
}
return path.Substring (2, len - 2).Replace (AltDirectorySeparatorChar, DirectorySeparatorChar);
@@ -646,8 +646,8 @@ namespace System.IO {
return false;
// UNC handling
if (IsDsc (root[0]) && IsDsc (root[1])) {
if (!(IsDsc (path[0]) && IsDsc (path[1])))
if (IsDirectorySeparator (root[0]) && IsDirectorySeparator (root[1])) {
if (!(IsDirectorySeparator (path[0]) && IsDirectorySeparator (path[1])))
return false;
string rootShare = GetServerAndShare (root);
@@ -664,7 +664,7 @@ namespace System.IO {
return false;
if ((root.Length > 2) && (path.Length > 2)) {
// but don't directory compare the directory separator
return (IsDsc (root[2]) && IsDsc (path[2]));
return (IsDirectorySeparator (root[2]) && IsDirectorySeparator (path[2]));
}
return true;
}
@@ -692,7 +692,7 @@ namespace System.IO {
int target = 0;
bool isUnc = Environment.IsRunningOnWindows &&
root.Length > 2 && IsDsc (root[0]) && IsDsc (root[1]);
root.Length > 2 && IsDirectorySeparator (root[0]) && IsDirectorySeparator (root[1]);
// Set an overwrite limit for UNC paths since '\' + server + share
// must not be eliminated by the '..' elimination algorithm.
@@ -728,7 +728,7 @@ namespace System.IO {
if (isUnc) {
return ret;
} else if (!IsDsc (path[0]) && SameRoot (root, path)) {
} else if (!IsDirectorySeparator (path[0]) && SameRoot (root, path)) {
if (ret.Length <= 2 && !ret.EndsWith (DirectorySeparatorStr)) // '\' after "c:"
ret += Path.DirectorySeparatorChar;
return ret;
@@ -736,10 +736,10 @@ namespace System.IO {
string current = Directory.GetCurrentDirectory ();
if (current.Length > 1 && current[1] == Path.VolumeSeparatorChar) {
// DOS local file path
if (ret.Length == 0 || IsDsc (ret[0]))
if (ret.Length == 0 || IsDirectorySeparator (ret[0]))
ret += '\\';
return current.Substring (0, 2) + ret;
} else if (IsDsc (current[current.Length - 1]) && IsDsc (ret[0]))
} else if (IsDirectorySeparator (current[current.Length - 1]) && IsDirectorySeparator (ret[0]))
return current + ret.Substring (1);
else
return current + ret;
@@ -776,11 +776,7 @@ namespace System.IO {
return String.Compare (subset, slast, path, slast, subset.Length - slast) == 0;
}
#if NET_4_0
public
#else
internal
#endif
static string Combine (params string [] paths)
{
if (paths == null)
@@ -821,11 +817,7 @@ namespace System.IO {
return ret.ToString ();
}
#if NET_4_0
public
#else
internal
#endif
static string Combine (string path1, string path2, string path3)
{
if (path1 == null)
@@ -840,11 +832,7 @@ namespace System.IO {
return Combine (new string [] { path1, path2, path3 });
}
#if NET_4_0
public
#else
internal
#endif
static string Combine (string path1, string path2, string path3, string path4)
{
if (path1 == null)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,190 +0,0 @@
//
// System.IO.StringReader
//
// Authors:
// Marcin Szczepanski (marcins@zipworld.com.au)
// 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.Globalization;
using System.Runtime.InteropServices;
#if NET_4_5
using System.Threading.Tasks;
#endif
namespace System.IO {
[Serializable]
[ComVisible (true)]
public class StringReader : TextReader {
string source;
int nextChar;
int sourceLength;
static char[] cr_lf;
public StringReader (string s)
{
if (s == null)
throw new ArgumentNullException ("s");
this.source = s;
nextChar = 0;
sourceLength = s.Length;
}
public override void Close ()
{
Dispose (true);
}
protected override void Dispose (bool disposing)
{
source = null;
base.Dispose (disposing);
}
public override int Peek ()
{
if (source == null)
ObjectDisposedException ();
if (nextChar >= sourceLength)
return -1;
return (int)source [nextChar];
}
public override int Read ()
{
if (source == null)
ObjectDisposedException ();
if (nextChar >= sourceLength)
return -1;
return (int)source [nextChar++];
}
// The method will read up to count characters from the StringReader
// into the buffer character array starting at position index. Returns
// the actual number of characters read, or zero if the end of the string
// has been reached and no characters are read.
public override int Read ([In, Out] char[] buffer, int index, int count)
{
if (source == null)
ObjectDisposedException ();
if (buffer == null)
throw new ArgumentNullException ("buffer");
if (buffer.Length - index < count)
throw new ArgumentException ();
if (index < 0 || count < 0)
throw new ArgumentOutOfRangeException ();
int charsToRead;
// reordered to avoir possible integer overflow
if (nextChar > sourceLength - count)
charsToRead = sourceLength - nextChar;
else
charsToRead = count;
source.CopyTo (nextChar, buffer, index, charsToRead);
nextChar += charsToRead;
return charsToRead;
}
public override string ReadLine ()
{
// Reads until next \r or \n or \r\n, otherwise return null
if (source == null)
ObjectDisposedException ();
if (nextChar >= source.Length)
return null;
if (cr_lf == null)
cr_lf = new char [] { '\n', '\r' };
int readto = source.IndexOfAny (cr_lf, nextChar);
if (readto == -1)
return ReadToEnd ();
bool consecutive = source[readto] == '\r'
&& readto + 1 < source.Length
&& source[readto + 1] == '\n';
string nextLine = source.Substring (nextChar, readto - nextChar);
nextChar = readto + ((consecutive) ? 2 : 1);
return nextLine;
}
public override string ReadToEnd ()
{
if (source == null)
ObjectDisposedException ();
string toEnd = source.Substring (nextChar, sourceLength - nextChar);
nextChar = sourceLength;
return toEnd;
}
#if NET_4_5
//
// All async methods return finished task with a result as it's faster
// than setting up async call
//
public override Task<int> ReadAsync (char[] buffer, int index, int count)
{
return Task.FromResult (Read (buffer, index, count));
}
public override Task<int> ReadBlockAsync (char[] buffer, int index, int count)
{
return Task.FromResult (ReadBlock (buffer, index, count));
}
public override Task<string> ReadLineAsync ()
{
return Task.FromResult (ReadLine ());
}
public override Task<string> ReadToEndAsync ()
{
return Task.FromResult (ReadToEnd ());
}
#endif
static void ObjectDisposedException ()
{
throw new ObjectDisposedException ("StringReader",
Locale.GetText ("Cannot read from a closed StringReader"));
}
}
}

View File

@@ -1,191 +0,0 @@
//
// System.IO.StringWriter
//
// Authors
// Marcin Szczepanski (marcins@zipworld.com.au)
// Sebastien Pouliot <sebastien@ximian.com>
// 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.Globalization;
using System.Text;
using System.Runtime.InteropServices;
#if NET_4_5
using System.Threading.Tasks;
#endif
namespace System.IO
{
[Serializable]
[ComVisible (true)]
[MonoLimitation ("Serialization format not compatible with .NET")]
public class StringWriter : TextWriter
{
private StringBuilder internalString;
private bool disposed;
public StringWriter ()
: this (new StringBuilder ())
{
}
public StringWriter (IFormatProvider formatProvider)
: this (new StringBuilder (), formatProvider)
{
}
public StringWriter (StringBuilder sb)
: this (sb, null)
{
}
public StringWriter (StringBuilder sb, IFormatProvider formatProvider)
{
if (sb == null)
throw new ArgumentNullException ("sb");
internalString = sb;
internalFormatProvider = formatProvider;
}
public override Encoding Encoding {
get {
return Encoding.Unicode;
}
}
public override void Close ()
{
Dispose (true);
disposed = true;
}
protected override void Dispose (bool disposing)
{
// MS.NET doesn't clear internal buffer.
// internalString = null;
base.Dispose (disposing);
disposed = true;
}
public virtual StringBuilder GetStringBuilder ()
{
return internalString;
}
public override string ToString ()
{
return internalString.ToString ();
}
public override void Write (char value)
{
if (disposed) {
throw new ObjectDisposedException ("StringReader",
Locale.GetText ("Cannot write to a closed StringWriter"));
}
internalString.Append (value);
}
public override void Write (string value)
{
if (disposed) {
throw new ObjectDisposedException ("StringReader",
Locale.GetText ("Cannot write to a closed StringWriter"));
}
internalString.Append (value);
}
public override void Write (char[] buffer, int index, int count)
{
if (disposed) {
throw new ObjectDisposedException ("StringReader",
Locale.GetText ("Cannot write to a closed StringWriter"));
}
if (buffer == null)
throw new ArgumentNullException ("buffer");
if (index < 0)
throw new ArgumentOutOfRangeException ("index", "< 0");
if (count < 0)
throw new ArgumentOutOfRangeException ("count", "< 0");
// re-ordered to avoid possible integer overflow
if (index > buffer.Length - count)
throw new ArgumentException ("index + count > buffer.Length");
internalString.Append (buffer, index, count);
}
#if NET_4_5
public override Task FlushAsync ()
{
// it appears to do nothing
return TaskConstants.Finished;
}
//
// All async methods return finished task with a result as it's faster
// than setting up async call
//
public override Task WriteAsync (char value)
{
Write (value);
return TaskConstants.Finished;
}
public override Task WriteAsync (char[] buffer, int index, int count)
{
Write (buffer, index, count);
return TaskConstants.Finished;
}
public override Task WriteAsync (string value)
{
Write (value);
return TaskConstants.Finished;
}
public override Task WriteLineAsync (char value)
{
WriteLine (value);
return TaskConstants.Finished;
}
public override Task WriteLineAsync (char[] buffer, int index, int count)
{
WriteLine (buffer, index, count);
return TaskConstants.Finished;
}
public override Task WriteLineAsync (string value)
{
WriteLine (value);
return TaskConstants.Finished;
}
#endif
}
}

View File

@@ -1,291 +0,0 @@
//
// System.IO.TextReader
//
// Authors:
// Marcin Szczepanski (marcins@zipworld.com.au)
// Miguel de Icaza (miguel@gnome.org)
// 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.Runtime.InteropServices;
#if NET_4_5
using System.Threading.Tasks;
#endif
namespace System.IO {
[Serializable]
[ComVisible (true)]
#if NET_2_1
public abstract class TextReader : IDisposable {
#else
public abstract class TextReader : MarshalByRefObject, IDisposable {
#endif
sealed class NullTextReader : TextReader
{
public override string ReadLine ()
{
return null;
}
public override string ReadToEnd ()
{
return String.Empty;
}
}
public static readonly TextReader Null = new NullTextReader ();
protected TextReader()
{
}
public virtual void Close()
{
Dispose(true);
}
public void Dispose ()
{
Dispose(true);
}
protected virtual void Dispose (bool disposing)
{
if (disposing){
// If we are explicitly disposed, we can avoid finalization.
GC.SuppressFinalize (this);
}
return;
}
public virtual int Peek()
{
return -1;
}
public virtual int Read()
{
return -1;
}
public virtual int Read ([In, Out] char[] buffer, int index, int count)
{
int c, i;
for (i = 0; i < count; i++) {
if ((c = Read ()) == -1)
return i;
buffer [index + i] = (char)c;
}
return i;
}
public virtual int ReadBlock ([In, Out] char [] buffer, int index, int count)
{
int total_read_count = 0;
int current_read_count;
do {
current_read_count = Read (buffer, index, count);
index += current_read_count;
total_read_count += current_read_count;
count -= current_read_count;
} while (current_read_count != 0 && count > 0);
return total_read_count;
}
public virtual string ReadLine ()
{
var result = new System.Text.StringBuilder ();
int c;
while ((c = Read ()) != -1){
// check simple character line ending
if (c == '\n')
break;
if (c == '\r') {
if (Peek () == '\n')
Read ();
break;
}
result.Append ((char) c);
}
if (c == -1 && result.Length == 0)
return null;
return result.ToString ();
}
public virtual string ReadToEnd ()
{
var result = new System.Text.StringBuilder ();
int c;
while ((c = Read ()) != -1)
result.Append ((char) c);
return result.ToString ();
}
public static TextReader Synchronized (TextReader reader)
{
if (reader == null)
throw new ArgumentNullException ("reader is null");
if (reader is SynchronizedReader)
return reader;
return new SynchronizedReader (reader);
}
#if NET_4_5
//
// Use tuple to pack the arguments because it's faster than
// setting up anonymous method container with an instance delegate
//
public virtual Task<int> ReadAsync (char[] buffer, int index, int count)
{
return Task.Factory.StartNew (l => {
var t = (Tuple<TextReader, char[], int, int>) l;
return t.Item1.Read (t.Item2, t.Item3, t.Item4);
}, Tuple.Create (this, buffer, index, count));
}
public virtual Task<int> ReadBlockAsync (char[] buffer, int index, int count)
{
return Task.Factory.StartNew (l => {
var t = (Tuple<TextReader, char[], int, int>) l;
return t.Item1.ReadBlock (t.Item2, t.Item3, t.Item4);
}, Tuple.Create (this, buffer, index, count));
}
public virtual Task<string> ReadLineAsync ()
{
return Task.Factory.StartNew (l => ((TextReader) l).ReadLine (), this);
}
public virtual Task<string> ReadToEndAsync ()
{
return Task.Factory.StartNew (l => ((TextReader) l).ReadToEnd (), this);
}
#endif
}
//
// Synchronized Reader implementation, used internally.
//
[Serializable]
sealed class SynchronizedReader : TextReader
{
readonly TextReader reader;
public SynchronizedReader (TextReader reader)
{
this.reader = reader;
}
public override void Close ()
{
lock (this){
reader.Close ();
}
}
public override int Peek ()
{
lock (this){
return reader.Peek ();
}
}
public override int ReadBlock (char [] buffer, int index, int count)
{
lock (this){
return reader.ReadBlock (buffer, index, count);
}
}
public override string ReadLine ()
{
lock (this){
return reader.ReadLine ();
}
}
public override string ReadToEnd ()
{
lock (this){
return reader.ReadToEnd ();
}
}
public override int Read ()
{
lock (this){
return reader.Read ();
}
}
public override int Read (char [] buffer, int index, int count)
{
lock (this){
return reader.Read (buffer, index, count);
}
}
#if NET_4_5
public override Task<int> ReadAsync (char[] buffer, int index, int count)
{
lock (this) {
return reader.ReadAsync (buffer, index, count);
}
}
public override Task<int> ReadBlockAsync (char[] buffer, int index, int count)
{
lock (this) {
return reader.ReadBlockAsync (buffer, index, count);
}
}
public override Task<string> ReadLineAsync ()
{
lock (this) {
return reader.ReadLineAsync ();
}
}
public override Task<string> ReadToEndAsync ()
{
lock (this) {
return reader.ReadToEndAsync ();
}
}
#endif
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -52,7 +52,7 @@ namespace System.IO {
*/
public UnexceptionalStreamWriter (Stream stream,
Encoding encoding)
: base (stream, encoding)
: base (stream, encoding, DefaultBufferSize, true)
{
}
/*

Some files were not shown because too many files have changed in this diff Show More