Fix a potential crash in html parsing code. How come it was never reported ?
[beagle.git] / bludgeon / TextFileObject.cs
blob168a20f780029e1d9a6f22b1c27d6abaa22d5fad
2 using System;
3 using System.Collections;
4 using System.IO;
5 using System.Text;
7 using Beagle.Util;
8 using Beagle;
10 namespace Bludgeon {
12 public class TextFileObject : FileObject {
14 const int body_size = 10;
15 string [] body;
17 public TextFileObject ()
19 body = new string [body_size];
20 for (int i = 0; i < body_size; ++i)
21 body [i] = Token.GetRandom ();
24 override public string MimeType {
25 get { return "text/plain"; }
28 override public string Extension {
29 get { return ".txt"; }
32 override public void AddToStream (Stream stream, EventTracker tracker)
34 if (tracker != null)
35 tracker.ExpectingAdded (this.Uri);
37 // We can't just use a StreamWriter here, since that
38 // will close the underlying stream when it gets
39 // disposed.
40 UnclosableStream unclosable = new UnclosableStream (stream);
41 StreamWriter writer = new StreamWriter (unclosable);
43 foreach (string str in body)
44 writer.WriteLine (str);
46 writer.Close ();
49 override protected bool MatchesQueryPart (QueryPart abstract_part)
51 if (abstract_part is QueryPart_Text) {
52 QueryPart_Text part;
53 part = (QueryPart_Text) abstract_part;
55 if (part.SearchFullText)
56 foreach (string str in body)
57 if (part.Text == str)
58 return true;
61 return false;