用 APDU & Boolean 重写函数

问题描述

我需要帮助

如果 while 被执行或没有,我需要这个函数返回一个布尔值。

你能帮我吗?


 public static void receiveIncomingFNEL(APDU apdu) {
        
      byte[] srcBuffer = apdu.getBuffer();
      short readCount = apdu.setIncomingAndReceive();
      short bytesLeft = (short) (srcBuffer[ISO7816.OFFSET_LC] & 0x00FF);
      while ( bytesLeft > 0){
            bytesLeft -= readCount;
            readCount = apdu.receiveBytes(ISO7816.OFFSET_CDATA); // read more APDU data
      }
      
      bufferProp[BUF_LEN_OFFSET] = Util.makeShort(srcBuffer[ISO7816.OFFSET_CDATA],srcBuffer[ISO7816.OFFSET_CDATA + 1]);
      bufferProp[BUF_START_OFFSET] = repository.allocReclaimableMemory(bufferProp[BUF_LEN_OFFSET]);
      Util.arraycopyNonAtomic(srcBuffer,(short)(ISO7816.OFFSET_CDATA + 2),(byte[]) bufferRef[0],(short)bufferProp[BUF_START_OFFSET],(short)bufferProp[BUF_LEN_OFFSET]);
  }

解决方法

让我们重写 API 中的 APDU 示例,因为它显然已损坏。不需要时,它会向 receiveBytes 生成单独的请求。

public boolean receiveIncomingFNEL(APDU apdu) {
    byte[] buf = apdu.getBuffer();

    short bytesRead = apdu.setIncomingAndReceive();
    // NOTE: we must always call setIncomingAndReceive() first
    short offsetCdata = apdu.getOffsetCdata();
    short bytesLeft = apdu.getIncomingLength() - bytesRead;
    boolean receiveBytesRequired = true;
    while (true) {
        // --- do something with the bytes in buf,offsetCdata and bytesRead here
        if (bytesLeft <= 0) {
             receiveBytesRequired = false;
             break;
        }
        bytesRead = apdu.receiveBytes(offsetCdata);
        bytesLeft -= bytesRead;
    }
    // --- do other stuff
    return receiveBytesRequired;
}

if 循环中的 breakwhile() 语句有点奇怪,但这是我能想到的唯一方法,让一个地方处理 APDU 缓冲区中的数据以及调用 receiveBytes() 的部分。这是因为 setIncomingAndReceive() 在调用中包含一个 receiveBytes()(创建正常 while 循环欢迎的想法)。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...