Mercurial > projects > dwt-linux
annotate dwt/dwthelper/FileInputStream.d @ 356:8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
author | John Reimer <terminal.node@gmail.com> |
---|---|
date | Sun, 04 Jan 2009 02:47:54 -0500 |
parents | a2166f25ce17 |
children | ee1dd551f5b1 |
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){ |
356
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
11 import tango.io.device.File; |
316 | 12 } else { |
356
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
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 | |
356
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
23 version(TANGOSVN) |
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
24 private tango.io.device.File.File file_; |
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
25 else |
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
26 private FileConduit conduit; |
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
27 |
12 | 28 private ubyte[] buffer; |
29 private int buf_pos; | |
30 private int buf_size; | |
31 private const int BUFFER_SIZE = 0x10000; | |
32 private bool eof; | |
33 | |
238 | 34 public this ( String name ){ |
356
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
35 version(TANGOSVN) |
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
36 file_ = new tango.io.device.File.File( name ); |
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
37 else |
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
38 conduit = new FileConduit( name ); |
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
39 |
12 | 40 buffer = new ubyte[]( BUFFER_SIZE ); |
41 } | |
42 | |
43 public this ( dwt.dwthelper.File.File file ){ | |
44 implMissing( __FILE__, __LINE__ ); | |
356
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
45 version(TANGOSVN) |
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
46 file_ = new tango.io.device.File.File ( file.getAbsolutePath(), tango.io.device.File.File.ReadExisting ); |
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
47 else |
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
48 conduit = new FileConduit( file.getAbsolutePath(), FileConduit.ReadExisting ); |
12 | 49 buffer = new ubyte[]( BUFFER_SIZE ); |
50 } | |
51 | |
52 public override int read(){ | |
53 if( eof ){ | |
54 return -1; | |
55 } | |
56 try{ | |
57 if( buf_pos == buf_size ){ | |
58 buf_pos = 0; | |
356
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
59 version(TANGOSVN) |
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
60 buf_size = file_.read( buffer ); |
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
61 else |
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
62 buf_size = conduit.input.read( buffer ); |
12 | 63 } |
64 if( buf_size <= 0 ){ | |
65 eof = true; | |
66 return -1; | |
67 } | |
68 assert( buf_pos < BUFFER_SIZE, Format( "{0} {1}", buf_pos, buf_size ) ); | |
69 assert( buf_size <= BUFFER_SIZE ); | |
70 int res = cast(int) buffer[ buf_pos ]; | |
71 buf_pos++; | |
72 return res; | |
73 } | |
74 catch( IOException e ){ | |
75 eof = true; | |
76 return -1; | |
77 } | |
78 } | |
79 | |
80 public long skip( long n ){ | |
81 implMissing( __FILE__, __LINE__ ); | |
82 return 0L; | |
83 } | |
84 | |
85 public int available(){ | |
86 implMissing( __FILE__, __LINE__ ); | |
87 return 0; | |
88 } | |
89 | |
90 public override void close(){ | |
356
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
91 version(TANGOSVN) |
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
92 file_.close(); |
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
93 else |
8ebacc5c07dc
Fixes for TANGOSVN r4235 -- still some warnings but builds
John Reimer <terminal.node@gmail.com>
parents:
316
diff
changeset
|
94 conduit.close(); |
12 | 95 } |
96 } | |
97 | |
98 |