1 package org.codehaus.groovy.syntax.lexer;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.io.FileInputStream;
6 import org.codehaus.groovy.syntax.ReadException;
7
8 public class FileCharStream
9 implements CharStream
10 {
11 private File file;
12 private CharStream charStream;
13
14 public FileCharStream(File file)
15 {
16 this.file = file;
17 }
18
19 public File getFile()
20 {
21 return this.file;
22 }
23
24 protected CharStream getCharStream()
25 throws ReadException
26 {
27 try
28 {
29 if ( this.charStream == null )
30 {
31 this.charStream = new InputStreamCharStream( new FileInputStream( getFile() ) );
32 }
33 }
34 catch( IOException e )
35 {
36 throw new ReadException( e );
37 }
38
39 return this.charStream;
40 }
41
42 public String getDescription()
43 {
44 return getFile().getPath();
45 }
46
47 public char consume()
48 throws ReadException
49 {
50 return getCharStream().consume();
51 }
52
53 public void close()
54 throws ReadException
55 {
56 getCharStream().close();
57 }
58 }