private static void createFinalDocument(File pdfFile, File overlayPdf) throws IOException { PDDocument doc = new PDDocument(); try { PDPage page = new PDPage(); doc.addPage(page); PDImageXObject pdImage =JPEGFactory.createFromStream(doc, new AutoCloseInputStream(ExampleAddImage.class.getClassLoader().getResourceAsStream("death-star-plans.jpg"))); PDPageContentStream contentStream = new PDPageContentStream(doc, page, PDPageContentStream.AppendMode.APPEND, true); Map<Integer, String> overlayGuide = new HashMap<>(); contentStream.drawImage(pdImage, 100, 300, pdImage.getWidth()*scale, pdImage.getHeight()*scale); overlayGuide.put(1, overlayPdf.getAbsolutePath()); Overlay overlay = new Overlay(); overlay.setInputPDF(doc); overlay.setOverlayPosition(Overlay.Position.FOREGROUND); overlay.overlay(overlayGuide); contentStream.close(); doc.save(pdfFile); } finally { doc.close(); } }
private void pushArtifactsToVersion(BintrayUploadInfo uploadInfo, List<FileInfo> artifactsToPush, BasicStatusHolder status, VersionHandle bintrayVersionHandle) throws MultipleBintrayCallException { List<RepoPath> artifactPaths = Lists.newArrayList(); Map<String, InputStream> streamMap = Maps.newHashMap(); try { for (FileInfo fileInfo : artifactsToPush) { artifactPaths.add(fileInfo.getRepoPath()); ResourceStreamHandle handle = repoService.getResourceStreamHandle(fileInfo.getRepoPath()); streamMap.put(fileInfo.getRelPath(), new AutoCloseInputStream(handle.getInputStream())); } status.status("Starting to push the requested files to " + String.format("into %s/%s/%s/%s: ", uploadInfo.getPackageDetails().getSubject(), uploadInfo.getPackageDetails().getRepo(), uploadInfo.getPackageDetails().getName(), uploadInfo.getVersionDetails().getName()), log); log.info("Pushing {} files...", streamMap.keySet().size()); log.debug("Pushing the following files into Bintray: {}", Arrays.toString(artifactPaths.toArray())); bintrayVersionHandle.upload(streamMap); } catch (MultipleBintrayCallException mbce) { for (BintrayCallException bce : mbce.getExceptions()) { status.error(bce.toString(), bce.getStatusCode(), log); } throw mbce; } finally { for (InputStream stream : streamMap.values()) { IOUtils.closeQuietly(stream); } } }
@Override public InputStream getFileAsStream(Path file) throws IOException { InputStream in = new FileInputStream(file.toFile()); BufferedInputStream bis = new BufferedInputStream(in); AutoCloseInputStream acis = new AutoCloseInputStream (bis); return acis; }
private String md5sum(final File file) { try { final InputStream fis = new AutoCloseInputStream(new FileInputStream(file)); return new String(Hex.encodeHex(DigestUtils.md5(fis))); } catch (Exception e) { throw new RuntimeException(e); } }
/** * {@inheritDoc} */ @Override public InputStream openInputStream(URI handle, boolean compressed) throws DataStoreException { checkScheme(handle); try { return new AutoCloseInputStream(FileUtils.openInputStream(openFile(handle, compressed))); } catch (final IOException e) { throw new DataStoreException("Could not open input stream for data: ", e); } }
@Override public InputStream openInputStream(URI handle, boolean compressed) throws DataStoreException { checkScheme(handle); try { return new AutoCloseInputStream(FileUtils.openInputStream(openFile(handle, compressed))); } catch (final IOException e) { throw new DataStoreException("Could not open input stream for data " + handle + ":", e); } }
public SolrNativeQueryResult(InputStream inputStream) { super(); this.inputStream = new AutoCloseInputStream(inputStream); }
private XmlObject parseIncomingXmlObject(InputStream payload) throws XmlException, IOException { // fixes https://issues.apache.org/jira/browse/XMLBEANS-226 // @see http://commons.apache.org/io/api-release/org/apache/commons/io/input/AutoCloseInputStream.html XmlObject request = XmlObject.Factory.parse(new AutoCloseInputStream(payload)); return request; }
private XmlObject parseIncomingXmlObject(InputStream payload) throws XmlException, IOException { // @see https://issues.apache.org/jira/browse/XMLBEANS-226 // @see http://commons.apache.org/io/api-release/org/apache/commons/io/input/AutoCloseInputStream.html return XmlObject.Factory.parse(new AutoCloseInputStream(payload)); }
/** * Decode a B-encoded byte buffer. * * <p> * Automatically instantiates a new BDecoder for the provided buffer and * decodes its root member. * </p> * * @param data The {@link ByteBuffer} to read from. */ public static BEValue bdecode(ByteBuffer data) throws IOException { return BDecoder.bdecode(new AutoCloseInputStream( new ByteArrayInputStream(data.array()))); }