Mercurial > projects > dwt-win
annotate dwt/dwthelper/FileInputStream.d @ 308:8d53428f9be0
Tango breaking change for new package tango.io.device
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 14 Sep 2008 19:58:20 +0200 |
parents | ab60f3309436 |
children | 1ee938a6e02e |
rev | line source |
---|---|
0 | 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 | |
308
8d53428f9be0
Tango breaking change for new package tango.io.device
Frank Benoit <benoit@tionex.de>
parents:
212
diff
changeset
|
10 version(TANGOSVN){ |
8d53428f9be0
Tango breaking change for new package tango.io.device
Frank Benoit <benoit@tionex.de>
parents:
212
diff
changeset
|
11 import tango.io.device.FileConduit; |
8d53428f9be0
Tango breaking change for new package tango.io.device
Frank Benoit <benoit@tionex.de>
parents:
212
diff
changeset
|
12 } else { |
0 | 13 import tango.io.FileConduit; |
308
8d53428f9be0
Tango breaking change for new package tango.io.device
Frank Benoit <benoit@tionex.de>
parents:
212
diff
changeset
|
14 } |
0 | 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 | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
30 public this ( String name ){ |
0 | 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 |