PCSC4Java
0.2
Library PCSC for Java language.
|
00001 /* 00002 * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. 00003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 00004 * 00005 * This code is free software; you can redistribute it and/or modify it 00006 * under the terms of the GNU General Public License version 2 only, as 00007 * published by the Free Software Foundation. Oracle designates this 00008 * particular file as subject to the "Classpath" exception as provided 00009 * by Oracle in the LICENSE file that accompanied this code. 00010 * 00011 * This code is distributed in the hope that it will be useful, but WITHOUT 00012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00014 * version 2 for more details (a copy is included in the LICENSE file that 00015 * accompanied this code). 00016 * 00017 * You should have received a copy of the GNU General Public License version 00018 * 2 along with this work; if not, write to the Free Software Foundation, 00019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 00020 * 00021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 00022 * or visit www.oracle.com if you need additional information or have any 00023 * questions. 00024 */ 00025 00026 package fr.redbilled.pcscforjava; 00027 00028 import java.util.Arrays; 00029 00046 public final class ResponseAPDU implements java.io.Serializable { 00047 00048 private static final long serialVersionUID = 6962744978375594225L; 00049 00051 private byte[] apdu; 00052 00065 public ResponseAPDU(byte[] apdu) { 00066 apdu = apdu.clone(); 00067 check(apdu); 00068 this.apdu = apdu; 00069 } 00070 00071 private static void check(byte[] apdu) { 00072 if (apdu.length < 2) { 00073 throw new IllegalArgumentException("apdu must be at least 2 bytes long"); 00074 } 00075 } 00076 00085 public int getNr() { 00086 return apdu.length - 2; 00087 } 00088 00096 public byte[] getData() { 00097 byte[] data = new byte[apdu.length - 2]; 00098 System.arraycopy(apdu, 0, data, 0, data.length); 00099 return data; 00100 } 00101 00107 public int getSW1() { 00108 return apdu[apdu.length - 2] & 0xff; 00109 } 00110 00116 public int getSW2() { 00117 return apdu[apdu.length - 1] & 0xff; 00118 } 00119 00128 public int getSW() { 00129 return (getSW1() << 8) | getSW2(); 00130 } 00131 00137 public byte[] getBytes() { 00138 return apdu.clone(); 00139 } 00140 00146 public String toString() { 00147 return "ResponseAPDU: " + apdu.length + " bytes, SW=" 00148 + Integer.toHexString(getSW()); 00149 } 00150 00159 public boolean equals(Object obj) { 00160 if (this == obj) { 00161 return true; 00162 } 00163 if (obj instanceof ResponseAPDU == false) { 00164 return false; 00165 } 00166 ResponseAPDU other = (ResponseAPDU)obj; 00167 return Arrays.equals(this.apdu, other.apdu); 00168 } 00169 00175 public int hashCode() { 00176 return Arrays.hashCode(apdu); 00177 } 00178 00179 private void readObject(java.io.ObjectInputStream in) 00180 throws java.io.IOException, ClassNotFoundException { 00181 apdu = (byte[])in.readUnshared(); 00182 check(apdu); 00183 } 00184 00185 }