axiosengine/axios/Engine/File/AxiosRegularFile.cs

70 lines
1.8 KiB
C#
Raw Normal View History

using System.IO;
using System;
2012-03-19 23:57:59 +00:00
using Axios.Engine.Interfaces;
namespace Axios.Engine.File
{
public class AxiosRegularFile : AxiosFile, IAxiosFile, IDisposable
2012-03-19 23:57:59 +00:00
{
protected FileStream _fs;
2012-03-19 23:57:59 +00:00
public AxiosRegularFile(string file)
{
_filename = file;
}
public override void WriteData(string data, FileMode mode)
{
//Make sure that a proper mode is passed
if (mode == FileMode.Append
|| mode == FileMode.Create
|| mode == FileMode.CreateNew
|| mode == FileMode.Truncate)
{
FileStream fs = new FileStream(_filename, mode);
StreamWriter sw = new StreamWriter(fs);
sw.Write(data);
sw.Close();
}
}
public override string ReadData()
{
string ret = "";
FileStream fs = new FileStream(_filename, FileMode.Open);
StreamReader sr = new StreamReader(fs);
ret = sr.ReadToEnd();
sr.Close();
return ret;
}
public override Stream GetStream(FileMode mode)
{
_fs = new FileStream(_filename, mode);
return (Stream)_fs;
}
public void Dispose()
{
// http://msdn.microsoft.com/en-us/library/system.idisposable%28v=vs.110%29.aspx
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposed)
return;
if (disposing && _fs != null)
{
_fs.Close();
}
disposed = true;
}
2012-03-19 23:57:59 +00:00
}
}