Mercurial > projects > dwt-win
annotate dwt/dwthelper/FileInputStream.d @ 339:210994f12c4c
Fixes for dmd 1.041 and tango 0.99.8
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 28 Mar 2009 03:12:07 +0100 |
parents | f866e80af235 |
children |
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 | |
332
1ee938a6e02e
Tango updates, removing trace prints and added prints via Logger
Frank Benoit <benoit@tionex.de>
parents:
308
diff
changeset
|
10 import TangoFile = tango.io.device.File; |
0 | 11 import tango.core.Exception; |
12 import tango.text.convert.Format; | |
13 | |
14 public class FileInputStream : dwt.dwthelper.InputStream.InputStream { | |
15 | |
16 alias dwt.dwthelper.InputStream.InputStream.read read; | |
17 | |
332
1ee938a6e02e
Tango updates, removing trace prints and added prints via Logger
Frank Benoit <benoit@tionex.de>
parents:
308
diff
changeset
|
18 private TangoFile.File conduit; |
0 | 19 private ubyte[] buffer; |
20 private int buf_pos; | |
21 private int buf_size; | |
22 private const int BUFFER_SIZE = 0x10000; | |
23 private bool eof; | |
24 | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
25 public this ( String name ){ |
332
1ee938a6e02e
Tango updates, removing trace prints and added prints via Logger
Frank Benoit <benoit@tionex.de>
parents:
308
diff
changeset
|
26 conduit = new TangoFile.File( name ); |
0 | 27 buffer = new ubyte[]( BUFFER_SIZE ); |
28 } | |
29 | |
30 public this ( dwt.dwthelper.File.File file ){ | |
31 implMissing( __FILE__, __LINE__ ); | |
332
1ee938a6e02e
Tango updates, removing trace prints and added prints via Logger
Frank Benoit <benoit@tionex.de>
parents:
308
diff
changeset
|
32 conduit = new TangoFile.File( file.getAbsolutePath(), TangoFile.File.ReadExisting ); |
0 | 33 buffer = new ubyte[]( BUFFER_SIZE ); |
34 } | |
35 | |
36 public override int read(){ | |
37 if( eof ){ | |
38 return -1; | |
39 } | |
40 try{ | |
41 if( buf_pos == buf_size ){ | |
42 buf_pos = 0; | |
43 buf_size = conduit.input.read( buffer ); | |
44 } | |
45 if( buf_size <= 0 ){ | |
46 eof = true; | |
47 return -1; | |
48 } | |
49 assert( buf_pos < BUFFER_SIZE, Format( "{0} {1}", buf_pos, buf_size ) ); | |
50 assert( buf_size <= BUFFER_SIZE ); | |
51 int res = cast(int) buffer[ buf_pos ]; | |
52 buf_pos++; | |
53 return res; | |
54 } | |
55 catch( IOException e ){ | |
56 eof = true; | |
57 return -1; | |
58 } | |
59 } | |
60 | |
61 public long skip( long n ){ | |
62 implMissing( __FILE__, __LINE__ ); | |
63 return 0L; | |
64 } | |
65 | |
66 public int available(){ | |
67 implMissing( __FILE__, __LINE__ ); | |
68 return 0; | |
69 } | |
70 | |
71 public override void close(){ | |
72 conduit.close(); | |
73 } | |
74 } | |
75 | |
76 |