当前位置: 首页>>代码示例>>Java>>正文


Java TerminalFactory.getDefault方法代码示例

本文整理汇总了Java中javax.smartcardio.TerminalFactory.getDefault方法的典型用法代码示例。如果您正苦于以下问题:Java TerminalFactory.getDefault方法的具体用法?Java TerminalFactory.getDefault怎么用?Java TerminalFactory.getDefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.smartcardio.TerminalFactory的用法示例。


在下文中一共展示了TerminalFactory.getDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:23,代码来源:PcscTest.java

示例2: main

import javax.smartcardio.TerminalFactory; //导入方法依赖的package包/类
public static void main(final String[] args) throws CardException, CommunicationException {

		TerminalFactory factory = TerminalFactory.getDefault();
		List<CardTerminal> terminals = factory.terminals().list();
		LOGGER.info("Terminals: " + terminals);

		if (terminals != null && !terminals.isEmpty()) {
			// Use the first terminal
			CardTerminal terminal = terminals.get(0);

			// Connect with the card
			Card card = terminal.connect("*");
			LOGGER.info("card: " + card);
			CardChannel channel = card.getBasicChannel();

			PcscProvider provider = new PcscProvider(channel);
			EmvParser parser = new EmvParser(provider, false);
			parser.readEmvCard();

			// Disconnect the card
			card.disconnect(false);
		} else {
			LOGGER.error("No pcsc terminal found");
		}

	}
 
开发者ID:devnied,项目名称:EMV-NFC-Paycard-Enrollment,代码行数:27,代码来源:Main.java

示例3: 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;
	}
}
 
开发者ID:e-Contract,项目名称:commons-eid,代码行数:38,代码来源:CardAndTerminalManager.java

示例4: main

import javax.smartcardio.TerminalFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    TerminalFactory terminalFactory = TerminalFactory.getDefault();
    List<CardTerminal> cardTerminals = terminalFactory.terminals().list();
    System.out.println("Terminals: " + cardTerminals);
    if (cardTerminals.isEmpty()) {
        throw new Exception("No card terminals available");
    }
    CardTerminal cardTerminal = cardTerminals.get(0);
    Card card = cardTerminal.connect("DIRECT");
    card.disconnect(true);

    System.out.println("OK.");
}
 
开发者ID:frohoff,项目名称:jdk8u-dev-jdk,代码行数:14,代码来源:TestDirect.java

示例5: 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());
	}

}
 
开发者ID:intarsys,项目名称:smartcard-io,代码行数:17,代码来源:ListReaders.java

示例6: 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");
		}
	}
}
 
开发者ID:intarsys,项目名称:smartcard-io,代码行数:26,代码来源:Connect.java

示例7: 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));
	}
}
 
开发者ID:jnasmartcardio,项目名称:jnasmartcardio,代码行数:22,代码来源:WaitForChange.java

示例8: create

import javax.smartcardio.TerminalFactory; //导入方法依赖的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);

}
 
开发者ID:identiv,项目名称:ts-cards,代码行数:30,代码来源:SmartcardIoTransmitter.java

示例9: main

import javax.smartcardio.TerminalFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    TerminalFactory terminalFactory = TerminalFactory.getDefault();
    List<CardTerminal> cardTerminals = terminalFactory.terminals().list();
    if (cardTerminals.isEmpty()) {
        System.out.println("Skipping the test: " +
                "no card terminals available");
        return;
    }
    System.out.println("Terminals: " + cardTerminals);
    CardTerminal cardTerminal = cardTerminals.get(0);
    Card card = cardTerminal.connect("DIRECT");
    card.disconnect(true);

    System.out.println("OK.");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:TestDirect.java

示例10: main

import javax.smartcardio.TerminalFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    TerminalFactory factory = TerminalFactory.getDefault();
    System.out.println("Type: " + factory.getType());
    List<CardTerminal> terminals = factory.terminals().list();
    if (terminals.isEmpty()) {
        System.out.println("Skipping the test: " +
                "no card terminals available");
        return;
    }
    System.out.println("Terminals: " + terminals);

    System.out.println("OK.");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:TestDefault.java

示例11: PcscEid

import javax.smartcardio.TerminalFactory; //导入方法依赖的package包/类
public PcscEid(View view, Messages messages) {
	this.view = view;

	Logger logger = new Logger(view);
	LibJ2PCSCGNULinuxFix.fixNativeLibrary(logger);

	this.terminalFactory = TerminalFactory.getDefault();
	this.dialogs = new Dialogs(this.view, messages);
	this.locale = messages.getLocale();
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:11,代码来源:PcscEid.java

示例12: 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;
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:28,代码来源:PcscEid.java

示例13: 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;
	}
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:16,代码来源:PcscEid.java

示例14: 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);
	}
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:33,代码来源:PcscEid.java

示例15: getSlot

import javax.smartcardio.TerminalFactory; //导入方法依赖的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;
	}
 
开发者ID:bluecrystalsign,项目名称:signer-source,代码行数:35,代码来源:Pkcs11Wrapper.java


注:本文中的javax.smartcardio.TerminalFactory.getDefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。