2014-09-24 10:50:23 +04:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var Override = {};
|
|
|
|
|
2014-09-24 10:56:54 +04:00
|
|
|
Override.getKey = function(methodInfo) {
|
|
|
|
return methodInfo.classInfo.className + "." + methodInfo.name + "." + methodInfo.signature;
|
|
|
|
}
|
|
|
|
|
|
|
|
Override.hasMethod = function(methodInfo) {
|
2014-09-24 20:14:49 +04:00
|
|
|
return ("override" in methodInfo || Override.getKey(methodInfo) in Override);
|
2014-09-24 10:56:54 +04:00
|
|
|
}
|
|
|
|
|
2014-09-24 10:50:23 +04:00
|
|
|
Override.invoke = function(ctx, methodInfo) {
|
2014-09-24 11:32:43 +04:00
|
|
|
if (!methodInfo.override) {
|
|
|
|
var key = Override.getKey(methodInfo);
|
|
|
|
methodInfo.override = Override[key];
|
2014-09-24 10:50:23 +04:00
|
|
|
if (!methodInfo.override) {
|
2014-09-24 11:32:43 +04:00
|
|
|
console.error("Missing override: " + key);
|
|
|
|
ctx.raiseExceptionAndYield("java/lang/RuntimeException", key + " not found");
|
2014-09-24 10:50:23 +04:00
|
|
|
}
|
2014-09-24 11:32:43 +04:00
|
|
|
}
|
|
|
|
methodInfo.override.call(null, ctx, ctx.current().stack);
|
2014-09-24 10:50:23 +04:00
|
|
|
}
|
2014-09-24 12:10:39 +04:00
|
|
|
|
|
|
|
Override["com/ibm/oti/connection/file/Connection.decode.(Ljava/lang/String;)Ljava/lang/String;"] = function(ctx, stack) {
|
2014-09-24 23:55:17 +04:00
|
|
|
var string = util.fromJavaString(stack.pop());
|
|
|
|
stack.push(ctx.newString(decodeURIComponent(string)));
|
|
|
|
}
|
|
|
|
|
|
|
|
Override["com/ibm/oti/connection/file/Connection.encode.(Ljava/lang/String;)Ljava/lang/String;"] = function(ctx, stack) {
|
|
|
|
var string = util.fromJavaString(stack.pop());
|
2014-09-25 04:44:06 +04:00
|
|
|
stack.push(ctx.newString(string.replace(/[^a-zA-Z0-9-_\.!~\*\\'()/:]/g, encodeURIComponent)));
|
2014-09-24 12:10:39 +04:00
|
|
|
}
|
2014-09-25 23:14:32 +04:00
|
|
|
|
|
|
|
Override["java/lang/Math.min.(II)I"] = function(ctx, stack) {
|
|
|
|
var b = stack.pop(), a = stack.pop();
|
|
|
|
stack.push(a <= b ? a : b);
|
|
|
|
}
|
2014-09-26 04:06:43 +04:00
|
|
|
|
2014-09-26 05:14:38 +04:00
|
|
|
Override["java/io/ByteArrayInputStream.<init>.([B)V"] = function(ctx, stack) {
|
|
|
|
var buf = stack.pop(), _this = stack.pop();
|
|
|
|
|
|
|
|
if (!buf) {
|
|
|
|
ctx.raiseExceptionAndYield("java/lang/NullPointerException");
|
|
|
|
}
|
|
|
|
|
|
|
|
_this.buf = buf;
|
|
|
|
_this.pos = _this.mark = 0;
|
|
|
|
_this.count = buf.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
Override["java/io/ByteArrayInputStream.<init>.([BII)V"] = function(ctx, stack) {
|
|
|
|
var length = stack.pop(), offset = stack.pop(), buf = stack.pop(), _this = stack.pop();
|
|
|
|
|
|
|
|
if (!buf) {
|
|
|
|
ctx.raiseExceptionAndYield("java/lang/NullPointerException");
|
|
|
|
}
|
|
|
|
|
|
|
|
_this.buf = buf;
|
|
|
|
_this.pos = _this.mark = offset;
|
|
|
|
_this.count = (offset + length <= buf.length) ? (offset + length) : buf.length;
|
|
|
|
}
|
|
|
|
|
2014-09-26 04:06:43 +04:00
|
|
|
Override["java/io/ByteArrayInputStream.read.()I"] = function(ctx, stack) {
|
|
|
|
var _this = stack.pop();
|
2014-09-26 05:14:38 +04:00
|
|
|
stack.push((_this.pos < _this.count) ? (_this.buf[_this.pos++] & 0xFF) : -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Override["java/io/ByteArrayInputStream.read.([BII)I"] = function(ctx, stack) {
|
|
|
|
var len = stack.pop(), off = stack.pop(), b = stack.pop(), _this = stack.pop();
|
|
|
|
|
|
|
|
if (!b) {
|
|
|
|
ctx.raiseExceptionAndYield("java/lang/NullPointerException");
|
|
|
|
} else if ((off < 0) || (off > b.length) || (len < 0) ||
|
|
|
|
((off + len) > b.length) || ((off + len) < 0)) {
|
|
|
|
ctx.raiseExceptionAndYield("java/lang/IndexOutOfBoundsException");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_this.pos >= _this.count) {
|
|
|
|
stack.push(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_this.pos + len > _this.count) {
|
|
|
|
len = _this.count - _this.pos;
|
|
|
|
}
|
|
|
|
if (len <= 0) {
|
|
|
|
stack.push(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
b.set(_this.buf.subarray(_this.pos, _this.pos + len), off);
|
|
|
|
|
|
|
|
_this.pos += len;
|
|
|
|
stack.push(len);
|
|
|
|
}
|
|
|
|
|
|
|
|
Override["java/io/ByteArrayInputStream.skip.(J)J"] = function(ctx, stack) {
|
|
|
|
var nLong = stack.pop2(), _this = stack.pop();
|
2014-09-26 04:06:43 +04:00
|
|
|
|
2014-09-26 05:14:38 +04:00
|
|
|
var n = nLong.toNumber();
|
2014-09-26 04:06:43 +04:00
|
|
|
|
2014-09-26 05:14:38 +04:00
|
|
|
if (_this.pos + n > _this.count) {
|
|
|
|
n = _this.count - _this.pos;
|
2014-09-26 04:06:43 +04:00
|
|
|
}
|
2014-09-26 05:14:38 +04:00
|
|
|
|
|
|
|
if (n < 0) {
|
|
|
|
stack.push2(Long.fromNumber(0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_this.pos += n;
|
|
|
|
|
|
|
|
stack.push2(nLong);
|
|
|
|
}
|
|
|
|
|
|
|
|
Override["java/io/ByteArrayInputStream.available.()I"] = function(ctx, stack) {
|
|
|
|
var _this = stack.pop();
|
|
|
|
stack.push(_this.count - _this.pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
Override["java/io/ByteArrayInputStream.mark.(I)V"] = function(ctx, stack) {
|
|
|
|
var readAheadLimit = stack.pop(), _this = stack.pop();
|
|
|
|
_this.mark = _this.pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
Override["java/io/ByteArrayInputStream.reset.()V"] = function(ctx, stack) {
|
|
|
|
var _this = stack.pop();
|
|
|
|
_this.pos = _this.mark;
|
2014-09-26 04:06:43 +04:00
|
|
|
}
|