KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > groovy > syntax > lexer > FileCharStream


1 package org.codehaus.groovy.syntax.lexer;
2
3 import java.io.File JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.io.FileInputStream JavaDoc;
6 import org.codehaus.groovy.syntax.ReadException;
7
8 public class FileCharStream
9     implements CharStream
10 {
11     private File JavaDoc file;
12     private CharStream charStream;
13
14     public FileCharStream(File JavaDoc file)
15     {
16         this.file = file;
17     }
18
19     public File JavaDoc 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 JavaDoc( getFile() ) );
32             }
33         }
34         catch( IOException JavaDoc e )
35         {
36             throw new ReadException( e );
37         }
38
39         return this.charStream;
40     }
41
42     public String JavaDoc 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 }
59
Popular Tags