Override ResourceInputStream::read() and ResourceInputStream::available() instead of implementing the natives they call

This commit is contained in:
Marco Castelluccio 2014-09-25 11:40:22 -07:00
Родитель 62ec354597
Коммит 9a7e55135c
1 изменённых файлов: 16 добавлений и 4 удалений

Просмотреть файл

@ -573,13 +573,25 @@ Native["com/sun/cldc/io/ResourceInputStream.open.(Ljava/lang/String;)Ljava/lang/
stack.push(obj);
};
Native["com/sun/cldc/io/ResourceInputStream.bytesRemain.(Ljava/lang/Object;)I"] = function(ctx, stack) {
var handle = stack.pop();
Override["com/sun/cldc/io/ResourceInputStream.available.()I"] = function(ctx, stack) {
var _this = stack.pop();
var handle = _this.class.getField("fileDecoder", "Ljava/lang/Object;").get(_this);
if (!handle) {
ctx.raiseExceptionAndYield("java/io/IOException");
}
stack.push(handle.data.length - handle.pos);
}
Native["com/sun/cldc/io/ResourceInputStream.readByte.(Ljava/lang/Object;)I"] = function(ctx, stack) {
var handle = stack.pop();
Override["com/sun/cldc/io/ResourceInputStream.read.()I"] = function(ctx, stack) {
var _this = stack.pop();
var handle = _this.class.getField("fileDecoder", "Ljava/lang/Object;").get(_this);
if (!handle) {
ctx.raiseExceptionAndYield("java/io/IOException");
}
stack.push((handle.data.length - handle.pos > 0) ? handle.data[handle.pos++] : -1);
}