comparison java/src/java/io/FileInputStream.d @ 21:9b96950f2c3c

the 'java' tree compiles on both D1-Tango and D2-Phobos
author Frank Benoit <benoit@tionex.de>
date Thu, 19 Mar 2009 20:38:55 +0100
parents 2847134a5fc0
children
comparison
equal deleted inserted replaced
20:dccb717aa902 21:9b96950f2c3c
5 5
6 import java.lang.all; 6 import java.lang.all;
7 import java.io.File; 7 import java.io.File;
8 import java.io.InputStream; 8 import java.io.InputStream;
9 9
10 import TangoFile = tango.io.device.File; 10 version(Tango){
11 import tango.core.Exception; 11 import TangoFile = tango.io.device.File;
12 import tango.text.convert.Format; 12 } else { // Phobos
13 }
13 14
14 public class FileInputStream : java.io.InputStream.InputStream { 15 public class FileInputStream : java.io.InputStream.InputStream {
15 16
16 alias java.io.InputStream.InputStream.read read; 17 alias java.io.InputStream.InputStream.read read;
17 18
18 private TangoFile.File conduit; 19 version(Tango){
20 private TangoFile.File conduit;
21 } else { // Phobos
22 }
19 private ubyte[] buffer; 23 private ubyte[] buffer;
20 private int buf_pos; 24 private int buf_pos;
21 private int buf_size; 25 private int buf_size;
22 private const int BUFFER_SIZE = 0x10000; 26 private const int BUFFER_SIZE = 0x10000;
23 private bool eof; 27 private bool eof;
24 28
25 public this ( String name ){ 29 public this ( String name ){
26 conduit = new TangoFile.File( name ); 30 version(Tango){
31 conduit = new TangoFile.File( name );
32 } else { // Phobos
33 implMissing( __FILE__, __LINE__ );
34 }
27 buffer = new ubyte[]( BUFFER_SIZE ); 35 buffer = new ubyte[]( BUFFER_SIZE );
28 } 36 }
29 37
30 public this ( java.io.File.File file ){ 38 public this ( java.io.File.File file ){
31 implMissing( __FILE__, __LINE__ ); 39 implMissing( __FILE__, __LINE__ );
32 conduit = new TangoFile.File( file.getAbsolutePath(), TangoFile.File.ReadExisting ); 40 version(Tango){
41 conduit = new TangoFile.File( file.getAbsolutePath(), TangoFile.File.ReadExisting );
42 } else { // Phobos
43 implMissing( __FILE__, __LINE__ );
44 }
33 buffer = new ubyte[]( BUFFER_SIZE ); 45 buffer = new ubyte[]( BUFFER_SIZE );
34 } 46 }
35 47
36 public override int read(){ 48 public override int read(){
37 if( eof ){ 49 version(Tango){
38 return -1; 50 if( eof ){
39 } 51 return -1;
40 try{
41 if( buf_pos == buf_size ){
42 buf_pos = 0;
43 buf_size = conduit.input.read( buffer );
44 } 52 }
45 if( buf_size <= 0 ){ 53 try{
54 if( buf_pos == buf_size ){
55 buf_pos = 0;
56 buf_size = conduit.input.read( buffer );
57 }
58 if( buf_size <= 0 ){
59 eof = true;
60 return -1;
61 }
62 assert( buf_pos < BUFFER_SIZE, Format( "{0} {1}", buf_pos, buf_size ) );
63 assert( buf_size <= BUFFER_SIZE );
64 int res = cast(int) buffer[ buf_pos ];
65 buf_pos++;
66 return res;
67 }
68 catch( IOException e ){
46 eof = true; 69 eof = true;
47 return -1; 70 return -1;
48 } 71 }
49 assert( buf_pos < BUFFER_SIZE, Format( "{0} {1}", buf_pos, buf_size ) ); 72 } else { // Phobos
50 assert( buf_size <= BUFFER_SIZE ); 73 implMissing( __FILE__, __LINE__ );
51 int res = cast(int) buffer[ buf_pos ]; 74 return 0;
52 buf_pos++;
53 return res;
54 }
55 catch( IOException e ){
56 eof = true;
57 return -1;
58 } 75 }
59 } 76 }
60 77
61 public long skip( long n ){ 78 public long skip( long n ){
62 implMissing( __FILE__, __LINE__ ); 79 implMissing( __FILE__, __LINE__ );
67 implMissing( __FILE__, __LINE__ ); 84 implMissing( __FILE__, __LINE__ );
68 return 0; 85 return 0;
69 } 86 }
70 87
71 public override void close(){ 88 public override void close(){
72 conduit.close(); 89 version(Tango){
90 conduit.close();
91 } else { // Phobos
92 implMissing( __FILE__, __LINE__ );
93 }
73 } 94 }
74 } 95 }
75 96
76 97