I can’t write data at index above 128 in byte array.
code is given below.
private void Write1(APDU apdu) throws ISOException
{
apdu.setIncomingAndReceive();
byte[] apduBuffer = apdu.getBuffer();
byte j = (byte)apduBuffer[4]; // Return incoming bytes lets take 160
Buffer1 = new byte[j]; // initialize a array with size 160
for (byte i=0; i<j; i++)
Buffer1[(byte)i] = (byte)apduBuffer[5+i];
}
It gives me error 6F 00 (It means reach End Of file).
I am using:
- smart card type = contact card
- using java card 2.2.2 with jcop using apdu
Your code contains several problems:
As already pointed out by ‘pst’ you are using a signed
bytevalue which works only up to 128 – use ashortinsteadYour are creating a new buffer
Buffer1on every call of yourWrite1method. On JavaCard there is usually no automatic garbage collection – therefore memory allocation should only be done once when the app is installed. If you only want to process the data in the adpu buffer just use it from there. And if you want to copy data from one byte array into another better usejavacard.framework.Util.arrayCopy(..).You are calling
apdu.setIncomingAndReceive();but ignore the return value. The return value gives you the number of bytes of data you can read.The following code is from the API docs and shows the common way: