12
|
1 /**
|
|
2 * Authors: Frank Benoit <keinfarbton@googlemail.com>
|
|
3 */
|
|
4 module dwt.dwthelper.FileInputStream;
|
|
5
|
|
6 import dwt.dwthelper.utils;
|
|
7 import dwt.dwthelper.File;
|
|
8 import dwt.dwthelper.InputStream;
|
|
9
|
316
|
10 version(TANGOSVN){
|
|
11 import tango.io.device.FileConduit;
|
|
12 } else {
|
12
|
13 import tango.io.FileConduit;
|
316
|
14 }
|
12
|
15 import tango.io.protocol.Reader;
|
|
16 import tango.core.Exception;
|
|
17 import tango.text.convert.Format;
|
|
18
|
|
19 public class FileInputStream : dwt.dwthelper.InputStream.InputStream {
|
|
20
|
|
21 alias dwt.dwthelper.InputStream.InputStream.read read;
|
|
22
|
|
23 private FileConduit conduit;
|
|
24 private ubyte[] buffer;
|
|
25 private int buf_pos;
|
|
26 private int buf_size;
|
|
27 private const int BUFFER_SIZE = 0x10000;
|
|
28 private bool eof;
|
|
29
|
238
|
30 public this ( String name ){
|
12
|
31 conduit = new FileConduit( name );
|
|
32 buffer = new ubyte[]( BUFFER_SIZE );
|
|
33 }
|
|
34
|
|
35 public this ( dwt.dwthelper.File.File file ){
|
|
36 implMissing( __FILE__, __LINE__ );
|
|
37 conduit = new FileConduit( file.getAbsolutePath(), FileConduit.ReadExisting );
|
|
38 buffer = new ubyte[]( BUFFER_SIZE );
|
|
39 }
|
|
40
|
|
41 public override int read(){
|
|
42 if( eof ){
|
|
43 return -1;
|
|
44 }
|
|
45 try{
|
|
46 if( buf_pos == buf_size ){
|
|
47 buf_pos = 0;
|
|
48 buf_size = conduit.input.read( buffer );
|
|
49 }
|
|
50 if( buf_size <= 0 ){
|
|
51 eof = true;
|
|
52 return -1;
|
|
53 }
|
|
54 assert( buf_pos < BUFFER_SIZE, Format( "{0} {1}", buf_pos, buf_size ) );
|
|
55 assert( buf_size <= BUFFER_SIZE );
|
|
56 int res = cast(int) buffer[ buf_pos ];
|
|
57 buf_pos++;
|
|
58 return res;
|
|
59 }
|
|
60 catch( IOException e ){
|
|
61 eof = true;
|
|
62 return -1;
|
|
63 }
|
|
64 }
|
|
65
|
|
66 public long skip( long n ){
|
|
67 implMissing( __FILE__, __LINE__ );
|
|
68 return 0L;
|
|
69 }
|
|
70
|
|
71 public int available(){
|
|
72 implMissing( __FILE__, __LINE__ );
|
|
73 return 0;
|
|
74 }
|
|
75
|
|
76 public override void close(){
|
|
77 conduit.close();
|
|
78 }
|
|
79 }
|
|
80
|
|
81
|