Mercurial > projects > dwt-linux
annotate dwt/dwthelper/FileInputStream.d @ 360:ee1dd551f5b1
Make compilable for tango 0.99.8
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 20 Mar 2009 20:30:32 +0100 |
parents | 8ebacc5c07dc |
children |
rev | line source |
---|---|
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){ |
360
ee1dd551f5b1
Make compilable for tango 0.99.8
Frank Benoit <benoit@tionex.de>
parents:
356
diff
changeset
|
11 import TangoFile = tango.io.device.File; |
316 | 12 } else { |
360
ee1dd551f5b1
Make compilable for tango 0.99.8
Frank Benoit <benoit@tionex.de>
parents:
356
diff
changeset
|
13 import TangoFile = tango.io.FileConduit; |
316 | 14 } |
12 | 15 import tango.core.Exception; |
16 import tango.text.convert.Format; | |
17 | |
18 public class FileInputStream : dwt.dwthelper.InputStream.InputStream { | |
19 | |
20 alias dwt.dwthelper.InputStream.InputStream.read read; | |
21 | |
360
ee1dd551f5b1
Make compilable for tango 0.99.8
Frank Benoit <benoit@tionex.de>
parents:
356
diff
changeset
|
22 private TangoFile.File conduit; |
12 | 23 private ubyte[] buffer; |
24 private int buf_pos; | |
25 private int buf_size; | |
26 private const int BUFFER_SIZE = 0x10000; | |
27 private bool eof; | |
28 | |
238 | 29 public this ( String name ){ |
360
ee1dd551f5b1
Make compilable for tango 0.99.8
Frank Benoit <benoit@tionex.de>
parents:
356
diff
changeset
|
30 conduit = new TangoFile.File( name ); |
12 | 31 buffer = new ubyte[]( BUFFER_SIZE ); |
32 } | |
33 | |
34 public this ( dwt.dwthelper.File.File file ){ | |
35 implMissing( __FILE__, __LINE__ ); | |
360
ee1dd551f5b1
Make compilable for tango 0.99.8
Frank Benoit <benoit@tionex.de>
parents:
356
diff
changeset
|
36 conduit = new TangoFile.File( file.getAbsolutePath(), TangoFile.File.ReadExisting ); |
12 | 37 buffer = new ubyte[]( BUFFER_SIZE ); |
38 } | |
39 | |
40 public override int read(){ | |
41 if( eof ){ | |
42 return -1; | |
43 } | |
44 try{ | |
45 if( buf_pos == buf_size ){ | |
46 buf_pos = 0; | |
360
ee1dd551f5b1
Make compilable for tango 0.99.8
Frank Benoit <benoit@tionex.de>
parents:
356
diff
changeset
|
47 buf_size = conduit.input.read( buffer ); |
12 | 48 } |
49 if( buf_size <= 0 ){ | |
50 eof = true; | |
51 return -1; | |
52 } | |
53 assert( buf_pos < BUFFER_SIZE, Format( "{0} {1}", buf_pos, buf_size ) ); | |
54 assert( buf_size <= BUFFER_SIZE ); | |
55 int res = cast(int) buffer[ buf_pos ]; | |
56 buf_pos++; | |
57 return res; | |
58 } | |
59 catch( IOException e ){ | |
60 eof = true; | |
61 return -1; | |
62 } | |
63 } | |
64 | |
65 public long skip( long n ){ | |
66 implMissing( __FILE__, __LINE__ ); | |
67 return 0L; | |
68 } | |
69 | |
70 public int available(){ | |
71 implMissing( __FILE__, __LINE__ ); | |
72 return 0; | |
73 } | |
74 | |
75 public override void close(){ | |
360
ee1dd551f5b1
Make compilable for tango 0.99.8
Frank Benoit <benoit@tionex.de>
parents:
356
diff
changeset
|
76 conduit.close(); |
12 | 77 } |
78 } | |
79 | |
80 |