本文整理汇总了Java中javax.smartcardio.CardTerminal.isCardPresent方法的典型用法代码示例。如果您正苦于以下问题:Java CardTerminal.isCardPresent方法的具体用法?Java CardTerminal.isCardPresent怎么用?Java CardTerminal.isCardPresent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.smartcardio.CardTerminal
的用法示例。
在下文中一共展示了CardTerminal.isCardPresent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connect
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
/**
* Establishes a connection with a card. The first reader found is used.
*
* @return <code>true</code> on success
*/
public boolean connect(int termNb) {
CardTerminals cardTerminals = TerminalFactory.getDefault().terminals();
try {
CardTerminal terminal = cardTerminals.list().get(termNb);
if (!terminal.isCardPresent()) {
System.out.println("No smart card present on the terminal.");
return false;
}
card = terminal.connect("*");
channel = card.getBasicChannel();
System.out.println(channel.getCard().toString());
} catch (CardException e) {
e.printStackTrace();
System.out.println("Is reader connected?");
return false;
}
return true;
}
示例2: connect
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
/**
* Establish connection to terminal and card on terminal.
*
* @param index
* Number of the terminal to use
* @return connect Connection successfull ?
* @throws CardException
*/
public boolean connect(int index) throws CardException {
/* Is a Reader connected we can access? */
if (TerminalFactory.getDefault().terminals().list().size() == 0) {
logger.error("No reader available");
throw new CardException("No reader available");
}
/* Terminal we are working on */
CardTerminal terminal = TerminalFactory.getDefault().terminals().list().get(index);
/* Is a card present? */
if (!terminal.isCardPresent()) {
logger.error("No card available");
throw new CardException("No card available");
}
card = terminal.connect("T=1");
channel = card.getBasicChannel();
connected = true;
return connected;
}
示例3: terminalsWithCardsIn
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
private Set<CardTerminal> terminalsWithCardsIn(
final Set<CardTerminal> terminals) {
final Set<CardTerminal> terminalsWithCards = new HashSet<CardTerminal>();
synchronized (this.terminalsToIgnoreCardEventsFor) {
for (CardTerminal terminal : terminals) {
try {
if (terminal.isCardPresent()
&& !this.areCardEventsIgnoredFor(terminal)) {
terminalsWithCards.add(terminal);
}
} catch (final CardException cex) {
this.logger
.error("Problem determining card presence in terminal ["
+ terminal.getName() + "]", cex);
}
}
}
return terminalsWithCards;
}
示例4: getTerminal
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
static CardTerminal getTerminal(String[] args) throws Exception {
setLibrary(args);
TerminalFactory factory = TerminalFactory.getInstance("PC/SC", null);
System.out.println(factory);
List<CardTerminal> terminals = factory.terminals().list();
System.out.println("Terminals: " + terminals);
if (terminals.isEmpty()) {
throw new Exception("No card terminals available");
}
CardTerminal terminal = terminals.get(0);
if (terminal.isCardPresent() == false) {
System.out.println("*** Insert card");
if (terminal.waitForCardPresent(20 * 1000) == false) {
throw new Exception("no card available");
}
}
return terminal;
}
示例5: create
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
public static SmartcardIoTransmitter create() throws CardException {
TerminalFactory tf = TerminalFactory.getDefault();
CardTerminal cardTerminal = null;
if (tf.terminals().list().size() == 1) {
cardTerminal = tf.terminals().list().get(0);
} else {
for (CardTerminal terminal : tf.terminals().list()) {
logger.info("Checking for card: {}", terminal.getName());
if (terminal.isCardPresent()) {
cardTerminal = terminal;
}
}
}
if (cardTerminal != null) {
cardTerminal.waitForCardPresent(0);
} else {
throw new RuntimeException("No card found!");
}
logger.info("Using -> " + cardTerminal.getName());
Card card = cardTerminal.connect("*");
return new SmartcardIoTransmitter(card);
}
示例6: getConnectedCardATR
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
public static ArrayList<String> getConnectedCardATR(){
ArrayList<String> ret = new ArrayList<String>();
try{
List<CardTerminal> terminalList = TerminalFactory.getDefault().terminals().list();
for(CardTerminal terminal:terminalList)
if(terminal.isCardPresent()){
javax.smartcardio.Card card = terminal.connect("*");
ret.add(StringUtils.toHexString(card.getATR().getBytes()));
card.disconnect(false);
}
}catch(Exception ex){}
return ret;
}
示例7: getTerminal
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
static CardTerminal getTerminal(String[] args, String provider) throws Exception {
setLibrary(args);
try {
TerminalFactory factory = (provider == null)
? TerminalFactory.getInstance("PC/SC", null)
: TerminalFactory.getInstance("PC/SC", null, provider);
System.out.println(factory);
List<CardTerminal> terminals = factory.terminals().list();
System.out.println("Terminals: " + terminals);
if (terminals.isEmpty()) {
return null;
}
CardTerminal terminal = terminals.get(0);
if (terminal.isCardPresent() == false) {
System.out.println("*** Insert card");
if (terminal.waitForCardPresent(20 * 1000) == false) {
throw new Exception("no card available");
}
}
System.out.println("card present: " + terminal.isCardPresent());
return terminal;
} catch (NoSuchAlgorithmException e) {
Throwable cause = e.getCause();
if (cause != null && cause.getMessage().startsWith("PC/SC not available")) {
return null;
}
throw e;
}
}
示例8: connectToAllCardsByTerminalFactory
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
private static void connectToAllCardsByTerminalFactory(TerminalFactory factory, byte[] appAID, ArrayList<CardChannel> cardsList) throws CardException {
ArrayList<CardTerminal> terminals = new ArrayList<>();
Card card = null;
try {
for (CardTerminal t : factory.terminals().list()) {
terminals.add(t);
if (t.isCardPresent()) {
System.out.print("Connecting...");
card = t.connect("*"); // Connect with the card
System.out.println(" Done.");
System.out.print("Establishing channel...");
CardChannel channel = card.getBasicChannel();
System.out.println(" Done.");
// Select applet (mpcapplet)
System.out.println("Smartcard: Selecting applet...");
CommandAPDU cmd = new CommandAPDU(appAID);
ResponseAPDU response = transmit(channel, cmd);
if (response.getSW() == (ISO7816.SW_NO_ERROR & 0xffff)) {
cardsList.add(channel);
}
}
}
} catch (Exception e) {
System.out.println("Failed.");
}
System.out.println("MPC cards found: " + cardsList.size());
}
示例9: getSlot
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
private int getSlot() throws Exception {
// "Fabrica" de Terminais PC/SC
TerminalFactory factory;
// Lista de Leitores PC/SC
List terminals;
// Adquire Fabrica de Leitores
factory = TerminalFactory.getDefault();
// Adquire Lista de Leitores PC/SC no Sistema
terminals = factory.terminals().list();
// Logger.print(false, "Lista : " + terminals);
int i = 0;
for (Object next : terminals) {
CardTerminal t = (CardTerminal) next;
// System.out.print(t.getName());
// System.out.println(t.isCardPresent() ? " COM" : " sem");
if (t.isCardPresent()) {
break;
// card = t.connect("*");
// CardChannel channel = card.getBasicChannel();
//
// int cn = channel.getChannelNumber();
// System.out.println("getChannelNumber(): "+cn);
// System.out.println("Protocol: "+card.getProtocol());
}
i++;
}
return i;
}
示例10: getSlot
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
public int getSlot() throws Exception {
// "Fabrica" de Terminais PC/SC
TerminalFactory factory;
// Lista de Leitores PC/SC
List terminals;
// Adquire Fabrica de Leitores
factory = TerminalFactory.getDefault();
// Adquire Lista de Leitores PC/SC no Sistema
terminals = factory.terminals().list();
// Logger.print(false, "Lista : " + terminals);
int i = 0;
for (Object next : terminals) {
CardTerminal t = (CardTerminal) next;
// System.out.print(t.getName());
// System.out.println(t.isCardPresent() ? " COM" : " sem");
if (t.isCardPresent()) {
break;
// card = t.connect("*");
// CardChannel channel = card.getBasicChannel();
//
// int cn = channel.getChannelNumber();
// System.out.println("getChannelNumber(): "+cn);
// System.out.println("Protocol: "+card.getProtocol());
}
i++;
}
return i;
}
示例11: testList
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
@Test
public void testList() throws CardException {
List<CardTerminal> terminalList = terminals.list();
assertEquals(1, terminalList.size());
CardTerminal terminal = terminalList.get(0);
String name = terminal.getName();
assertTrue(0 != name.length());
boolean isCardPresent = terminal.isCardPresent();
assertTrue(isCardPresent);
}
示例12: connectToCardByTerminalFactory
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
private CardChannel connectToCardByTerminalFactory(TerminalFactory factory, int targetReaderIndex) throws CardException {
List<CardTerminal> terminals = new ArrayList<>();
boolean card_found = false;
CardTerminal terminal = null;
Card card = null;
try {
for (CardTerminal t : factory.terminals().list()) {
terminals.add(t);
if (t.isCardPresent()) {
card_found = true;
}
}
System.out.println("Success.");
} catch (Exception e) {
System.out.println("Failed.");
}
if (card_found) {
System.out.println("Cards found: " + terminals);
terminal = terminals.get(targetReaderIndex); // Prioritize physical card over simulations
System.out.print("Connecting...");
card = terminal.connect("*"); // Connect with the card
System.out.println(" Done.");
System.out.print("Establishing channel...");
m_channel = card.getBasicChannel();
System.out.println(" Done.");
// Select applet (mpcapplet)
System.out.println("Smartcard: Selecting applet...");
CommandAPDU cmd = new CommandAPDU(0x00, 0xa4, 0x04, 0x00, m_APPLET_AID);
ResponseAPDU response = transmit(cmd);
} else {
System.out.print("Failed to find physical card.");
}
if (card != null) {
return card.getBasicChannel();
} else {
return null;
}
}
示例13: connectToCardByTerminalFactory
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
private CardChannel connectToCardByTerminalFactory(TerminalFactory factory, int targetReaderIndex) throws CardException {
List<CardTerminal> terminals = new ArrayList<>();
boolean card_found = false;
CardTerminal terminal = null;
Card card = null;
try {
for (CardTerminal t : factory.terminals().list()) {
terminals.add(t);
if (t.isCardPresent()) {
card_found = true;
}
}
} catch (Exception ignored) {
}
if (card_found) {
System.out.println("Cards found: " + terminals);
terminal = terminals.get(targetReaderIndex);
System.out.print("Connecting...");
card = terminal.connect("*");
System.out.println(" done.");
System.out.print("Establishing channel...");
m_channel = card.getBasicChannel();
System.out.println(" done.");
System.out.print("Selecting applet...");
CommandAPDU cmd = new CommandAPDU(0x00, 0xa4, 0x04, 0x00, m_APPLET_AID);
ResponseAPDU response = transmit(cmd);
if (response.getSW() == (ISO7816.SW_NO_ERROR & 0xffff)) {
System.out.print(" done");
}
else {
System.out.print(" failed.");
}
} else {
System.out.print("Failed to find required card.");
}
if (card != null) {
return card.getBasicChannel();
} else {
return null;
}
}
示例14: main
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
CardTerminal terminal = getTerminal(args);
if (terminal == null) {
System.out.println("Skipping the test: " +
"no card terminals available");
return;
}
while (terminal.isCardPresent()) {
System.out.println("*** Remove card!");
Thread.sleep(1000);
}
Timer timer = new Timer();
System.out.println("Testing waitForCardAbsent() with card already absent...");
isTrue(terminal.waitForCardAbsent(10));
timer.print();
isTrue(terminal.waitForCardAbsent(100));
timer.print();
isTrue(terminal.waitForCardAbsent(10000));
timer.print();
isTrue(terminal.waitForCardAbsent(0));
timer.print();
System.out.println("Testing waitForCardPresent() timeout...");
isFalse(terminal.waitForCardPresent(10));
timer.print();
isFalse(terminal.waitForCardPresent(100));
timer.print();
isFalse(terminal.waitForCardPresent(1000));
timer.print();
isFalse(terminal.isCardPresent());
isFalse(terminal.isCardPresent());
System.out.println("*** Insert card!");
isTrue(terminal.waitForCardPresent(0));
timer.print();
isTrue(terminal.isCardPresent());
isTrue(terminal.isCardPresent());
System.out.println("Testing waitForCardPresent() with card already present...");
isTrue(terminal.waitForCardPresent(0));
timer.print();
isTrue(terminal.waitForCardPresent(10000));
timer.print();
isTrue(terminal.waitForCardPresent(100));
timer.print();
isTrue(terminal.waitForCardPresent(10));
timer.print();
System.out.println("Testing waitForCardAbsent() timeout...");
isFalse(terminal.waitForCardAbsent(1000));
timer.print();
isFalse(terminal.waitForCardAbsent(100));
timer.print();
isFalse(terminal.waitForCardAbsent(10));
timer.print();
System.out.println("*** Remove card!");
isTrue(terminal.waitForCardAbsent(0));
timer.print();
isFalse(terminal.isCardPresent());
isFalse(terminal.isCardPresent());
System.out.println("OK.");
}
示例15: connectToCardByTerminalFactory
import javax.smartcardio.CardTerminal; //导入方法依赖的package包/类
private static CardChannel connectToCardByTerminalFactory(TerminalFactory factory, int targetReaderIndex, byte[] appAID) throws CardException {
ArrayList<CardTerminal> terminals = new ArrayList<>();
boolean card_found = false;
CardTerminal terminal = null;
Card card = null;
try {
for (CardTerminal t : factory.terminals().list()) {
terminals.add(t);
if (t.isCardPresent()) {
card_found = true;
}
}
System.out.println("Success.");
} catch (Exception e) {
System.out.println("Failed.");
}
if (card_found) {
System.out.println("Cards found: " + terminals);
terminal = terminals.get(targetReaderIndex); // Prioritize physical card over simulations
System.out.print("Connecting...");
card = terminal.connect("*"); // Connect with the card
System.out.println(" Done.");
System.out.print("Establishing channel...");
CardChannel channel = card.getBasicChannel();
System.out.println(" Done.");
// Select applet (mpcapplet)
System.out.println("Smartcard: Selecting applet...");
CommandAPDU cmd = new CommandAPDU(appAID);
ResponseAPDU response = transmit(channel, cmd);
} else {
System.out.print("Failed to find physical card.");
}
if (card != null) {
return card.getBasicChannel();
} else {
return null;
}
}