@Override protected void encode(InputStream input, OutputStream encoded, COSDictionary parameters) throws IOException { IOUtils.copy(input, encoded); encoded.flush(); } }
@Override public void write(OutputStream out) throws IOException, CMSException { // read the content only one time IOUtils.copy(in, out); in.close(); }
/** * Reads the input stream and returns its contents as a byte array. * @param in the input stream to read from. * @return the byte array * @throws IOException if an I/O error occurs */ public static byte[] toByteArray(InputStream in) throws IOException { ByteArrayOutputStream baout = new ByteArrayOutputStream(); copy(in, baout); return baout.toByteArray(); }
private String getStringOfStream(InputStream in, String encoding) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { IOUtils.copy(in, baos); return baos.toString(encoding); } catch (IOException e) { e.printStackTrace(); return null; } }
@Override public DecodeResult decode(InputStream encoded, OutputStream decoded, COSDictionary parameters, int index) throws IOException { IOUtils.copy(encoded, decoded); decoded.flush(); return new DecodeResult(parameters); }
@Override protected void encode(InputStream input, OutputStream encoded, COSDictionary parameters) throws IOException { try (ASCII85OutputStream os = new ASCII85OutputStream(encoded)) { IOUtils.copy(input, os); } encoded.flush(); } }
public ByteArrayDataSource(InputStream is) throws IOException { data = new ByteArrayOutputStream(); IOUtils.copy(is, data); IOUtils.closeQuietly(is); }
private File createTmpFile(InputStream input) throws IOException { File tmpFile = File.createTempFile(TMP_FILE_PREFIX, ".pdf"); try (FileOutputStream fos = new FileOutputStream(tmpFile)) { IOUtils.copy(input, fos); return tmpFile; } finally { IOUtils.closeQuietly(input); } }
/** * Write an incremental update for a non signature case. This can be used for e.g. augmenting * signatures. * * @throws IOException */ private void doWriteIncrement() throws IOException { // write existing PDF IOUtils.copy(new RandomAccessInputStream(incrementalInput), incrementalOutput); // write the actual incremental update incrementalOutput.write(((ByteArrayOutputStream) output).toByteArray()); }
/** * This will copy the stream into a byte array. * * @return The byte array of the filteredStream. * @throws IOException if an I/O error occurs. */ public byte[] toByteArray() throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); try (InputStream is = createInputStream()) { IOUtils.copy(is, output); } return output.toByteArray(); }
@Override public DecodeResult decode(InputStream encoded, OutputStream decoded, COSDictionary parameters, int index) throws IOException { try (ASCII85InputStream is = new ASCII85InputStream(encoded)) { IOUtils.copy(is, decoded); } decoded.flush(); return new DecodeResult(parameters); }
private void writeFont(PDFontDescriptor fd, String name) throws IOException { if (fd != null) { PDStream ff2Stream = fd.getFontFile2(); if (ff2Stream != null) { System.out.println("Writing font: " + name); try (OutputStream os = new FileOutputStream(new File(name + ".ttf")); InputStream is = ff2Stream.createInputStream()) { IOUtils.copy(is, os); } } } }
@Override protected void encode(InputStream input, OutputStream encoded, COSDictionary parameters) throws IOException { int cols = parameters.getInt(COSName.COLUMNS); int rows = parameters.getInt(COSName.ROWS); CCITTFaxEncoderStream ccittFaxEncoderStream = new CCITTFaxEncoderStream(encoded, cols, rows, TIFFExtension.FILL_LEFT_TO_RIGHT); IOUtils.copy(input, ccittFaxEncoderStream); input.close(); } }
/** * Write externally created signature of PDF data obtained via {@link #getDataToSign()} method. * * @param cmsSignature CMS signature byte array * @throws IllegalStateException if PDF is not prepared for external signing * @throws IOException if source data stream is closed */ public void writeExternalSignature(byte[] cmsSignature) throws IOException { if (incrementPart == null || incrementalInput == null) { throw new IllegalStateException("PDF not prepared for setting signature"); } byte[] signatureBytes = Hex.getBytes(cmsSignature); // substract 2 bytes because of the enclosing "<>" if (signatureBytes.length > signatureLength - 2) { throw new IOException("Can't write signature, not enough space"); } // overwrite the signature Contents in the buffer int incPartSigOffset = (int) (signatureOffset - incrementalInput.length()); System.arraycopy(signatureBytes, 0, incrementPart, incPartSigOffset + 1, signatureBytes.length); // write the data to the incremental output stream IOUtils.copy(new RandomAccessInputStream(incrementalInput), incrementalOutput); incrementalOutput.write(incrementPart); // prevent further use incrementPart = null; }
/** * Constructor. Reads all data from the input stream and embeds it into the document with the * given filters applied, if any. This method closes the InputStream. */ private PDStream(PDDocument doc, InputStream input, COSBase filters) throws IOException { stream = doc.getDocument().createCOSStream(); try (OutputStream output = stream.createOutputStream(filters)) { IOUtils.copy(input, output); } finally { if (input != null) { input.close(); } } }
/** * Creates a COS stream from raw (encoded) data. */ private static COSStream createRawStream(PDDocument document, InputStream rawInput) throws IOException { COSStream stream = document.getDocument().createCOSStream(); try (OutputStream output = stream.createRawOutputStream()) { IOUtils.copy(rawInput, output); } return stream; }
/** * Returns the contents of the stream as a PDF "text string". */ public String toTextString() { ByteArrayOutputStream out = new ByteArrayOutputStream(); InputStream input = null; try { input = createInputStream(); IOUtils.copy(input, out); } catch (IOException e) { LOG.debug("An exception occured trying to get the content - returning empty string instead", e); return ""; } finally { IOUtils.closeQuietly(input); } COSString string = new COSString(out.toByteArray()); return string.getString(); }
org.apache.pdfbox.io.IOUtils.copy(data, out); org.apache.pdfbox.io.IOUtils.closeQuietly(data); } else { org.apache.pdfbox.io.IOUtils.copy(data, out); org.apache.pdfbox.io.IOUtils.closeQuietly(data); } else if ("jb2".equals(suffix)) { InputStream data = pdImage.createInputStream(JB2); org.apache.pdfbox.io.IOUtils.copy(data, out); org.apache.pdfbox.io.IOUtils.closeQuietly(data); } else{
private COSStream createCombinedContentStream(COSBase contents) throws IOException { List<COSStream> contentStreams = createContentStreamList(contents); // concatenate streams COSStream concatStream = inputPDFDocument.getDocument().createCOSStream(); try (OutputStream out = concatStream.createOutputStream(COSName.FLATE_DECODE)) { for (COSStream contentStream : contentStreams) { try (InputStream in = contentStream.createInputStream()) { IOUtils.copy(in, out); out.flush(); } } } return concatStream; }
IOUtils.copy(input, getStandardOutput());