comparison base/src/java/io/FileInputStream.d @ 112:9f4c18c268b2

Update to compile and execute with dmd 2.052.
author kntroh
date Wed, 16 Mar 2011 21:53:53 +0900
parents 1bf55a6eb092
children 536e43f63c81
comparison
equal deleted inserted replaced
111:b6e9904989ed 112:9f4c18c268b2
8 import java.io.InputStream; 8 import java.io.InputStream;
9 9
10 version(Tango){ 10 version(Tango){
11 import TangoFile = tango.io.device.File; 11 import TangoFile = tango.io.device.File;
12 } else { // Phobos 12 } else { // Phobos
13 static import std.stream;
13 } 14 }
14 15
15 public class FileInputStream : java.io.InputStream.InputStream { 16 public class FileInputStream : java.io.InputStream.InputStream {
16 17
17 alias java.io.InputStream.InputStream.read read; 18 alias java.io.InputStream.InputStream.read read;
18 19
19 version(Tango){ 20 version(Tango){
20 private TangoFile.File conduit; 21 private TangoFile.File conduit;
21 } else { // Phobos 22 } else { // Phobos
23 private std.stream.File conduit;
22 } 24 }
23 private ubyte[] buffer; 25 private ubyte[] buffer;
24 private int buf_pos; 26 private int buf_pos;
25 private int buf_size; 27 private int buf_size;
26 private const int BUFFER_SIZE = 0x10000; 28 private const int BUFFER_SIZE = 0x10000;
28 30
29 public this ( String name ){ 31 public this ( String name ){
30 version(Tango){ 32 version(Tango){
31 conduit = new TangoFile.File( name ); 33 conduit = new TangoFile.File( name );
32 } else { // Phobos 34 } else { // Phobos
33 implMissing( __FILE__, __LINE__ ); 35 conduit = new std.stream.File( name );
34 } 36 }
35 buffer = new ubyte[]( BUFFER_SIZE ); 37 buffer = new ubyte[]( BUFFER_SIZE );
36 } 38 }
37 39
38 public this ( java.io.File.File file ){ 40 public this ( java.io.File.File file ){
39 implMissing( __FILE__, __LINE__ ); 41 implMissing( __FILE__, __LINE__ );
40 version(Tango){ 42 version(Tango){
41 conduit = new TangoFile.File( file.getAbsolutePath(), TangoFile.File.ReadExisting ); 43 conduit = new TangoFile.File( file.getAbsolutePath(), TangoFile.File.ReadExisting );
42 } else { // Phobos 44 } else { // Phobos
43 implMissing( __FILE__, __LINE__ ); 45 conduit = new std.stream.File( file.getAbsolutePath(), std.stream.FileMode.In );
44 } 46 }
45 buffer = new ubyte[]( BUFFER_SIZE ); 47 buffer = new ubyte[]( BUFFER_SIZE );
46 } 48 }
47 49
48 public override int read(){ 50 public override int read(){
68 catch( IOException e ){ 70 catch( IOException e ){
69 eof = true; 71 eof = true;
70 return -1; 72 return -1;
71 } 73 }
72 } else { // Phobos 74 } else { // Phobos
73 implMissing( __FILE__, __LINE__ ); 75 if( eof ){
74 return 0; 76 return -1;
77 }
78 try{
79 if( buf_pos == buf_size ){
80 buf_pos = 0;
81 buf_size = conduit.read( buffer );
82 }
83 if( buf_size <= 0 ){
84 eof = true;
85 return -1;
86 }
87 assert( buf_pos < BUFFER_SIZE, Format( "{} {}", buf_pos, buf_size ) );
88 assert( buf_size <= BUFFER_SIZE );
89 int res = cast(int) buffer[ buf_pos ];
90 buf_pos++;
91 return res;
92 }
93 catch( IOException e ){
94 eof = true;
95 return -1;
96 }
75 } 97 }
76 } 98 }
77 99
78 public long skip( long n ){ 100 public long skip( long n ){
79 implMissing( __FILE__, __LINE__ ); 101 implMissing( __FILE__, __LINE__ );
87 109
88 public override void close(){ 110 public override void close(){
89 version(Tango){ 111 version(Tango){
90 conduit.close(); 112 conduit.close();
91 } else { // Phobos 113 } else { // Phobos
92 implMissing( __FILE__, __LINE__ ); 114 conduit.close();
93 } 115 }
94 } 116 }
95 } 117 }
96 118
97 119