I have some reference code which is written in Javascript and I am trying to port it to Java.
The problem I have with the porting is that I don't have anything in Java which can be used as stack and normal array at the same time. The reference code uses an array object which can act as a normal array and also like a stack.
Is there anything which I can use to resolve my problem?
Reference Code:
var ascii85 = function (input) {
// input: Array: an array of numbers (0-255) to encode
var result = [],
reminder = input.length % 4,
length = input.length - reminder;
c(input, length, result);
if (reminder) {
var t = input.slice(length);
while (t.length < 4) {
t.push(0);
}
c(t, 4, result);
var x = result.pop();
if (x == "z") {
x = "!!!!!";
}
result.push(x.substr(0, reminder + 1));
}
return result.join("");
};
The code of c function is below:
var c = function (input, length, result) {
var i, j, n, b = [0, 0, 0, 0, 0];
for (i = 0; i < length; i += 4) {
n = ((input[i] * 256 + input[i + 1]) * 256 + input[i + 2])
* 256 + input[i + 3];
if (!n) {
result.push("z");
} else {
for (j = 0; j < 5;
b[j++] = n % 85 + 33, n = Math.floor(n / 85)
);
}
result.push(String.fromCharCode(
b[4], b[3], b[2], b[1], b[0]));
}
};
list.get(n).