/************************************************************************************/ //原子性 /* Util.arrayCopy方法保證要么所有的字節(jié)被正確地拷貝,要么目標數(shù)組被恢復為其原來的字節(jié)值。 如果該目標數(shù)組是臨時的,就不具有原子特性。 */ public static short arrayCopy(byte[] src,short srcOff,byte[] dest,short desOff,short length);
//方法arrayCopyNonAtomic在拷貝操作過程中不使用事務設(shè)施,即使一個事務正在執(zhí)行之中。 public static short arrayCopyNonAtomic(byte[] src,short srcOff,byte[] dest,short desOff,short length);
//用指定的值填入一個字節(jié)數(shù)組的諸元素: public static short arrayFillNonAtomic(byte[] bArray,short bOff,short bLen,byte bValue);
//該方法由applet用來向JCRE注冊本applet實例并指定CAP文件中的缺省AID給本applet實例 Protected final void Register()
//該方法由applet用來向JCRE注冊本applet實例并將數(shù)組bArray中指出的AID賦予該applet實例。 Protected final void Register(byte[] bArray,short bOffset,byte bLength)
/************************************************************************************/ //JCRE調(diào)用這個方法通知該applet它已經(jīng)被選擇。 Public boolean Select()
//JCRE調(diào)用這個方法指示該applet處理一個輸入的APDU命令。 Public abstract void Process(APDU apdu)
//JCRE調(diào)用這個方法通知當前選擇的applet另一個(或同一個)applet將被選擇。 Public void deselect()
//檢查是否還有剩余數(shù)據(jù),如果無,跳出循環(huán)。 If (bytes_left <=0) break; //如果有剩余數(shù)據(jù),在讀數(shù)據(jù)。 Read_count = apdu.receiveBytes((short)0);
Bytes_left -= read_count;
} //執(zhí)行其它任務和向host送回響應 …… }
//重新設(shè)置數(shù)據(jù)傳送方向為輸出,置JCRE為數(shù)據(jù)發(fā)送模式.剩余的輸入數(shù)據(jù)將被丟棄,并且applet就不能再繼續(xù)接收命令數(shù)據(jù) Public short setOutgoing() throws APDUException;
//調(diào)用了setOutgoing方法之后,applet必須調(diào)用setOutgoingLength方法,以向host指出它將實際發(fā)送總共多少響應數(shù)據(jù)字節(jié)(不包括SW) public void setOutgoingLength(short length) throws APDUException;
//sendBytes方法從APDU Buffer中指定位移bOff處發(fā)送len個數(shù)據(jù)字節(jié).因此,applet在調(diào)用這個方法之前,必須在APDU Buffer中生成響應數(shù)據(jù)或從別處拷貝過來。 public void sendBytes(short bOff,short len) throws APDUException;
//示例 public void process(APDU apdu){ //接收和處理命令APDU …… //現(xiàn)在準備好發(fā)送響應數(shù)據(jù) //首先設(shè)置JCRE為數(shù)據(jù)發(fā)送模式并獲得期望的行應數(shù)據(jù)長度(Le) short le = apdu.setOutgoing(); //接著通知host:applet將實際發(fā)送10個字節(jié) apdu.setOugoingLength((short)10); //在APDU Buffer中準備數(shù)據(jù),從位移0開始 …… //準備結(jié)束時,發(fā)送數(shù)據(jù) apdu.sendBytes((short)0,(short)10); }
//設(shè)置傳輸模式為發(fā)送,設(shè)置響應數(shù)據(jù)長度為len,從APDU Buffer 位移bOff起發(fā)送響應數(shù)據(jù)字節(jié) public void setOutgoingAndSend(short bOff,short len) throws APDUException;
//sendBytesLong方法從字節(jié)數(shù)組outDATA中的位移bOff開始處發(fā)送len字節(jié)數(shù)據(jù).僅當已經(jīng)先調(diào)用了setOutgoing和setOutgoingLength方法之后,它才能被調(diào)用。 public void sendBytesLong(byte[] outDATA,short bOff,short len) throws APDUException;