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


Java Utils.closeQuietly方法代码示例

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


在下文中一共展示了Utils.closeQuietly方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: save

import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
private void save(DSSDocument signedDocument) {
	FileChooser fileChooser = new FileChooser();
	fileChooser.setInitialFileName(signedDocument.getName());
	MimeType mimeType = signedDocument.getMimeType();
	ExtensionFilter extFilter = new ExtensionFilter(mimeType.getMimeTypeString(), "*." + MimeType.getExtension(mimeType));
	fileChooser.getExtensionFilters().add(extFilter);
	File fileToSave = fileChooser.showSaveDialog(stage);

	if (fileToSave != null) {
		try {
			FileOutputStream fos = new FileOutputStream(fileToSave);
			Utils.copy(signedDocument.openStream(), fos);
			Utils.closeQuietly(fos);
		} catch (Exception e) {
			Alert alert = new Alert(AlertType.ERROR, "Unable to save file : " + e.getMessage(), ButtonType.CLOSE);
			alert.showAndWait();
			return;
		}
	}
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:21,代码来源:SignatureController.java

示例2: init

import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
@PostConstruct
public void init() throws Exception {

	FopFactoryBuilder builder = new FopFactoryBuilder(new File(".").toURI());
	builder.setAccessibility(true);

	fopFactory = builder.build();

	foUserAgent = fopFactory.newFOUserAgent();
	foUserAgent.setCreator("DSS Webapp");
	foUserAgent.setAccessibility(true);

	TransformerFactory transformerFactory = DomUtils.getSecureTransformerFactory();

	InputStream simpleIS = FOPService.class.getResourceAsStream("/xslt/pdf/simple-report.xslt");
	templateSimpleReport = transformerFactory.newTemplates(new StreamSource(simpleIS));
	Utils.closeQuietly(simpleIS);

	InputStream detailedIS = FOPService.class.getResourceAsStream("/xslt/pdf/detailed-report.xslt");
	templateDetailedReport = transformerFactory.newTemplates(new StreamSource(detailedIS));
	Utils.closeQuietly(detailedIS);
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:23,代码来源:FOPService.java

示例3: init

import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
@Before
public void init() throws Exception {
	File file = new File("src/test/resources/sample.xml");
	FileInputStream fis = new FileInputStream(file);
	byte[] bytes = Utils.toByteArray(fis);
	Utils.closeQuietly(fis);
	String computedDigest = Utils.toBase64(DSSUtils.digest(DigestAlgorithm.SHA256, bytes));

	DigestDocument digestDocument = new DigestDocument();
	digestDocument.setName("sample.xml");
	digestDocument.addDigest(DigestAlgorithm.SHA256, computedDigest);

	documentToSign = digestDocument;

	signatureParameters = new XAdESSignatureParameters();
	signatureParameters.bLevel().setSigningDate(new Date());
	signatureParameters.setSigningCertificate(getSigningCert());
	signatureParameters.setCertificateChain(getCertificateChain());
	signatureParameters.setSignaturePackaging(SignaturePackaging.DETACHED);
	signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B);

	service = new XAdESService(getCompleteCertificateVerifier());
}
 
开发者ID:esig,项目名称:dss,代码行数:24,代码来源:XAdESLevelBDetachedDigestDocumentTest.java

示例4: getAsn1SequenceFromDerOctetString

import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
/**
 * This method returns the {@code ASN1Sequence} encapsulated in {@code DEROctetString}. The {@code DEROctetString}
 * is represented as {@code byte} array.
 *
 * @param bytes
 *            {@code byte} representation of {@code DEROctetString}
 * @return encapsulated {@code ASN1Sequence}
 * @throws DSSException
 *             in case of a decoding problem
 */
public static ASN1Sequence getAsn1SequenceFromDerOctetString(byte[] bytes) throws DSSException {
	ASN1InputStream input = null;
	try {

		input = new ASN1InputStream(bytes);
		final DEROctetString s = (DEROctetString) input.readObject();
		final byte[] content = s.getOctets();
		input.close();
		input = new ASN1InputStream(content);
		final ASN1Sequence seq = (ASN1Sequence) input.readObject();
		return seq;
	} catch (IOException e) {
		throw new DSSException("Error when computing certificate's extensions.", e);
	} finally {
		Utils.closeQuietly(input);
	}
}
 
开发者ID:esig,项目名称:dss,代码行数:28,代码来源:DSSASN1Utils.java

示例5: call

import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
public byte[] call() {
	OutputStream out = null;
	InputStream inputStream = null;
	byte[] result = null;
	try {
		URLConnection connection = createConnection();

		connection.setUseCaches(useCaches);
		connection.setDoInput(true);
		if (content != null) {
			connection.setDoOutput(true);
			out = connection.getOutputStream();
			Utils.write(content, out);
		}
		inputStream = connection.getInputStream();
		result = Utils.toByteArray(maxInputSize > 0? new MaxSizeInputStream(inputStream, maxInputSize, url): inputStream);
	} catch (IOException e) {
		throw new DSSException(String.format(ERROR_MESSAGE, url, e.getMessage()), e);
	} finally {
		Utils.closeQuietly(out);
		Utils.closeQuietly(inputStream);
	}
	return result;
}
 
开发者ID:esig,项目名称:dss,代码行数:25,代码来源:NativeDataLoaderCall.java

示例6: getDigestSignaturePolicy

import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
@Test
public void getDigestSignaturePolicy() throws Exception {
	FileInputStream fis = new FileInputStream("src/test/resources/signature-policy-example.der");
	byte[] policyBytes = Utils.toByteArray(fis);
	Utils.closeQuietly(fis);

	byte[] signaturePolicyDigest = DSSASN1Utils.getAsn1SignaturePolicyDigest(DigestAlgorithm.SHA256, policyBytes);
	String hexSignaturePolicyDigest = Utils.toHex(signaturePolicyDigest);

	assertEquals("fe71e01aedd99f444238602d4e98f47bbab405c58c0e3811b9511dcd58c3c983", hexSignaturePolicyDigest);
}
 
开发者ID:esig,项目名称:dss,代码行数:12,代码来源:DSSASN1UtilsTest.java

示例7: isDSSDictionaryPresentInPreviousRevision

import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
private boolean isDSSDictionaryPresentInPreviousRevision(byte[] originalBytes) {
	PDDocument doc = null;
	PdfDssDict dssDictionary = null;
	try {
		doc = PDDocument.load(originalBytes);
		List<PDSignature> pdSignatures = doc.getSignatureDictionaries();
		if (Utils.isCollectionNotEmpty(pdSignatures)) {
			PdfDict catalog = new PdfBoxDict(doc.getDocumentCatalog().getCOSObject(), doc);
			dssDictionary = PdfDssDict.extract(catalog);
		}
	} catch (Exception e) {
		LOG.warn("Cannot check in previous revisions if DSS dictionary already exist : " + e.getMessage(), e);
	} finally {
		Utils.closeQuietly(doc);
	}

	return dssDictionary != null;
}
 
开发者ID:esig,项目名称:dss,代码行数:19,代码来源:PdfBoxSignatureService.java

示例8: isAsn1Encoded

import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
/**
 * Checks if the signature is ASN.1 encoded.
 *
 * @param signatureValue
 *            signature value to check.
 * @return if the signature is ASN.1 encoded.
 */
private static boolean isAsn1Encoded(byte[] signatureValue) {
	ASN1InputStream is = null;
	try {
		is = new ASN1InputStream(signatureValue);
		ASN1Sequence seq = (ASN1Sequence) is.readObject();
		return seq != null && seq.size() == 2;
	} catch (Exception e) {
		return false;
	} finally {
		Utils.closeQuietly(is);
	}
}
 
开发者ID:esig,项目名称:dss,代码行数:20,代码来源:DSSSignatureUtils.java

示例9: signAndVerify

import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
@Override
public void signAndVerify() throws IOException {
	String containerTemporaryPath = temporaryFolder.newFile().getPath();
	getSignatureParameters().aSiC().setSignatureFileName("signatures2047.xml");
	documentToSign = sign();
	documentToSign.save(containerTemporaryPath);
	ZipFile zip = new ZipFile(containerTemporaryPath);
	assertNotNull("Signature file name is not correct", zip.getEntry("META-INF/signatures2047.xml"));
	Utils.closeQuietly(zip);
}
 
开发者ID:esig,项目名称:dss,代码行数:11,代码来源:ASiCEXAdESSignatureFilenameTest.java

示例10: initKeystore

import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
private void initKeystore(final InputStream ksStream, final String ksType, final String ksPassword) {
	try {
		keyStore = KeyStore.getInstance(ksType);
		final char[] password = (ksPassword == null) ? null : ksPassword.toCharArray();
		keyStore.load(ksStream, password);
		passwordProtection = new PasswordProtection(password);
	} catch (GeneralSecurityException | IOException e) {
		throw new DSSException("Unable to initialize the keystore", e);
	} finally {
		Utils.closeQuietly(ksStream);
	}
}
 
开发者ID:esig,项目名称:dss,代码行数:13,代码来源:KeyStoreCertificateSource.java

示例11: setConnectionManagerSchemeHttps

import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
private RegistryBuilder<ConnectionSocketFactory> setConnectionManagerSchemeHttps(
		final RegistryBuilder<ConnectionSocketFactory> socketFactoryRegistryBuilder) throws DSSException {
	FileInputStream fis = null;
	FileInputStream trustStoreIs = null;
	try {

		X509TrustManager trustManager = null;
		if (Utils.isStringEmpty(sslTruststorePath)) {
			trustManager = new AcceptAllTrustManager();
		} else {
			trustStoreIs = new FileInputStream(new File(sslTruststorePath));
			trustManager = new DefaultTrustManager(trustStoreIs, sslTruststoreType, sslTruststorePassword);
		}

		KeyManager[] keysManager = null;
		if (Utils.isStringEmpty(sslKeystorePath)) {
			LOG.debug("Use default SSL configuration");
			keysManager = new KeyManager[0];
		} else {
			LOG.debug("Use provided info for SSL");
			fis = new FileInputStream(new File(sslKeystorePath));
			DefaultKeyManager dkm = new DefaultKeyManager(fis, sslKeystoreType, sslKeystorePassword);
			keysManager = new KeyManager[] { dkm };
		}

		SSLContext sslContext = SSLContext.getInstance("TLS");
		sslContext.init(keysManager, new TrustManager[] { trustManager }, new SecureRandom());

		SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext);
		return socketFactoryRegistryBuilder.register("https", sslConnectionSocketFactory);
	} catch (final Exception e) {
		throw new DSSException(e);
	} finally {
		Utils.closeQuietly(fis);
		Utils.closeQuietly(trustStoreIs);
	}
}
 
开发者ID:esig,项目名称:dss,代码行数:38,代码来源:CommonsDataLoader.java

示例12: getContent

import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
protected byte[] getContent(final HttpEntity responseEntity) throws DSSException {
	InputStream content = null;
	try {
		content = responseEntity.getContent();
		final byte[] bytes = DSSUtils.toByteArray(content);
		return bytes;
	} catch (IOException e) {
		throw new DSSException(e);
	} finally {
		Utils.closeQuietly(content);
	}
}
 
开发者ID:esig,项目名称:dss,代码行数:13,代码来源:CommonsDataLoader.java

示例13: regenerateCMSSignedData

import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
protected CMSSignedData regenerateCMSSignedData(CMSSignedData cmsSignedData, CAdESSignatureParameters parameters, Store certificatesStore,
		Store attributeCertificatesStore, Store crlsStore, Store otherRevocationInfoFormatStoreBasic, Store otherRevocationInfoFormatStoreOcsp) {
	try {

		final CMSSignedDataGenerator cmsSignedDataGenerator = new CMSSignedDataGenerator();
		cmsSignedDataGenerator.addSigners(cmsSignedData.getSignerInfos());
		cmsSignedDataGenerator.addAttributeCertificates(attributeCertificatesStore);
		cmsSignedDataGenerator.addCertificates(certificatesStore);
		cmsSignedDataGenerator.addCRLs(crlsStore);
		cmsSignedDataGenerator.addOtherRevocationInfo(id_pkix_ocsp_basic, otherRevocationInfoFormatStoreBasic);
		cmsSignedDataGenerator.addOtherRevocationInfo(id_ri_ocsp_response, otherRevocationInfoFormatStoreOcsp);
		final boolean encapsulate = cmsSignedData.getSignedContent() != null;
		if (!encapsulate) {
			List<DSSDocument> detachedContents = parameters.getDetachedContents();
			// CAdES can only sign one document
			final InputStream inputStream = detachedContents.get(0).openStream();
			final CMSProcessableByteArray content = new CMSProcessableByteArray(DSSUtils.toByteArray(inputStream));
			Utils.closeQuietly(inputStream);
			cmsSignedData = cmsSignedDataGenerator.generate(content, encapsulate);
		} else {
			cmsSignedData = cmsSignedDataGenerator.generate(cmsSignedData.getSignedContent(), encapsulate);
		}
		return cmsSignedData;
	} catch (CMSException e) {
		throw new DSSException(e);
	}
}
 
开发者ID:esig,项目名称:dss,代码行数:28,代码来源:CMSSignedDataBuilder.java

示例14: loadCertificate

import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
@Test
public void loadCertificate() throws Exception {
	CertificateToken certificate = DSSUtils.loadCertificate(new FileInputStream("src/test/resources/belgiumrs2.crt"));
	assertNotNull(certificate);

	FileInputStream fis = new FileInputStream("src/test/resources/belgiumrs2.crt");
	byte[] byteArray = Utils.toByteArray(fis);
	logger.info(Utils.toBase64(byteArray));
	Utils.closeQuietly(fis);
	CertificateToken certificate2 = DSSUtils.loadCertificate(byteArray);
	assertNotNull(certificate2);

	CertificateToken certificateNew = DSSUtils.loadCertificate(new FileInputStream("src/test/resources/belgiumrs2-new.crt"));
	assertNotNull(certificateNew);

	FileInputStream fisNew = new FileInputStream("src/test/resources/belgiumrs2-new.crt");
	byte[] byteArrayNew = Utils.toByteArray(fisNew);
	logger.info(Utils.toBase64(byteArrayNew));
	Utils.closeQuietly(fisNew);
	CertificateToken certificate2New = DSSUtils.loadCertificate(byteArrayNew);
	assertNotNull(certificate2New);

	// String cert =
	// "PGh0bWw+PGhlYWQ+PHRpdGxlPlJlcXVlc3QgUmVqZWN0ZWQ8L3RpdGxlPjwvaGVhZD48Ym9keT5UaGUgcmVxdWVzdGVkIFVSTCB3YXMgcmVqZWN0ZWQuIFBsZWFzZSBjb25zdWx0IHdpdGggeW91ciBhZG1pbmlzdHJhdG9yLjxicj48YnI+WW91ciBzdXBwb3J0IElEIGlzOiAxMTY1Njg3NjQzMzgzMDI3NjMxNjwvYm9keT48L2h0bWw+";
	// byte[] decodeBase64 = Base64.decodeBase64(cert);
	// byte[] decodeBase642 = Base64.decodeBase64(decodeBase64);
	// CertificateToken certificate3 =
	// DSSUtils.loadCertificate(base64StringToBase64Binary);
	// assertNotNull(certificate3);
}
 
开发者ID:esig,项目名称:dss,代码行数:31,代码来源:DSSUtilsTest.java

示例15: buildDOM

import eu.europa.esig.dss.utils.Utils; //导入方法依赖的package包/类
/**
 * This method returns the {@link org.w3c.dom.Document} created based on the XML inputStream.
 *
 * @param inputStream
 *            The inputStream stream representing the dssDocument to be created.
 * @return
 * @throws DSSException
 */
public static Document buildDOM(final InputStream inputStream) throws DSSException {
	try {
		ensureDocumentBuilder();
		final Document rootElement = dbFactory.newDocumentBuilder().parse(inputStream);
		return rootElement;
	} catch (Exception e) {
		throw new DSSException(e);
	} finally {
		Utils.closeQuietly(inputStream);
	}
}
 
开发者ID:esig,项目名称:dss,代码行数:20,代码来源:DomUtils.java


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