From 9a7e55135c138cdc16856ac18d9281c34177ea97 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Thu, 25 Sep 2014 11:40:22 -0700 Subject: [PATCH] Override ResourceInputStream::read() and ResourceInputStream::available() instead of implementing the natives they call --- native.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/native.js b/native.js index 70327f7a..697be2df 100644 --- a/native.js +++ b/native.js @@ -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); }