Browse Source

Revert "[java] use BufferedInputStream in FileInput"

This reverts commit a2c3714582edebe09b56cb815ee517dcab04f9de.
Simon Krajewski 1 year ago
parent
commit
a79f913737
1 changed files with 18 additions and 8 deletions
  1. 18 8
      std/java/_std/sys/io/FileInput.hx

+ 18 - 8
std/java/_std/sys/io/FileInput.hx

@@ -22,8 +22,6 @@
 
 
 package sys.io;
 package sys.io;
 
 
-import java.io.FileInputStream;
-import java.io.BufferedInputStream;
 import haxe.Int64;
 import haxe.Int64;
 import haxe.io.Bytes;
 import haxe.io.Bytes;
 import haxe.io.Eof;
 import haxe.io.Eof;
@@ -33,12 +31,10 @@ import java.io.IOException;
 
 
 class FileInput extends Input {
 class FileInput extends Input {
 	var f:java.io.RandomAccessFile;
 	var f:java.io.RandomAccessFile;
-	var b:BufferedInputStream;
 	var _eof:Bool;
 	var _eof:Bool;
 
 
 	function new(f) {
 	function new(f) {
 		this.f = f;
 		this.f = f;
-		b = new BufferedInputStream(new FileInputStream(f.getFD()));
 		this._eof = false;
 		this._eof = false;
 	}
 	}
 
 
@@ -50,16 +46,29 @@ class FileInput extends Input {
 	}
 	}
 
 
 	override public function readByte():Int {
 	override public function readByte():Int {
-		var i = b.read();
-		if (i == -1) {
+		try {
+			return f.readUnsignedByte();
+		} catch (e:EOFException) {
+
 			_eof = true;
 			_eof = true;
 			throw new Eof();
 			throw new Eof();
+		} catch (e:IOException) {
+			throw haxe.io.Error.Custom(e);
 		}
 		}
-		return i;
 	}
 	}
 
 
 	override public function readBytes(s:Bytes, pos:Int, len:Int):Int {
 	override public function readBytes(s:Bytes, pos:Int, len:Int):Int {
-		var ret = b.read(s.getData(), pos, len);
+		var ret = 0;
+		try {
+			ret = f.read(s.getData(), pos, len);
+		} catch (e:EOFException) {
+
+			_eof = true;
+			throw new Eof();
+		} catch (e:IOException) {
+			throw haxe.io.Error.Custom(e);
+		}
+
 		if (ret == -1) {
 		if (ret == -1) {
 			_eof = true;
 			_eof = true;
 			throw new Eof();
 			throw new Eof();
@@ -80,6 +89,7 @@ class FileInput extends Input {
 					f.seek(haxe.Int64.add(f.length(), cast p));
 					f.seek(haxe.Int64.add(f.length(), cast p));
 			}
 			}
 		} catch (e:EOFException) {
 		} catch (e:EOFException) {
+
 			_eof = true;
 			_eof = true;
 			throw new Eof();
 			throw new Eof();
 		} catch (e:IOException) {
 		} catch (e:IOException) {