1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
* Use of this file is governed by the BSD 3-clause license that
* can be found in the LICENSE.txt file in the project root.
*/
using Encoding = System.Text.Encoding;
using File = System.IO.File;
namespace Antlr4.Runtime
{
/// <summary>
/// This is an
/// <see cref="AntlrInputStream"/>
/// that is loaded from a file all at once
/// when you construct the object.
/// </summary>
public class AntlrFileStream : AntlrInputStream
{
protected internal string fileName;
/// <exception cref="System.IO.IOException"/>
public AntlrFileStream(string fileName)
: this(fileName, null)
{
}
/// <exception cref="System.IO.IOException"/>
public AntlrFileStream(string fileName, Encoding encoding)
{
this.fileName = fileName;
Load(fileName, encoding);
}
/// <exception cref="System.IO.IOException"/>
public virtual void Load(string fileName, Encoding encoding)
{
if (fileName == null)
{
return;
}
string text;
if (encoding != null)
text = File.ReadAllText(fileName, encoding);
else
text = File.ReadAllText(fileName);
data = text.ToCharArray();
n = data.Length;
}
public override string SourceName
{
get
{
return fileName;
}
}
}
}