}
@Override
public void writeBlock(MfAccess mfAccess, MfBlock... mfBlock) throws IOException {
AcsConnectionToken connectionToken = retrieveConnectionToken(mfAccess);
CardChannel cardChannel = connectionToken.getCard().getBasicChannel();
loginIntoSector(mfAccess, cardChannel);
for (int currentBlock = 0; currentBlock < mfBlock.length; currentBlock++) {
int blockNumber = mfAccess.getCard().getBlockNumber(mfAccess.getSector(), mfAccess.getBlock())
+ currentBlock;
if (mfAccess.getCard().isTrailerBlock(mfAccess.getSector(), mfAccess.getBlock() + currentBlock)) {
if (!(mfBlock[currentBlock] instanceof TrailerBlock))
throw new MfException("invalid block for trailer");
}
CommandAPDU writeBlock = new CommandAPDU(Apdu.CLS_PTS, Apdu.INS_UPDATE_BINARY, 0x00, blockNumber,
mfBlock[currentBlock].getData());
ResponseAPDU writeBlockResponse;
try {
writeBlockResponse = cardChannel.transmit(writeBlock);
if (!ApduUtils.isSuccess(writeBlockResponse)) {
throw new MfException("Writing block failed. Sector: " + mfAccess.getSector() + ", Block: "
+ mfAccess.getBlock() + " Key: " + mfAccess.getKey().name() + ", Response: "
+ writeBlockResponse);
}