/* * $Workfile: HelloWorld.java $ $Revision: 1 $, $Date: 2/10/98 3:43p $ * * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved. * * This software is the confidential and proprietary information of Sun * Microsystems, Inc. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Sun. * * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING * THIS SOFTWARE OR ITS DERIVATIVES. */ // /* // $Workfile: HelloWorld.java $ // $Revision: 1 $ // $Date: 2/10/98 3:43p $ // $Author: Vadim $ // $Archive: /Releases/L 980212 JC20-DR2-P/Input/Sample-Code/src/HelloWorld/HelloWorld.java $ // $Modtime: 12/19/97 2:54p $ // Original author: Mitch Butler // */ package applets.HelloWorld; import javacard.framework.*; /** */ public class HelloWorld extends Applet { private byte[] echoBytes; private static final short LENGTH_ECHO_BYTES = 256; /** * Only this class's install method should create the applet object. * @see APDU * @param apdu the incoming APDU containing the INSTALL command. */ protected HelloWorld(APDU apdu) { register(); echoBytes = new byte[LENGTH_ECHO_BYTES]; } /** * Installs this applet. * @see APDU * @param apdu the incoming APDU containing the INSTALL command. * @exception ISOException with the response bytes per ISO 7816-4 */ public static void install(APDU apdu) { new HelloWorld(apdu); } /** * Processes an incoming APDU. * @see APDU * @param apdu the incoming APDU * @exception ISOException with the response bytes per ISO 7816-4 */ public void process(APDU apdu) { byte buffer[] = apdu.getBuffer(); short bytesRead = apdu.setIncomingAndReceive(); short echoOffset = (short)0; while ( bytesRead > 0 ) { Util.arrayCopyNonAtomic(buffer, ISO.OFFSET_CDATA, echoBytes, echoOffset, bytesRead); echoOffset += bytesRead; bytesRead = apdu.receiveBytes(ISO.OFFSET_CDATA); } apdu.setOutgoing(); apdu.setOutgoingLength( (short) (echoOffset + 5) ); // echo header apdu.sendBytes( (short)0, (short) 5); // echo data apdu.sendBytesLong( echoBytes, (short) 0, echoOffset ); } }