I'm trying to convert the following JS to Java:
serializeSig:function(r,s){
var rBa=r.toByteArraySigned();
var sBa=s.toByteArraySigned();
var sequence=[];
sequence.push(2);
sequence.push(rBa.length);
sequence=sequence.concat(rBa);
sequence.push(2);
sequence.push(sBa.length);
sequence=sequence.concat(sBa);
sequence.unshift(sequence.length);
sequence.unshift(48);
return sequence
}
I think push would translate to add, concat to some kind of addAll, but what is unshift? And of what type would my variables in java be?
myArray.unshift(obj) corresponds to myList.add(0, obj).
A byte array in Java is byte[]. A list of byte arrays would be a List<byte[]>. (That's java.util.List, not java.awt.List, just in case you get the wrong import.)
EDIT: Looks like you are trying to create a byte array, not a list of byte arrays. In that case, you should use a java.nio.ByteBuffer, or possibly a java.io.ByteArrayOutputStream. The latter has to be written to sequentially -- you cannot do the equivalent of an unshift.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With