Procházet zdrojové kódy

[java] use BufferedInputStream in FileInput

closes #11487
Simon Krajewski před 1 rokem
rodič
revize
a2c3714582
1 změnil soubory, kde provedl 8 přidání a 18 odebrání
  1. 8 18
      std/java/_std/sys/io/FileInput.hx

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

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