Lendo arquivo grande de um applet javacard
Eu estou escrevendo um applet que armazena 3 arquivos de diferentes tamanhos 5 Kb, 7 Kb e 11 Kb. Não tenho problemas em armazenar os arquivos dentro do applet. Mas quando tento lê-los de volta, só consigo ler os dois primeiros (arquivos menores). O terceiro arquivo lança uma exceção:
javax.smartcardio.CardException: Could not obtain response
at sun.security.smartcardio.ChannelImpl.doTransmit(Unknown Source)
at sun.security.smartcardio.ChannelImpl.transmit(Unknown Source)
Eu tentei descobrir o problema e descobri que tem a ver com o tamanho do arquivo. Então eu criei um arquivo de teste de tamanho 7 Kb e incrementei esse arquivo pouco a pouco. Funcionou até eu atingir 7905 bytes. Isso significa que 7905 bytes é o número máximo de bytes que posso ler no applet. Eu estou encadeando a resposta usando código de amostra:
public void readFile(APDU apdu, short[] offset, short selectedFile, short MAX_APDU_SEN, byte OFFSET_SENT) {
byte[] file = getFile(selectedFile);
if (file == null) {
+ ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);+
}
// work out how many bytes to send this time and how many will be left
short remain = (short) (file.length - offset[OFFSET_SENT]);
boolean chain = remain > MAX_APDU_SEN;
short sendLen = chain ? MAX_APDU_SEN : remain;
apdu.setOutgoing();
apdu.setOutgoingLength(sendLen);
apdu.sendBytesLong(file, offset[OFFSET_SENT], sendLen);
// Check to see if there are more APDU's to send
if (chain) {
+offset[OFFSET_SENT] = sendLen; // count the bytes sent
ISOException.throwIt(ISO7816.SW_BYTES_REMAINING_00); // indicate there are more bytes to come
} else {+
offset[OFFSET_SENT] = 0; // no more bytes to send
}
}
Eu tentei dois tipos diferentes de cartões, ou seja, cartões compatíveis JC 2.2.1 (36Kb) e JC 2.2.2 (80Kb), mas todos eles se comportam da mesma forma.
Alguma ajuda por favor?