
Untitled
By: a guest on
Apr 17th, 2012 | syntax:
None | size: 2.07 KB | hits: 7 | expires: Never
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Illumine
{
public class TextDocument
{
private String _text;
private String _filePath;
/// <summary>
/// Constructor for the TextDocument class
/// </summary>
public TextDocument ()
{
_text = "";
_filePath = "";
}
/// <summary>
/// Constructor for the TextDocument class
/// Will attempt to load the text file into memory
/// </summary>
/// <param name="documentPath">A path to a file</param>
public TextDocument ( String documentPath )
{
_filePath = documentPath;
// Initializing a StreamReader object. We will attempt to figure out what the encoding is via the BOM if any.
StreamReader sr = new StreamReader ( _filePath, true );
try
{
String str = "";
do
{
str += sr.ReadLine ();
} while ( !sr.EndOfStream );
_text = str;
}
catch ( System.IO.IOException e )
{
System.Diagnostics.Debug.Print ( e.TargetSite + ": " + e.Message );
}
finally
{
sr.Close ();
}
}
/// <summary>
/// Constructor for the TextDocument class
/// Will attempt to load the text file into memory
/// </summary>
/// <param name="documentPath">A path to a file</param>
/// <param name="documentStream">A stream that points to a file; should be derived from the filePath.</param>
public TextDocument ( String documentPath, Stream documentStream )
{
_filePath = documentPath;
// Initializing a StreamReader object. We will attempt to figure out what the encoding is via the BOM if any.
StreamReader sr = new StreamReader ( documentStream, true );
try
{
String str = "";
do
{
str += sr.ReadLine ();
} while ( !sr.EndOfStream );
_text = str;
}
catch ( System.IO.IOException e )
{
System.Diagnostics.Debug.Print ( e.TargetSite + ": " + e.Message );
}
finally
{
sr.Close ();
}
}
public String GetDocument ()
{
return _text;
}
public String GetFilepath ()
{
return _filePath;
}
}
}