Mercurial > projects > dwt-linux
comparison 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 |
comparison
equal
deleted
inserted
replaced
359:fd2409fb852e | 360:ee1dd551f5b1 |
---|---|
6 import dwt.dwthelper.utils; | 6 import dwt.dwthelper.utils; |
7 import dwt.dwthelper.File; | 7 import dwt.dwthelper.File; |
8 import dwt.dwthelper.InputStream; | 8 import dwt.dwthelper.InputStream; |
9 | 9 |
10 version(TANGOSVN){ | 10 version(TANGOSVN){ |
11 import tango.io.device.File; | 11 import TangoFile = tango.io.device.File; |
12 } else { | 12 } else { |
13 import tango.io.FileConduit; | 13 import TangoFile = tango.io.FileConduit; |
14 } | 14 } |
15 import tango.io.protocol.Reader; | |
16 import tango.core.Exception; | 15 import tango.core.Exception; |
17 import tango.text.convert.Format; | 16 import tango.text.convert.Format; |
18 | 17 |
19 public class FileInputStream : dwt.dwthelper.InputStream.InputStream { | 18 public class FileInputStream : dwt.dwthelper.InputStream.InputStream { |
20 | 19 |
21 alias dwt.dwthelper.InputStream.InputStream.read read; | 20 alias dwt.dwthelper.InputStream.InputStream.read read; |
22 | 21 |
23 version(TANGOSVN) | 22 private TangoFile.File conduit; |
24 private tango.io.device.File.File file_; | |
25 else | |
26 private FileConduit conduit; | |
27 | |
28 private ubyte[] buffer; | 23 private ubyte[] buffer; |
29 private int buf_pos; | 24 private int buf_pos; |
30 private int buf_size; | 25 private int buf_size; |
31 private const int BUFFER_SIZE = 0x10000; | 26 private const int BUFFER_SIZE = 0x10000; |
32 private bool eof; | 27 private bool eof; |
33 | 28 |
34 public this ( String name ){ | 29 public this ( String name ){ |
35 version(TANGOSVN) | 30 conduit = new TangoFile.File( name ); |
36 file_ = new tango.io.device.File.File( name ); | |
37 else | |
38 conduit = new FileConduit( name ); | |
39 | |
40 buffer = new ubyte[]( BUFFER_SIZE ); | 31 buffer = new ubyte[]( BUFFER_SIZE ); |
41 } | 32 } |
42 | 33 |
43 public this ( dwt.dwthelper.File.File file ){ | 34 public this ( dwt.dwthelper.File.File file ){ |
44 implMissing( __FILE__, __LINE__ ); | 35 implMissing( __FILE__, __LINE__ ); |
45 version(TANGOSVN) | 36 conduit = new TangoFile.File( file.getAbsolutePath(), TangoFile.File.ReadExisting ); |
46 file_ = new tango.io.device.File.File ( file.getAbsolutePath(), tango.io.device.File.File.ReadExisting ); | |
47 else | |
48 conduit = new FileConduit( file.getAbsolutePath(), FileConduit.ReadExisting ); | |
49 buffer = new ubyte[]( BUFFER_SIZE ); | 37 buffer = new ubyte[]( BUFFER_SIZE ); |
50 } | 38 } |
51 | 39 |
52 public override int read(){ | 40 public override int read(){ |
53 if( eof ){ | 41 if( eof ){ |
54 return -1; | 42 return -1; |
55 } | 43 } |
56 try{ | 44 try{ |
57 if( buf_pos == buf_size ){ | 45 if( buf_pos == buf_size ){ |
58 buf_pos = 0; | 46 buf_pos = 0; |
59 version(TANGOSVN) | 47 buf_size = conduit.input.read( buffer ); |
60 buf_size = file_.read( buffer ); | |
61 else | |
62 buf_size = conduit.input.read( buffer ); | |
63 } | 48 } |
64 if( buf_size <= 0 ){ | 49 if( buf_size <= 0 ){ |
65 eof = true; | 50 eof = true; |
66 return -1; | 51 return -1; |
67 } | 52 } |
86 implMissing( __FILE__, __LINE__ ); | 71 implMissing( __FILE__, __LINE__ ); |
87 return 0; | 72 return 0; |
88 } | 73 } |
89 | 74 |
90 public override void close(){ | 75 public override void close(){ |
91 version(TANGOSVN) | 76 conduit.close(); |
92 file_.close(); | |
93 else | |
94 conduit.close(); | |
95 } | 77 } |
96 } | 78 } |
97 | 79 |
98 | 80 |