Leyendo archivo grande desde un applet javacard
Estoy escribiendo un applet que almacena 3 archivos de diferentes tamaños 5 Kb, 7 Kb y 11 Kb. No tengo problemas con almacenar los archivos dentro del applet. Pero cuando intento leerlos de nuevo, solo puedo leer los dos primeros (archivos más pequeños). El tercer archivo lanza una excepción:
javax.smartcardio.CardException: Could not obtain response
at sun.security.smartcardio.ChannelImpl.doTransmit(Unknown Source)
at sun.security.smartcardio.ChannelImpl.transmit(Unknown Source)
He intentado resolver el problema y he descubierto que tiene que ver con el tamaño del archivo. Así que creé un archivo de prueba de tamaño 7 Kb e incrementé este archivo poco a poco. Funcionó hasta que llegué a 7905 bytes. Significa que 7905 bytes es el número máximo de bytes que puedo leer desde el applet. Estoy encadenando la respuesta usando código de ejemplo:
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
}
}
He probado dos tipos diferentes de tarjetas, es decir, tarjetas compatibles con JC 2.2.1 (36Kb) y JC 2.2.2 (80Kb), pero todas se comportan igual.
¿Alguna ayuda por favor?