Home | History | Annotate | Download | only in runtime
      1 package org.antlr.runtime {
      2 	import flash.filesystem.File;
      3 	import flash.filesystem.FileMode;
      4 	import flash.filesystem.FileStream;
      5 	import flash.system.System;
      6 	
      7 	public class ANTLRFileStream extends ANTLRStringStream {
      8 		protected var _file:File;
      9 		
     10 		public function ANTLRFileStream(file:File, encoding:String = null) {
     11 			load(file, encoding);
     12 		}
     13 
     14 		public function load(file:File, encoding:String = null):void {
     15 			_file = file;
     16 			if (encoding == null) {
     17 				encoding = File.systemCharset;
     18 			}
     19 			
     20 			var stream:FileStream = new FileStream();
     21 			
     22 			try {
     23 				stream.open(file, FileMode.READ);
     24 				data = stream.readMultiByte(file.size, encoding);
     25 				n = data.length;
     26 			}
     27 			finally {
     28 				stream.close();
     29 			}
     30 		}
     31 		
     32 		public override function get sourceName():String {
     33 			return _file.name;
     34 		}
     35 	}
     36 }