本文整理汇总了Java中javax.smartcardio.TerminalFactory.terminals方法的典型用法代码示例。如果您正苦于以下问题:Java TerminalFactory.terminals方法的具体用法?Java TerminalFactory.terminals怎么用?Java TerminalFactory.terminals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.smartcardio.TerminalFactory
的用法示例。
在下文中一共展示了TerminalFactory.terminals方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReadPhoto
import javax.smartcardio.TerminalFactory; //导入方法依赖的package包/类
@Test
public void testReadPhoto() throws Exception {
TerminalFactory terminalFactory = TerminalFactory.getDefault();
CardTerminals cardTerminals = terminalFactory.terminals();
CardTerminal cardTerminal = cardTerminals.list().get(0);
Card card = cardTerminal.connect("T=0");
CardChannel cardChannel = card.getBasicChannel();
// select file
cardChannel.transmit(
new CommandAPDU(0x00, 0xA4, 0x08, 0x0C, new byte[] { 0x3F, 0x00, (byte) 0xDF, 0x01, 0x40, 0x35 }));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int offset = 0;
ResponseAPDU responseApdu;
do {
// read binary
responseApdu = cardChannel.transmit(new CommandAPDU(0x00, 0xB0, offset >> 8, offset & 0xFF, 0xff));
baos.write(responseApdu.getData());
offset += responseApdu.getData().length;
} while (responseApdu.getData().length == 0xff);
BufferedImage photo = ImageIO.read(new ByteArrayInputStream(baos.toByteArray()));
JOptionPane.showMessageDialog(null, new ImageIcon(photo));
}
示例2: CardAndTerminalManager
import javax.smartcardio.TerminalFactory; //导入方法依赖的package包/类
/**
* Instantiate a CardAndTerminalManager working on a specific CardTerminals
* instance, and that logs to the given Logger.In normal operation, you
* would use the constructor that takes no CardTerminals parameter, but
* using this one you could, for example obtain a CardTerminals instance
* from a different TerminalFactory, or from your own implementation.
*
* @param logger
* an instance of be.fedict.commons.eid.spi.Logger that will be
* send all the logs
* @param cardTerminals
* instance to obtain terminal and card events from
*/
public CardAndTerminalManager(final Logger logger,
final CardTerminals cardTerminals) {
// work around implementation bug in some GNU/Linux JRE's that causes
// libpcsc not to be found.
LibJ2PCSCGNULinuxFix.fixNativeLibrary(logger);
this.cardTerminalEventsListeners = new HashSet<CardTerminalEventsListener>();
this.cardEventsListeners = new HashSet<CardEventsListener>();
this.terminalsToIgnoreCardEventsFor = new HashSet<String>();
this.delay = DEFAULT_DELAY;
this.logger = logger;
this.running = false;
this.subSystemInitialized = false;
this.autoconnect = true;
this.protocol = PROTOCOL.ANY;
if (cardTerminals == null) {
final TerminalFactory terminalFactory = TerminalFactory
.getDefault();
this.cardTerminals = terminalFactory.terminals();
} else {
this.cardTerminals = cardTerminals;
}
}
示例3: run
import javax.smartcardio.TerminalFactory; //导入方法依赖的package包/类
public void run() throws Exception {
Security.insertProviderAt(new SmartcardioProvider(), 1);
//
// use "getInstance" to provide more detailed access
// TerminalFactory factory = TerminalFactory.getInstance("PC/SC", null);
TerminalFactory factory = TerminalFactory.getDefault();
CardTerminals terminals = factory.terminals();
List<CardTerminal> list = terminals.list();
for (CardTerminal terminal : list) {
System.out.println("found " + terminal + " named "
+ terminal.getName());
}
}
示例4: run
import javax.smartcardio.TerminalFactory; //导入方法依赖的package包/类
public void run() throws Exception {
Security.insertProviderAt(new SmartcardioProvider(), 1);
//
TerminalFactory factory = TerminalFactory.getDefault();
CardTerminals terminals = factory.terminals();
while (System.in.available() == 0) {
List<CardTerminal> list = terminals.list(State.CARD_INSERTION);
if (list.isEmpty()) {
System.out.println("no terminals");
}
for (CardTerminal cardTerminal : list) {
try {
connect(cardTerminal);
} catch (Exception e) {
System.out.println("error connecting " + e);
}
}
System.out.println("wait for change");
if (terminals.waitForChange(1000)) {
System.out.println("change detected...");
} else {
System.out.println("timeout");
}
}
}
示例5: main
import javax.smartcardio.TerminalFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
TerminalFactory context;
CardTerminals terminals;
if (true) {
Security.addProvider(new Smartcardio());
context = TerminalFactory.getInstance("PC/SC", null, Smartcardio.PROVIDER_NAME);
terminals = context.terminals();
} else {
TerminalFactory terminalFactory = TerminalFactory.getDefault();
terminals = terminalFactory.terminals();
}
List<CardTerminal> present = terminals.list(State.CARD_PRESENT);
List<CardTerminal> absent = terminals.list(State.CARD_ABSENT);
System.out.format("Initial: cards are present in %s; cards are absent from %s%n", terminalNames(present), terminalNames(absent));
while (true) {
terminals.waitForChange();
List<CardTerminal> inserted = terminals.list(State.CARD_INSERTION);
List<CardTerminal> removed = terminals.list(State.CARD_REMOVAL);
System.out.format("Card inserted in %s; cards removed from %s%n", terminalNames(inserted), terminalNames(removed));
}
}
示例6: getReaderList
import javax.smartcardio.TerminalFactory; //导入方法依赖的package包/类
public List<String> getReaderList() {
List<String> readerList = new LinkedList<String>();
TerminalFactory factory = TerminalFactory.getDefault();
CardTerminals cardTerminals = factory.terminals();
List<CardTerminal> cardTerminalList;
try {
cardTerminalList = cardTerminals.list();
} catch (CardException e) {
/*
* Windows can give use a sun.security.smartcardio.PCSCException
* SCARD_E_NO_READERS_AVAILABLE here in case no card readers are
* connected to the system.
*/
this.view.addDetailMessage("error on card terminals list: " + e.getMessage());
this.view.addDetailMessage("no card readers connected?");
Throwable cause = e.getCause();
if (null != cause) {
this.view.addDetailMessage("cause: " + cause.getMessage());
this.view.addDetailMessage("cause type: " + cause.getClass().getName());
}
return readerList;
}
for (CardTerminal cardTerminal : cardTerminalList) {
readerList.add(cardTerminal.getName());
}
return readerList;
}
示例7: hasCardReader
import javax.smartcardio.TerminalFactory; //导入方法依赖的package包/类
public boolean hasCardReader() {
try {
TerminalFactory factory = TerminalFactory.getDefault();
CardTerminals cardTerminals = factory.terminals();
List<CardTerminal> terminalList = cardTerminals.list();
if (!terminalList.isEmpty()) {
cardTerminalList = terminalList;
return true;
}
return false;
} catch (CardException e) {
this.view.addDetailMessage("card terminals list error: " + e.getMessage());
return false;
}
}
示例8: logoff
import javax.smartcardio.TerminalFactory; //导入方法依赖的package包/类
public void logoff(String readerName) throws Exception {
this.view.addDetailMessage("logoff from reader: \"" + readerName + "\"");
TerminalFactory factory = TerminalFactory.getDefault();
CardTerminals cardTerminals = factory.terminals();
CardTerminal cardTerminal = cardTerminals.getTerminal(readerName);
if (null == cardTerminal) {
this.view.addDetailMessage("logoff: card reader not found: " + readerName);
List<String> readerList = getReaderList();
this.view.addDetailMessage("reader list: " + readerList);
// throw new RuntimeException("card reader not found: " +
// readerName);
// we won't fail in this case...
return;
}
Card card = cardTerminal.connect("T=0");
try {
CardChannel cardChannel = card.getBasicChannel();
CommandAPDU logoffApdu = new CommandAPDU(0x80, 0xE6, 0x00, 0x00);
ResponseAPDU responseApdu = cardChannel.transmit(logoffApdu);
this.view.addDetailMessage("logoff... " + readerName);
if (0x9000 != responseApdu.getSW()) {
this.view.addDetailMessage("logoff status word: " + Integer.toHexString(responseApdu.getSW()));
if (0x6e00 == responseApdu.getSW()) {
// BUD001 smart card reader work-around
return;
}
throw new RuntimeException("logoff failed");
}
} finally {
card.disconnect(true);
}
}
示例9: setUp
import javax.smartcardio.TerminalFactory; //导入方法依赖的package包/类
@Before public void setUp() throws Exception {
if (true) {
Security.addProvider(new Smartcardio());
context = TerminalFactory.getInstance("PC/SC", null, Smartcardio.PROVIDER_NAME);
terminals = context.terminals();
} else {
TerminalFactory terminalFactory = TerminalFactory.getDefault();
terminals = terminalFactory.terminals();
}
}
示例10: SmartcardioTerminalProviderImpl
import javax.smartcardio.TerminalFactory; //导入方法依赖的package包/类
SmartcardioTerminalProviderImpl() {
TerminalFactory factory = TerminalFactory.getDefault();
providerInfo = "SmartcardIO[" + factory.getProvider() + "]";
terminals = factory.terminals();
}