summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/IO/UnmanagedMemoryStreamWrapper.cs
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2017-04-13 14:17:19 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2017-04-13 14:17:19 +0900
commita56e30c8d33048216567753d9d3fefc2152af8ac (patch)
tree7e5d979695fc4a431740982eb1cfecc2898b23a5 /src/mscorlib/src/System/IO/UnmanagedMemoryStreamWrapper.cs
parent4b11dc566a5bbfa1378d6266525c281b028abcc8 (diff)
downloadcoreclr-a56e30c8d33048216567753d9d3fefc2152af8ac.tar.gz
coreclr-a56e30c8d33048216567753d9d3fefc2152af8ac.tar.bz2
coreclr-a56e30c8d33048216567753d9d3fefc2152af8ac.zip
Imported Upstream version 2.0.0.11353upstream/2.0.0.11353
Diffstat (limited to 'src/mscorlib/src/System/IO/UnmanagedMemoryStreamWrapper.cs')
-rw-r--r--src/mscorlib/src/System/IO/UnmanagedMemoryStreamWrapper.cs153
1 files changed, 89 insertions, 64 deletions
diff --git a/src/mscorlib/src/System/IO/UnmanagedMemoryStreamWrapper.cs b/src/mscorlib/src/System/IO/UnmanagedMemoryStreamWrapper.cs
index 99b257ea56..86e4707dfd 100644
--- a/src/mscorlib/src/System/IO/UnmanagedMemoryStreamWrapper.cs
+++ b/src/mscorlib/src/System/IO/UnmanagedMemoryStreamWrapper.cs
@@ -18,94 +18,117 @@ using System.Diagnostics.Contracts;
using System.Threading;
using System.Threading.Tasks;
-namespace System.IO {
+namespace System.IO
+{
// Needed for backwards compatibility with V1.x usages of the
// ResourceManager, where a MemoryStream is now returned as an
// UnmanagedMemoryStream from ResourceReader.
- internal sealed class UnmanagedMemoryStreamWrapper : MemoryStream {
+ internal sealed class UnmanagedMemoryStreamWrapper : MemoryStream
+ {
private UnmanagedMemoryStream _unmanagedStream;
-
- internal UnmanagedMemoryStreamWrapper(UnmanagedMemoryStream stream) {
+
+ internal UnmanagedMemoryStreamWrapper(UnmanagedMemoryStream stream)
+ {
_unmanagedStream = stream;
}
-
- public override bool CanRead {
+
+ public override bool CanRead
+ {
[Pure]
get { return _unmanagedStream.CanRead; }
}
-
- public override bool CanSeek {
+
+ public override bool CanSeek
+ {
[Pure]
get { return _unmanagedStream.CanSeek; }
}
-
- public override bool CanWrite {
+
+ public override bool CanWrite
+ {
[Pure]
get { return _unmanagedStream.CanWrite; }
}
-
+
protected override void Dispose(bool disposing)
{
- try {
+ try
+ {
if (disposing)
_unmanagedStream.Close();
}
- finally {
+ finally
+ {
base.Dispose(disposing);
}
}
-
- public override void Flush() {
+
+ public override void Flush()
+ {
_unmanagedStream.Flush();
}
-
- public override byte[] GetBuffer() {
- throw new UnauthorizedAccessException(Environment.GetResourceString("UnauthorizedAccess_MemStreamBuffer"));
+
+ public override byte[] GetBuffer()
+ {
+ throw new UnauthorizedAccessException(SR.UnauthorizedAccess_MemStreamBuffer);
}
- public override bool TryGetBuffer(out ArraySegment<byte> buffer) {
+ public override bool TryGetBuffer(out ArraySegment<byte> buffer)
+ {
buffer = default(ArraySegment<byte>);
return false;
}
- public override int Capacity {
- get {
- return (int) _unmanagedStream.Capacity;
+ public override int Capacity
+ {
+ get
+ {
+ return (int)_unmanagedStream.Capacity;
}
[SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
- set {
- throw new IOException(Environment.GetResourceString("IO.IO_FixedCapacity"));
+ set
+ {
+ throw new IOException(SR.IO_FixedCapacity);
}
- }
-
- public override long Length {
- get {
+ }
+
+ public override long Length
+ {
+ get
+ {
return _unmanagedStream.Length;
}
}
- public override long Position {
- get {
+ public override long Position
+ {
+ get
+ {
return _unmanagedStream.Position;
}
- set {
+ set
+ {
_unmanagedStream.Position = value;
}
}
-
- public override int Read([In, Out] byte[] buffer, int offset, int count) {
+
+ public override int Read([In, Out] byte[] buffer, int offset, int count)
+ {
return _unmanagedStream.Read(buffer, offset, count);
}
-
- public override int ReadByte() {
+
+ public override int ReadByte()
+ {
return _unmanagedStream.ReadByte();
}
-
- public override long Seek(long offset, SeekOrigin loc) {
+
+ public override long Seek(long offset, SeekOrigin loc)
+ {
return _unmanagedStream.Seek(offset, loc);
}
- public unsafe override byte[] ToArray() {
+ public unsafe override byte[] ToArray()
+ {
if (!_unmanagedStream._isOpen) __Error.StreamIsClosed();
if (!_unmanagedStream.CanRead) __Error.ReadNotSupported();
@@ -113,31 +136,34 @@ namespace System.IO {
Buffer.Memcpy(buffer, 0, _unmanagedStream.Pointer, 0, (int)_unmanagedStream.Length);
return buffer;
}
-
- public override void Write(byte[] buffer, int offset, int count) {
+
+ public override void Write(byte[] buffer, int offset, int count)
+ {
_unmanagedStream.Write(buffer, offset, count);
}
-
- public override void WriteByte(byte value) {
+
+ public override void WriteByte(byte value)
+ {
_unmanagedStream.WriteByte(value);
}
-
+
// Writes this MemoryStream to another stream.
- public unsafe override void WriteTo(Stream stream) {
- if (stream==null)
- throw new ArgumentNullException(nameof(stream), Environment.GetResourceString("ArgumentNull_Stream"));
+ public unsafe override void WriteTo(Stream stream)
+ {
+ if (stream == null)
+ throw new ArgumentNullException(nameof(stream), SR.ArgumentNull_Stream);
Contract.EndContractBlock();
if (!_unmanagedStream._isOpen) __Error.StreamIsClosed();
if (!CanRead) __Error.ReadNotSupported();
byte[] buffer = ToArray();
-
+
stream.Write(buffer, 0, buffer.Length);
}
- public override void SetLength(Int64 value) {
-
+ public override void SetLength(Int64 value)
+ {
// This was probably meant to call _unmanagedStream.SetLength(value), but it was forgotten in V.4.0.
// Now this results in a call to the base which touches the underlying array which is never actually used.
// We cannot fix it due to compat now, but we should fix this at the next SxS release oportunity.
@@ -145,26 +171,26 @@ namespace System.IO {
}
- public override Task CopyToAsync(Stream destination, Int32 bufferSize, CancellationToken cancellationToken) {
-
+ public override Task CopyToAsync(Stream destination, Int32 bufferSize, CancellationToken cancellationToken)
+ {
// The parameter checks must be in sync with the base version:
if (destination == null)
throw new ArgumentNullException(nameof(destination));
-
+
if (bufferSize <= 0)
- throw new ArgumentOutOfRangeException(nameof(bufferSize), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
+ throw new ArgumentOutOfRangeException(nameof(bufferSize), SR.ArgumentOutOfRange_NeedPosNum);
if (!CanRead && !CanWrite)
- throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_StreamClosed"));
+ throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
if (!destination.CanRead && !destination.CanWrite)
- throw new ObjectDisposedException(nameof(destination), Environment.GetResourceString("ObjectDisposed_StreamClosed"));
+ throw new ObjectDisposedException(nameof(destination), SR.ObjectDisposed_StreamClosed);
if (!CanRead)
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnreadableStream"));
+ throw new NotSupportedException(SR.NotSupported_UnreadableStream);
if (!destination.CanWrite)
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnwritableStream"));
+ throw new NotSupportedException(SR.NotSupported_UnwritableStream);
Contract.EndContractBlock();
@@ -172,23 +198,22 @@ namespace System.IO {
}
- public override Task FlushAsync(CancellationToken cancellationToken) {
-
+ public override Task FlushAsync(CancellationToken cancellationToken)
+ {
return _unmanagedStream.FlushAsync(cancellationToken);
}
- public override Task<Int32> ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken) {
-
+ public override Task<Int32> ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
+ {
return _unmanagedStream.ReadAsync(buffer, offset, count, cancellationToken);
}
- public override Task WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken) {
-
+ public override Task WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
+ {
return _unmanagedStream.WriteAsync(buffer, offset, count, cancellationToken);
}
-
} // class UnmanagedMemoryStreamWrapper
} // namespace