comparison java/src/java/io/FileInputStream.d @ 0:6dd524f61e62

add dwt win and basic java stuff
author Frank Benoit <benoit@tionex.de>
date Mon, 02 Mar 2009 14:44:16 +0100
parents
children 2847134a5fc0
comparison
equal deleted inserted replaced
-1:000000000000 0:6dd524f61e62
1 /**
2 * Authors: Frank Benoit <keinfarbton@googlemail.com>
3 */
4 module java.io.FileInputStream;
5
6 import java.lang.all;
7 import java.io.File;
8 import java.io.InputStream;
9
10 version(TANGOSVN){
11 import TangoFile = tango.io.device.File;
12 } else {
13 import TangoFile = tango.io.FileConduit;
14 }
15 import tango.core.Exception;
16 import tango.text.convert.Format;
17
18 public class FileInputStream : java.io.InputStream.InputStream {
19
20 alias java.io.InputStream.InputStream.read read;
21
22 private TangoFile.File conduit;
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
29 public this ( String name ){
30 conduit = new TangoFile.File( name );
31 buffer = new ubyte[]( BUFFER_SIZE );
32 }
33
34 public this ( java.io.File.File file ){
35 implMissing( __FILE__, __LINE__ );
36 conduit = new TangoFile.File( file.getAbsolutePath(), TangoFile.File.ReadExisting );
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;
47 buf_size = conduit.input.read( buffer );
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(){
76 conduit.close();
77 }
78 }
79
80