FileStreamTest.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. // FileStreamTests.cs - NUnit2 Test Cases for System.IO.FileStream class
  2. //
  3. // Authors:
  4. // Ville Palo ([email protected])
  5. // Gert Driesen ([email protected])
  6. // Gonzalo Paniagua Javier ([email protected])
  7. //
  8. // (C) Ville Palo
  9. // (c) 2003 Ximian, Inc. (http://www.ximian.com)
  10. //
  11. using NUnit.Framework;
  12. using System;
  13. using System.IO;
  14. using System.Text;
  15. namespace MonoTests.System.IO
  16. {
  17. [TestFixture]
  18. public class FileStreamTest : Assertion
  19. {
  20. string TempFolder = Path.Combine (Path.GetTempPath (), "MonoTests.System.IO.Tests");
  21. [TearDown]
  22. public void TearDown()
  23. {
  24. if (Directory.Exists (TempFolder))
  25. Directory.Delete (TempFolder, true);
  26. }
  27. [SetUp]
  28. public void SetUp ()
  29. {
  30. if (Directory.Exists (TempFolder))
  31. Directory.Delete (TempFolder, true);
  32. Directory.CreateDirectory (TempFolder);
  33. }
  34. public void TestCtr ()
  35. {
  36. string path = TempFolder + "/testfilestream.tmp.1";
  37. DeleteFile (path);
  38. FileStream stream = null;
  39. try {
  40. stream = new FileStream (path, FileMode.Create);
  41. } finally {
  42. if (stream != null)
  43. stream.Close ();
  44. DeleteFile (path);
  45. }
  46. }
  47. [Test]
  48. [ExpectedException (typeof (ArgumentException))]
  49. public void CtorArgumentException1 ()
  50. {
  51. FileStream stream;
  52. stream = new FileStream ("", FileMode.Create);
  53. stream.Close ();
  54. }
  55. [Test]
  56. [ExpectedException (typeof (ArgumentNullException))]
  57. public void CtorArgumentNullException ()
  58. {
  59. FileStream stream = new FileStream (null, FileMode.Create);
  60. stream.Close ();
  61. }
  62. [Test]
  63. [ExpectedException (typeof (FileNotFoundException))]
  64. public void CtorFileNotFoundException1 ()
  65. {
  66. string path = TempFolder + "/thisfileshouldnotexists.test";
  67. DeleteFile (path);
  68. FileStream stream = null;
  69. try {
  70. stream = new FileStream (TempFolder + "/thisfileshouldnotexists.test", FileMode.Open);
  71. } finally {
  72. if (stream != null)
  73. stream.Close ();
  74. DeleteFile (path);
  75. }
  76. }
  77. [Test]
  78. [ExpectedException (typeof (FileNotFoundException))]
  79. public void CtorFileNotFoundException2 ()
  80. {
  81. string path = TempFolder + "/thisfileshouldNOTexists.test";
  82. DeleteFile (path);
  83. FileStream stream = null;
  84. try {
  85. stream = new FileStream (TempFolder + "/thisfileshouldNOTexists.test", FileMode.Truncate);
  86. } finally {
  87. if (stream != null)
  88. stream.Close ();
  89. DeleteFile (path);
  90. }
  91. }
  92. [Test]
  93. [ExpectedException (typeof (IOException))]
  94. public void CtorIOException1 ()
  95. {
  96. string path = TempFolder + "/thisfileshouldexists.test";
  97. FileStream stream = null;
  98. DeleteFile (path);
  99. try {
  100. stream = new FileStream (path, FileMode.CreateNew);
  101. stream.Close ();
  102. stream = null;
  103. stream = new FileStream (path, FileMode.CreateNew);
  104. } finally {
  105. if (stream != null)
  106. stream.Close ();
  107. DeleteFile (path);
  108. }
  109. }
  110. [Test]
  111. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  112. public void CtorArgumentOutOfRangeException1 ()
  113. {
  114. FileStream stream = null;
  115. string path = TempFolder + Path.DirectorySeparatorChar + "temp";
  116. DeleteFile (path);
  117. try {
  118. stream = new FileStream (path, FileMode.Append | FileMode.CreateNew);
  119. } finally {
  120. if (stream != null)
  121. stream.Close ();
  122. DeleteFile (path);
  123. }
  124. }
  125. [Test]
  126. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  127. public void CtorArgumentOutOfRangeException2 ()
  128. {
  129. FileStream stream = null;
  130. string path = TempFolder + Path.DirectorySeparatorChar + "temp";
  131. DeleteFile (path);
  132. try {
  133. stream = new FileStream ("test.test.test", FileMode.Append | FileMode.Open);
  134. } finally {
  135. if (stream != null)
  136. stream.Close ();
  137. DeleteFile (path);
  138. }
  139. }
  140. [Test]
  141. [ExpectedException (typeof (DirectoryNotFoundException))]
  142. public void CtorDirectoryNotFoundException ()
  143. {
  144. string path = TempFolder + "/thisDicrectoryShouldNotExists";
  145. if (Directory.Exists (path))
  146. Directory.Delete (path, true);
  147. FileStream stream = null;
  148. try {
  149. stream = new FileStream (path + "/eitherthisfile.test", FileMode.CreateNew);
  150. } finally {
  151. if (stream != null)
  152. stream.Close ();
  153. if (Directory.Exists (path))
  154. Directory.Delete (path, true);
  155. }
  156. }
  157. [Test]
  158. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  159. public void CtorArgumentOutOfRangeException3 ()
  160. {
  161. string path = TempFolder + "/CtorArgumentOutOfRangeException1";
  162. DeleteFile (path);
  163. FileStream stream = null;
  164. try {
  165. stream = new FileStream (path, FileMode.CreateNew, FileAccess.Read, FileShare.None | FileShare.Inheritable);
  166. } finally {
  167. if (stream != null)
  168. stream.Close ();
  169. DeleteFile (path);
  170. }
  171. }
  172. [Test]
  173. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  174. public void CtorArgumentOutOfRangeException4 ()
  175. {
  176. string path = TempFolder + "/CtorArgumentOutOfRangeException2";
  177. DeleteFile (path);
  178. FileStream stream = null;
  179. try {
  180. stream = new FileStream (path, FileMode.Truncate, FileAccess.Read, FileShare.ReadWrite, -1);
  181. } finally {
  182. if (stream != null)
  183. stream.Close ();
  184. DeleteFile (path);
  185. }
  186. }
  187. [Test]
  188. [ExpectedException (typeof (ArgumentException))]
  189. public void CtorArgumentException2 ()
  190. {
  191. // FileMode.CreateNew && FileAccess.Read
  192. string path = TempFolder + Path.DirectorySeparatorChar + "temp";
  193. FileStream stream = null;
  194. DeleteFile (path);
  195. try {
  196. stream = new FileStream (".test.test.test.2", FileMode.CreateNew, FileAccess.Read, FileShare.None | FileShare.Write);
  197. } finally {
  198. if (stream != null)
  199. stream.Close ();
  200. DeleteFile (path);
  201. }
  202. }
  203. [Test]
  204. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  205. public void CtorArgumentOutOfRangeException5 ()
  206. {
  207. string path = TempFolder + Path.DirectorySeparatorChar + "temp";
  208. DeleteFile (path);
  209. FileStream stream = null;
  210. try {
  211. stream = new FileStream (path, FileMode.CreateNew, FileAccess.Read, FileShare.Inheritable | FileShare.ReadWrite);
  212. } finally {
  213. if (stream != null)
  214. stream.Close ();
  215. DeleteFile (path);
  216. }
  217. }
  218. [Test]
  219. [ExpectedException (typeof (ArgumentException))]
  220. public void CtorArgumentException3 ()
  221. {
  222. string path = TempFolder + Path.DirectorySeparatorChar + "temp";
  223. FileStream stream = null;
  224. DeleteFile (path);
  225. try {
  226. stream = new FileStream (".test.test.test.2", FileMode.Truncate, FileAccess.Read);
  227. } finally {
  228. if (stream != null)
  229. stream.Close ();
  230. DeleteFile (path);
  231. }
  232. }
  233. [Test]
  234. [ExpectedException (typeof (IOException))]
  235. public void CtorIOException2 ()
  236. {
  237. FileStream stream = null;
  238. try {
  239. stream = new FileStream (new IntPtr (12), FileAccess.Read);
  240. } finally {
  241. if (stream != null)
  242. stream.Close ();
  243. }
  244. }
  245. [Test]
  246. [ExpectedException(typeof(IOException))]
  247. public void CtorIOException ()
  248. {
  249. string path = TempFolder + "/CTorIOException.Test";
  250. FileStream stream = null;
  251. FileStream stream2 = null;
  252. DeleteFile (path);
  253. try {
  254. stream = new FileStream (path, FileMode.CreateNew);
  255. // used by an another process
  256. stream2 = new FileStream (path, FileMode.OpenOrCreate);
  257. } finally {
  258. if (stream != null)
  259. stream.Close ();
  260. if (stream2 != null)
  261. stream2.Close ();
  262. DeleteFile (path);
  263. }
  264. }
  265. [Test]
  266. public void Flush ()
  267. {
  268. string path = TempFolder + "/FileStreamTest.Flush";
  269. FileStream stream = null;
  270. FileStream stream2 = null;
  271. DeleteFile (path);
  272. try {
  273. stream = new FileStream (path, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite);
  274. stream2 = new FileStream (path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
  275. stream.Write (new byte [] {1, 2, 3, 4, 5}, 0, 5);
  276. byte [] bytes = new byte [5];
  277. stream2.Read (bytes, 0, 5);
  278. AssertEquals ("test#01", 0, bytes [0]);
  279. AssertEquals ("test#02", 0, bytes [1]);
  280. AssertEquals ("test#03", 0, bytes [2]);
  281. AssertEquals ("test#04", 0, bytes [3]);
  282. stream.Flush ();
  283. stream2.Read (bytes, 0, 5);
  284. AssertEquals ("test#05", 1, bytes [0]);
  285. AssertEquals ("test#06", 2, bytes [1]);
  286. AssertEquals ("test#07", 3, bytes [2]);
  287. AssertEquals ("test#08", 4, bytes [3]);
  288. } finally {
  289. if (stream != null)
  290. stream.Close ();
  291. if (stream2 != null)
  292. stream2.Close ();
  293. DeleteFile (path);
  294. }
  295. }
  296. public void TestDefaultProperties ()
  297. {
  298. string path = TempFolder + Path.DirectorySeparatorChar + "testfilestream.tmp.2";
  299. DeleteFile (path);
  300. FileStream stream = new FileStream (path, FileMode.Create);
  301. AssertEquals ("test#01", true, stream.CanRead);
  302. AssertEquals ("test#02", true, stream.CanSeek);
  303. AssertEquals ("test#03", true, stream.CanWrite);
  304. AssertEquals ("test#04", false, stream.IsAsync);
  305. AssertEquals ("test#05", true, stream.Name.EndsWith (path));
  306. AssertEquals ("test#06", 0, stream.Position);
  307. AssertEquals ("test#07", "System.IO.FileStream", stream.ToString());
  308. stream.Close ();
  309. DeleteFile (path);
  310. stream = new FileStream (path, FileMode.OpenOrCreate, FileAccess.Read);
  311. AssertEquals ("test#08", true, stream.CanRead);
  312. AssertEquals ("test#09", true, stream.CanSeek);
  313. AssertEquals ("test#10", false, stream.CanWrite);
  314. AssertEquals ("test#11", false, stream.IsAsync);
  315. AssertEquals ("test#12", true, stream.Name.EndsWith (path));
  316. AssertEquals ("test#13", 0, stream.Position);
  317. AssertEquals ("test#14", "System.IO.FileStream", stream.ToString());
  318. stream.Close ();
  319. stream = new FileStream (path, FileMode.Truncate, FileAccess.Write, FileShare.ReadWrite);
  320. AssertEquals ("test#15", false, stream.CanRead);
  321. AssertEquals ("test#16", true, stream.CanSeek);
  322. AssertEquals ("test#17", true, stream.CanWrite);
  323. AssertEquals ("test#18", false, stream.IsAsync);
  324. AssertEquals ("test#19", true, stream.Name.EndsWith ("testfilestream.tmp.2"));
  325. AssertEquals ("test#20", 0, stream.Position);
  326. AssertEquals ("test#21", "System.IO.FileStream", stream.ToString());
  327. stream.Close ();
  328. DeleteFile (path);
  329. }
  330. public void TestLock()
  331. {
  332. string path = TempFolder + Path.DirectorySeparatorChar + "TestLock";
  333. DeleteFile (path);
  334. FileStream stream = new FileStream (path, FileMode.CreateNew, FileAccess.ReadWrite);
  335. stream.Write (new Byte [] {0,1,2,3,4,5,6,7,8,9,10}, 0, 10);
  336. stream.Close ();
  337. stream = new FileStream (path, FileMode.Open, FileAccess.ReadWrite);
  338. stream.Lock (0, 5);
  339. FileStream stream2 = new FileStream (path , FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
  340. byte [] bytes = new byte [5];
  341. try {
  342. stream2.Read (bytes, 0, 5);
  343. Fail ();
  344. } catch (Exception e) {
  345. // locked
  346. AssertEquals ("test#01", typeof (IOException), e.GetType ());
  347. }
  348. stream2.Seek (5, SeekOrigin.Begin);
  349. stream2.Read (bytes, 0, 5);
  350. AssertEquals ("test#02", 5, bytes [0]);
  351. AssertEquals ("test#03", 6, bytes [1]);
  352. AssertEquals ("test#04", 7, bytes [2]);
  353. AssertEquals ("test#05", 8, bytes [3]);
  354. AssertEquals ("test#06", 9, bytes [4]);
  355. stream.Unlock (0,5);
  356. stream2.Seek (0, SeekOrigin.Begin);
  357. stream2.Read (bytes, 0, 5);
  358. AssertEquals ("test#02", 0, bytes [0]);
  359. AssertEquals ("test#03", 1, bytes [1]);
  360. AssertEquals ("test#04", 2, bytes [2]);
  361. AssertEquals ("test#05", 3, bytes [3]);
  362. AssertEquals ("test#06", 4, bytes [4]);
  363. stream.Close ();
  364. stream2.Close ();
  365. DeleteFile (path);
  366. }
  367. [Test]
  368. public void Seek ()
  369. {
  370. string path = TempFolder + "/FST.Seek.Test";
  371. DeleteFile (path);
  372. FileStream stream = new FileStream (path, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite);
  373. FileStream stream2 = new FileStream (path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
  374. stream.Write (new byte [] {1, 2, 3, 4, 5, 6, 7, 8, 10}, 0, 9);
  375. AssertEquals ("test#01", 5, stream2.Seek (5, SeekOrigin.Begin));
  376. AssertEquals ("test#02", -1, stream2.ReadByte ());
  377. AssertEquals ("test#03", 2, stream2.Seek (-3, SeekOrigin.Current));
  378. AssertEquals ("test#04", -1, stream2.ReadByte ());
  379. AssertEquals ("test#05", 12, stream.Seek (3, SeekOrigin.Current));
  380. AssertEquals ("test#06", -1, stream.ReadByte ());
  381. AssertEquals ("test#07", 5, stream.Seek (-7, SeekOrigin.Current));
  382. AssertEquals ("test#08", 6, stream.ReadByte ());
  383. AssertEquals ("test#09", 5, stream2.Seek (5, SeekOrigin.Begin));
  384. AssertEquals ("test#10", 6, stream2.ReadByte ());
  385. stream.Close ();
  386. stream2.Close ();
  387. DeleteFile (path);
  388. }
  389. public void TestSeek ()
  390. {
  391. string path = TempFolder + Path.DirectorySeparatorChar + "TestSeek";
  392. DeleteFile (path);
  393. FileStream stream = new FileStream (path, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite);
  394. stream.Write (new byte[] {1, 2, 3, 4, 5, 6, 7, 8 , 9, 10}, 0, 10);
  395. stream.Seek (5, SeekOrigin.End);
  396. AssertEquals ("test#01", -1, stream.ReadByte ());
  397. stream.Seek (-5, SeekOrigin.End);
  398. AssertEquals ("test#02", 6, stream.ReadByte ());
  399. try {
  400. stream.Seek (-11, SeekOrigin.End);
  401. Fail ();
  402. } catch (Exception e) {
  403. AssertEquals ("test#03", typeof (IOException), e.GetType ());
  404. }
  405. stream.Seek (19, SeekOrigin.Begin);
  406. AssertEquals ("test#04", -1, stream.ReadByte ());
  407. stream.Seek (1, SeekOrigin.Begin);
  408. AssertEquals ("test#05", 2, stream.ReadByte ());
  409. stream.Seek (3, SeekOrigin.Current);
  410. AssertEquals ("test#06", 6, stream.ReadByte ());
  411. stream.Seek (-2, SeekOrigin.Current);
  412. AssertEquals ("test#07", 5, stream.ReadByte ());
  413. stream.Flush ();
  414. // Test that seeks work correctly when seeking inside the buffer
  415. stream.Seek (0, SeekOrigin.Begin);
  416. stream.WriteByte (0);
  417. stream.WriteByte (1);
  418. stream.Seek (0, SeekOrigin.Begin);
  419. byte[] buf = new byte [1];
  420. buf [0] = 2;
  421. stream.Write (buf, 0, 1);
  422. stream.Write (buf, 0, 1);
  423. stream.Flush ();
  424. stream.Seek (0, SeekOrigin.Begin);
  425. AssertEquals ("test#08", 2, stream.ReadByte ());
  426. AssertEquals ("test#09", 2, stream.ReadByte ());
  427. stream.Close ();
  428. DeleteFile (path);
  429. }
  430. public void TestClose ()
  431. {
  432. string path = TempFolder + Path.DirectorySeparatorChar + "TestClose";
  433. DeleteFile (path);
  434. FileStream stream = new FileStream (path, FileMode.CreateNew, FileAccess.ReadWrite);
  435. stream.Write (new byte [] {1, 2, 3, 4}, 0, 4);
  436. stream.ReadByte ();
  437. stream.Close ();
  438. try {
  439. stream.ReadByte ();
  440. Fail ();
  441. } catch (Exception e) {
  442. AssertEquals ("test#01", typeof (ObjectDisposedException), e.GetType ());
  443. }
  444. try {
  445. stream.WriteByte (64);
  446. Fail ();
  447. } catch (Exception e) {
  448. AssertEquals ("test#02", typeof (ObjectDisposedException), e.GetType ());
  449. }
  450. try {
  451. stream.Flush ();
  452. Fail ();
  453. } catch (Exception e) {
  454. AssertEquals ("test#03", typeof (ObjectDisposedException), e.GetType ());
  455. }
  456. try {
  457. long l = stream.Length;
  458. Fail ();
  459. } catch (Exception e) {
  460. AssertEquals ("test#04", typeof (ObjectDisposedException), e.GetType ());
  461. }
  462. try {
  463. long l = stream.Position;
  464. Fail ();
  465. } catch (Exception e) {
  466. AssertEquals ("test#05", typeof (ObjectDisposedException), e.GetType ());
  467. }
  468. AssertEquals ("test#06", false, stream.CanRead);
  469. AssertEquals ("test#07", false, stream.CanSeek);
  470. AssertEquals ("test#08", false, stream.CanWrite);
  471. AssertEquals ("test#09", true, stream.Name.EndsWith (path));
  472. DeleteFile (path);
  473. }
  474. /// <summary>
  475. /// Checks whether the <see cref="FileStream" /> throws a <see cref="NotSupportedException" />
  476. /// when the stream is opened with access mode <see cref="FileAccess.Read" /> and the
  477. /// <see cref="FileStream.Write(byte[], int, int)" /> method is called.
  478. /// </summary>
  479. [Test]
  480. [ExpectedException (typeof(NotSupportedException))]
  481. public void TestWriteVerifyAccessMode ()
  482. {
  483. string path = TempFolder + Path.DirectorySeparatorChar + "temp";
  484. DeleteFile (path);
  485. FileStream stream = null;
  486. byte[] buffer;
  487. try {
  488. buffer = Encoding.ASCII.GetBytes ("test");
  489. stream = new FileStream (path, FileMode.OpenOrCreate, FileAccess.Read);
  490. stream.Write (buffer, 0, buffer.Length);
  491. } finally {
  492. if (stream != null)
  493. stream.Close();
  494. DeleteFile (path);
  495. }
  496. }
  497. /// <summary>
  498. /// Checks whether the <see cref="FileStream" /> throws a <see cref="NotSupportedException" />
  499. /// when the stream is opened with access mode <see cref="FileAccess.Read" /> and the
  500. /// <see cref="FileStream.WriteByte(byte)" /> method is called.
  501. /// </summary>
  502. [Test]
  503. [ExpectedException (typeof (NotSupportedException))]
  504. public void TestWriteByteVerifyAccessMode ()
  505. {
  506. string path = TempFolder + Path.DirectorySeparatorChar + "temp";
  507. DeleteFile (path);
  508. FileStream stream = null;
  509. try {
  510. stream = new FileStream (path, FileMode.OpenOrCreate, FileAccess.Read);
  511. stream.WriteByte (Byte.MinValue);
  512. } finally {
  513. if (stream != null)
  514. stream.Close ();
  515. DeleteFile (path);
  516. }
  517. }
  518. /// <summary>
  519. /// Checks whether the <see cref="FileStream" /> throws a <see cref="NotSupportedException" />
  520. /// when the stream is opened with access mode <see cref="FileAccess.Write" /> and the
  521. /// <see cref="FileStream.Read(byte[], int, int)" /> method is called.
  522. /// </summary>
  523. [Test]
  524. [ExpectedException (typeof (NotSupportedException))]
  525. public void TestReadVerifyAccessMode ()
  526. {
  527. string path = TempFolder + Path.DirectorySeparatorChar + "temp";
  528. DeleteFile (path);
  529. FileStream stream = null;
  530. byte[] buffer = new byte [100];
  531. try {
  532. stream = new FileStream (path, FileMode.OpenOrCreate, FileAccess.Write);
  533. stream.Read (buffer, 0, buffer.Length);
  534. } finally {
  535. if (stream != null)
  536. stream.Close ();
  537. }
  538. }
  539. /// <summary>
  540. /// Checks whether the <see cref="FileStream" /> throws a <see cref="NotSupportedException" />
  541. /// when the stream is opened with access mode <see cref="FileAccess.Write" /> and the
  542. /// <see cref="FileStream.ReadByte()" /> method is called.
  543. /// </summary>
  544. [Test]
  545. [ExpectedException (typeof (NotSupportedException))]
  546. public void TestReadByteVerifyAccessMode ()
  547. {
  548. string path = TempFolder + Path.DirectorySeparatorChar + "temp";
  549. DeleteFile (path);
  550. FileStream stream = null;
  551. try {
  552. stream = new FileStream (path, FileMode.OpenOrCreate, FileAccess.Write);
  553. int readByte = stream.ReadByte ();
  554. } finally {
  555. if (stream != null)
  556. stream.Close();
  557. DeleteFile (path);
  558. }
  559. }
  560. private void DeleteFile (string path)
  561. {
  562. if (File.Exists (path))
  563. File.Delete (path);
  564. }
  565. }
  566. }