Mercurial > projects > dwt2
view 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 |
line wrap: on
line source
/** * Authors: Frank Benoit <keinfarbton@googlemail.com> */ module java.io.FileInputStream; import java.lang.all; import java.io.File; import java.io.InputStream; version(TANGOSVN){ import TangoFile = tango.io.device.File; } else { import TangoFile = tango.io.FileConduit; } import tango.core.Exception; import tango.text.convert.Format; public class FileInputStream : java.io.InputStream.InputStream { alias java.io.InputStream.InputStream.read read; private TangoFile.File conduit; private ubyte[] buffer; private int buf_pos; private int buf_size; private const int BUFFER_SIZE = 0x10000; private bool eof; public this ( String name ){ conduit = new TangoFile.File( name ); buffer = new ubyte[]( BUFFER_SIZE ); } public this ( java.io.File.File file ){ implMissing( __FILE__, __LINE__ ); conduit = new TangoFile.File( file.getAbsolutePath(), TangoFile.File.ReadExisting ); buffer = new ubyte[]( BUFFER_SIZE ); } public override int read(){ if( eof ){ return -1; } try{ if( buf_pos == buf_size ){ buf_pos = 0; buf_size = conduit.input.read( buffer ); } if( buf_size <= 0 ){ eof = true; return -1; } assert( buf_pos < BUFFER_SIZE, Format( "{0} {1}", buf_pos, buf_size ) ); assert( buf_size <= BUFFER_SIZE ); int res = cast(int) buffer[ buf_pos ]; buf_pos++; return res; } catch( IOException e ){ eof = true; return -1; } } public long skip( long n ){ implMissing( __FILE__, __LINE__ ); return 0L; } public int available(){ implMissing( __FILE__, __LINE__ ); return 0; } public override void close(){ conduit.close(); } }