/** * Creates a {@link IRandomAccessSource} based on an {@link InputStream}. The full content of the InputStream is read into memory and used * as the source for the {@link IRandomAccessSource} * @param inputStream the stream to read from * @return the newly created {@link IRandomAccessSource} */ public IRandomAccessSource createSource(InputStream inputStream) throws java.io.IOException{ return createSource(StreamUtil.inputStreamToArray(inputStream)); }
/** * Creates a {@link IRandomAccessSource} based on an {@link InputStream}. The full content of the InputStream is read into memory and used * as the source for the {@link IRandomAccessSource} * @param inputStream the stream to read from * @return the newly created {@link IRandomAccessSource} */ public IRandomAccessSource createSource(InputStream inputStream) throws java.io.IOException{ return createSource(StreamUtil.inputStreamToArray(inputStream)); }
/** * Creates a new {@link IRandomAccessSource} by reading the specified file/resource into memory * @param stream the name of the resource to read * @return the newly created {@link IRandomAccessSource} * @throws java.io.IOException if reading the underling file or stream fails */ private IRandomAccessSource createByReadingToMemory(InputStream stream) throws java.io.IOException { try { return new ArrayRandomAccessSource(StreamUtil.inputStreamToArray(stream)); } finally { try { stream.close(); } catch (java.io.IOException ignored) { } } }
/** * Creates a new {@link IRandomAccessSource} by reading the specified file/resource into memory * @param stream the name of the resource to read * @return the newly created {@link IRandomAccessSource} * @throws java.io.IOException if reading the underling file or stream fails */ private IRandomAccessSource createByReadingToMemory(InputStream stream) throws java.io.IOException { try { return new ArrayRandomAccessSource(StreamUtil.inputStreamToArray(stream)); } finally { try { stream.close(); } catch (java.io.IOException ignored) { } } }
public PdfButtonFormField setImage(String image) throws IOException { InputStream is = new FileInputStream(image); String str = Base64.encodeBytes(StreamUtil.inputStreamToArray(is)); return (PdfButtonFormField) setValue(str); }
public PdfButtonFormField setImage(String image) throws IOException { InputStream is = new FileInputStream(image); String str = Base64.encodeBytes(StreamUtil.inputStreamToArray(is)); return (PdfButtonFormField) setValue(str); }
/** * Deprecated: use retrieveBytesFromResource instead * Replaced by retrieveBytesFromResource for the sake of method name clarity. * * Retrieve a resource as a byte array from a source that * can either be a link to a file, or a base64 encoded {@link String}. * * @param src either link to file or base64 encoded stream. * @return byte[] on success, otherwise null. */ @Deprecated public byte[] retrieveStream(String src) { try (InputStream stream = retrieveResourceAsInputStream(src)) { if (stream != null) { return StreamUtil.inputStreamToArray(stream); } else { return null; } } catch (Exception e) { Logger logger = LoggerFactory.getLogger(ResourceResolver.class); logger.error(MessageFormatUtil.format(LogMessageConstant.UNABLE_TO_RETRIEVE_STREAM_WITH_GIVEN_BASE_URI, uriResolver.getBaseUri(), src), e); return null; } }
/** * Retrieve a resource as a byte array from a source that * can either be a link to a file, or a base64 encoded {@link String}. * * @param src either link to file or base64 encoded stream. * @return byte[] on success, otherwise null. */ public byte[] retrieveBytesFromResource(String src) { try (InputStream stream = retrieveResourceAsInputStream(src)) { if (stream != null) { return StreamUtil.inputStreamToArray(stream); } else { return null; } } catch (IOException ioe) { Logger logger = LoggerFactory.getLogger(ResourceResolver.class); logger.error(MessageFormatUtil.format(LogMessageConstant.UNABLE_TO_RETRIEVE_STREAM_WITH_GIVEN_BASE_URI, uriResolver.getBaseUri(), src), ioe); return null; } }
private OCSPResp getOcspResponse(X509Certificate checkCert, X509Certificate rootCert, String url) throws GeneralSecurityException, OCSPException, IOException, OperatorException { if (checkCert == null || rootCert == null) return null; if (url == null) { url = CertificateUtil.getOCSPURL(checkCert); } if (url == null) return null; LOGGER.info("Getting OCSP from " + url); OCSPReq request = generateOCSPRequest(rootCert, checkCert.getSerialNumber()); byte[] array = request.getEncoded(); URL urlt = new URL(url); InputStream in = SignUtils.getHttpResponseForOcspRequest(array, urlt); return new OCSPResp(StreamUtil.inputStreamToArray(in)); } }
private OCSPResp getOcspResponse(X509Certificate checkCert, X509Certificate rootCert, String url) throws GeneralSecurityException, OCSPException, IOException, OperatorException { if (checkCert == null || rootCert == null) return null; if (url == null) { url = CertificateUtil.getOCSPURL(checkCert); } if (url == null) return null; LOGGER.info("Getting OCSP from " + url); OCSPReq request = generateOCSPRequest(rootCert, checkCert.getSerialNumber()); byte[] array = request.getEncoded(); URL urlt = new URL(url); InputStream in = SignUtils.getHttpResponseForOcspRequest(array, urlt); return new OCSPResp(StreamUtil.inputStreamToArray(in)); } }
try { InputStream stream = resourceResolver.retrieveStyleSheet(styleSheetUri); byte[] bytes = StreamUtil.inputStreamToArray(stream);