eu.europa.esig.dss.utils.Utils.toByteArray()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(3.9k)|赞(0)|评价(0)|浏览(128)

本文整理了Java中eu.europa.esig.dss.utils.Utils.toByteArray()方法的一些代码示例,展示了Utils.toByteArray()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.toByteArray()方法的具体详情如下:
包路径:eu.europa.esig.dss.utils.Utils
类名称:Utils
方法名:toByteArray

Utils.toByteArray介绍

暂无

代码示例

代码示例来源:origin: esig/dss

/**
 * Get the contents of an {@code InputStream} as a {@code byte[]}.
 *
 * @param inputStream
 *            the inputstream to read
 * @return the content of the inputstream as byte array
 */
public static byte[] toByteArray(final InputStream inputStream) {
  if (inputStream == null) {
    throw new NullPointerException();
  }
  try {
    return Utils.toByteArray(inputStream);
  } catch (IOException e) {
    throw new DSSException(e);
  }
}

代码示例来源:origin: esig/dss

private void addCRLToken(final InputStream inputStream) {
  try (InputStream is = inputStream) {
    addCRLBinary(Utils.toByteArray(is));
  } catch (IOException e) {
    throw new DSSException(e);
  }
}

代码示例来源:origin: esig/dss

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;
}

代码示例来源:origin: esig/dss

@Test
public void toByteArray() throws UnsupportedEncodingException, IOException {
  String newFileName = "target/sample.txt";
  String newFileContent = "Hello world!";
  FileOutputStream fos = new FileOutputStream(newFileName);
  fos.write(newFileContent.getBytes("UTF-8"));
  fos.close();
  assertArrayEquals(newFileContent.getBytes("UTF-8"), Utils.toByteArray(new FileInputStream(newFileName)));
}

代码示例来源:origin: esig/dss

@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);
}

代码示例来源:origin: esig/dss

@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);
}

相关文章