**** Merged from MCS ****
[mono-project.git] / mcs / class / corlib / System.IO.IsolatedStorage / IsolatedStorageFileStream.cs
blob7f98cc8f1f759c8c0c7706757c4122c4ca8b8db7
1 // System.IO.IsolatedStorage.IsolatedStorageFileStream
2 //
3 // Sean MacIsaac (macisaac@ximian.com)
4 //
5 // (C) 2001 Ximian, Inc.
6 // (C) 2004 Novell (http://www.novell.com)
8 //
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System;
32 using System.Globalization;
33 using System.IO;
34 using System.Reflection;
36 namespace System.IO.IsolatedStorage {
38 public class IsolatedStorageFileStream : FileStream
40 private static string CreateIsolatedPath (string path)
42 string dir = IsolatedStorageInfo.CreateAssemblyFilename (Assembly.GetEntryAssembly());
44 string file = Path.Combine (dir, path);
46 // Ensure that the file can be created.
47 FileInfo fi = new FileInfo (file);
48 if (!fi.Directory.Exists)
49 fi.Directory.Create ();
51 return file;
54 public IsolatedStorageFileStream (string path, FileMode mode)
55 : base(CreateIsolatedPath (path), mode)
59 public IsolatedStorageFileStream (string path, FileMode mode, FileAccess access)
60 : base (CreateIsolatedPath (path), mode, access)
64 public IsolatedStorageFileStream (string path, FileMode mode, FileAccess access, FileShare share)
65 : base (CreateIsolatedPath (path), mode, access, share)
69 public IsolatedStorageFileStream (string path, FileMode mode, FileAccess access, FileShare share, int bufferSize)
70 : base (CreateIsolatedPath (path), mode, access, share, bufferSize)
74 public IsolatedStorageFileStream (string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, IsolatedStorageFile isf)
75 : base (CreateIsolatedPath (path), mode, access, share, bufferSize)
79 public IsolatedStorageFileStream (string path, FileMode mode, FileAccess access, FileShare share, IsolatedStorageFile isf)
80 : base (CreateIsolatedPath (path), mode, access, share)
84 public IsolatedStorageFileStream (string path, FileMode mode, FileAccess access, IsolatedStorageFile isf)
85 : base (CreateIsolatedPath (path), mode, access)
89 public IsolatedStorageFileStream (string path, FileMode mode, IsolatedStorageFile isf)
90 : base (CreateIsolatedPath (path), mode)
94 public override bool CanRead {
95 get {return base.CanRead;}
98 public override bool CanSeek {
99 get {return base.CanSeek;}
102 public override bool CanWrite {
103 get {return base.CanWrite;}
106 public override IntPtr Handle {
107 get {
108 throw new IsolatedStorageException (
109 Locale.GetText ("Information is restricted"));
113 public override bool IsAsync {
114 get {return base.IsAsync;}
117 public override long Length {
118 get {return base.Length;}
121 public override long Position {
122 get {return base.Position;}
123 set {base.Position = value;}
126 public override IAsyncResult BeginRead (byte[] buffer, int offset, int numBytes, AsyncCallback userCallback, object stateObject)
128 return base.BeginRead (buffer, offset, numBytes, userCallback, stateObject);
131 public override IAsyncResult BeginWrite (byte[] buffer, int offset, int numBytes, AsyncCallback userCallback, object stateObject)
133 return base.BeginWrite (buffer, offset, numBytes, userCallback, stateObject);
136 public override void Close ()
138 base.Close ();
141 public override int EndRead (IAsyncResult asyncResult)
143 return base.EndRead (asyncResult);
146 public override void EndWrite (IAsyncResult asyncResult)
148 base.EndWrite (asyncResult);
151 public override void Flush ()
153 base.Flush ();
156 public override int Read (byte[] buffer, int offset, int count)
158 return base.Read (buffer, offset, count);
161 public override int ReadByte ()
163 return base.ReadByte ();
166 public override long Seek (long offset, SeekOrigin origin)
168 return base.Seek (offset, origin);
171 public override void SetLength (long value)
173 base.SetLength (value);
176 public override void Write (byte[] buffer, int offset, int count)
178 base.Write (buffer, offset, count);
181 public override void WriteByte (byte value)
183 base.WriteByte (value);
186 protected override void Dispose (bool disposing)
188 base.Dispose (disposing);