org.apache.pdfbox.io.IOUtils.copy()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(357)

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

IOUtils.copy介绍

[英]Copies all the contents from the given input stream to the given output stream.
[中]将所有内容从给定的输入流复制到给定的输出流。

代码示例

代码示例来源:origin: apache/pdfbox

  1. @Override
  2. protected void encode(InputStream input, OutputStream encoded, COSDictionary parameters)
  3. throws IOException
  4. {
  5. IOUtils.copy(input, encoded);
  6. encoded.flush();
  7. }
  8. }

代码示例来源:origin: apache/pdfbox

  1. @Override
  2. public void write(OutputStream out) throws IOException, CMSException
  3. {
  4. // read the content only one time
  5. IOUtils.copy(in, out);
  6. in.close();
  7. }

代码示例来源:origin: apache/pdfbox

  1. /**
  2. * Reads the input stream and returns its contents as a byte array.
  3. * @param in the input stream to read from.
  4. * @return the byte array
  5. * @throws IOException if an I/O error occurs
  6. */
  7. public static byte[] toByteArray(InputStream in) throws IOException
  8. {
  9. ByteArrayOutputStream baout = new ByteArrayOutputStream();
  10. copy(in, baout);
  11. return baout.toByteArray();
  12. }

代码示例来源:origin: apache/pdfbox

  1. private String getStringOfStream(InputStream in, String encoding)
  2. {
  3. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  4. try
  5. {
  6. IOUtils.copy(in, baos);
  7. return baos.toString(encoding);
  8. }
  9. catch (IOException e)
  10. {
  11. e.printStackTrace();
  12. return null;
  13. }
  14. }

代码示例来源:origin: apache/pdfbox

  1. @Override
  2. public DecodeResult decode(InputStream encoded, OutputStream decoded,
  3. COSDictionary parameters, int index)
  4. throws IOException
  5. {
  6. IOUtils.copy(encoded, decoded);
  7. decoded.flush();
  8. return new DecodeResult(parameters);
  9. }

代码示例来源:origin: apache/pdfbox

  1. @Override
  2. protected void encode(InputStream input, OutputStream encoded, COSDictionary parameters)
  3. throws IOException
  4. {
  5. try (ASCII85OutputStream os = new ASCII85OutputStream(encoded))
  6. {
  7. IOUtils.copy(input, os);
  8. }
  9. encoded.flush();
  10. }
  11. }

代码示例来源:origin: apache/pdfbox

  1. public ByteArrayDataSource(InputStream is) throws IOException
  2. {
  3. data = new ByteArrayOutputStream();
  4. IOUtils.copy(is, data);
  5. IOUtils.closeQuietly(is);
  6. }

代码示例来源:origin: apache/pdfbox

  1. private File createTmpFile(InputStream input) throws IOException
  2. {
  3. File tmpFile = File.createTempFile(TMP_FILE_PREFIX, ".pdf");
  4. try (FileOutputStream fos = new FileOutputStream(tmpFile))
  5. {
  6. IOUtils.copy(input, fos);
  7. return tmpFile;
  8. }
  9. finally
  10. {
  11. IOUtils.closeQuietly(input);
  12. }
  13. }

代码示例来源:origin: apache/pdfbox

  1. /**
  2. * Write an incremental update for a non signature case. This can be used for e.g. augmenting
  3. * signatures.
  4. *
  5. * @throws IOException
  6. */
  7. private void doWriteIncrement() throws IOException
  8. {
  9. // write existing PDF
  10. IOUtils.copy(new RandomAccessInputStream(incrementalInput), incrementalOutput);
  11. // write the actual incremental update
  12. incrementalOutput.write(((ByteArrayOutputStream) output).toByteArray());
  13. }

代码示例来源:origin: apache/pdfbox

  1. /**
  2. * This will copy the stream into a byte array.
  3. *
  4. * @return The byte array of the filteredStream.
  5. * @throws IOException if an I/O error occurs.
  6. */
  7. public byte[] toByteArray() throws IOException
  8. {
  9. ByteArrayOutputStream output = new ByteArrayOutputStream();
  10. try (InputStream is = createInputStream())
  11. {
  12. IOUtils.copy(is, output);
  13. }
  14. return output.toByteArray();
  15. }

代码示例来源:origin: apache/pdfbox

  1. @Override
  2. public DecodeResult decode(InputStream encoded, OutputStream decoded,
  3. COSDictionary parameters, int index) throws IOException
  4. {
  5. try (ASCII85InputStream is = new ASCII85InputStream(encoded))
  6. {
  7. IOUtils.copy(is, decoded);
  8. }
  9. decoded.flush();
  10. return new DecodeResult(parameters);
  11. }

代码示例来源:origin: apache/pdfbox

  1. private void writeFont(PDFontDescriptor fd, String name) throws IOException
  2. {
  3. if (fd != null)
  4. {
  5. PDStream ff2Stream = fd.getFontFile2();
  6. if (ff2Stream != null)
  7. {
  8. System.out.println("Writing font: " + name);
  9. try (OutputStream os = new FileOutputStream(new File(name + ".ttf"));
  10. InputStream is = ff2Stream.createInputStream())
  11. {
  12. IOUtils.copy(is, os);
  13. }
  14. }
  15. }
  16. }

代码示例来源:origin: apache/pdfbox

  1. @Override
  2. protected void encode(InputStream input, OutputStream encoded, COSDictionary parameters)
  3. throws IOException
  4. {
  5. int cols = parameters.getInt(COSName.COLUMNS);
  6. int rows = parameters.getInt(COSName.ROWS);
  7. CCITTFaxEncoderStream ccittFaxEncoderStream =
  8. new CCITTFaxEncoderStream(encoded, cols, rows, TIFFExtension.FILL_LEFT_TO_RIGHT);
  9. IOUtils.copy(input, ccittFaxEncoderStream);
  10. input.close();
  11. }
  12. }

代码示例来源:origin: apache/pdfbox

  1. /**
  2. * Write externally created signature of PDF data obtained via {@link #getDataToSign()} method.
  3. *
  4. * @param cmsSignature CMS signature byte array
  5. * @throws IllegalStateException if PDF is not prepared for external signing
  6. * @throws IOException if source data stream is closed
  7. */
  8. public void writeExternalSignature(byte[] cmsSignature) throws IOException
  9. {
  10. if (incrementPart == null || incrementalInput == null)
  11. {
  12. throw new IllegalStateException("PDF not prepared for setting signature");
  13. }
  14. byte[] signatureBytes = Hex.getBytes(cmsSignature);
  15. // substract 2 bytes because of the enclosing "<>"
  16. if (signatureBytes.length > signatureLength - 2)
  17. {
  18. throw new IOException("Can't write signature, not enough space");
  19. }
  20. // overwrite the signature Contents in the buffer
  21. int incPartSigOffset = (int) (signatureOffset - incrementalInput.length());
  22. System.arraycopy(signatureBytes, 0, incrementPart, incPartSigOffset + 1, signatureBytes.length);
  23. // write the data to the incremental output stream
  24. IOUtils.copy(new RandomAccessInputStream(incrementalInput), incrementalOutput);
  25. incrementalOutput.write(incrementPart);
  26. // prevent further use
  27. incrementPart = null;
  28. }

代码示例来源:origin: apache/pdfbox

  1. /**
  2. * Constructor. Reads all data from the input stream and embeds it into the document with the
  3. * given filters applied, if any. This method closes the InputStream.
  4. */
  5. private PDStream(PDDocument doc, InputStream input, COSBase filters) throws IOException
  6. {
  7. stream = doc.getDocument().createCOSStream();
  8. try (OutputStream output = stream.createOutputStream(filters))
  9. {
  10. IOUtils.copy(input, output);
  11. }
  12. finally
  13. {
  14. if (input != null)
  15. {
  16. input.close();
  17. }
  18. }
  19. }

代码示例来源:origin: apache/pdfbox

  1. /**
  2. * Creates a COS stream from raw (encoded) data.
  3. */
  4. private static COSStream createRawStream(PDDocument document, InputStream rawInput)
  5. throws IOException
  6. {
  7. COSStream stream = document.getDocument().createCOSStream();
  8. try (OutputStream output = stream.createRawOutputStream())
  9. {
  10. IOUtils.copy(rawInput, output);
  11. }
  12. return stream;
  13. }

代码示例来源:origin: apache/pdfbox

  1. /**
  2. * Returns the contents of the stream as a PDF "text string".
  3. */
  4. public String toTextString()
  5. {
  6. ByteArrayOutputStream out = new ByteArrayOutputStream();
  7. InputStream input = null;
  8. try
  9. {
  10. input = createInputStream();
  11. IOUtils.copy(input, out);
  12. }
  13. catch (IOException e)
  14. {
  15. LOG.debug("An exception occured trying to get the content - returning empty string instead", e);
  16. return "";
  17. }
  18. finally
  19. {
  20. IOUtils.closeQuietly(input);
  21. }
  22. COSString string = new COSString(out.toByteArray());
  23. return string.getString();
  24. }

代码示例来源:origin: apache/tika

  1. org.apache.pdfbox.io.IOUtils.copy(data, out);
  2. org.apache.pdfbox.io.IOUtils.closeQuietly(data);
  3. } else {
  4. org.apache.pdfbox.io.IOUtils.copy(data, out);
  5. org.apache.pdfbox.io.IOUtils.closeQuietly(data);
  6. } else if ("jb2".equals(suffix)) {
  7. InputStream data = pdImage.createInputStream(JB2);
  8. org.apache.pdfbox.io.IOUtils.copy(data, out);
  9. org.apache.pdfbox.io.IOUtils.closeQuietly(data);
  10. } else{

代码示例来源:origin: apache/pdfbox

  1. private COSStream createCombinedContentStream(COSBase contents) throws IOException
  2. {
  3. List<COSStream> contentStreams = createContentStreamList(contents);
  4. // concatenate streams
  5. COSStream concatStream = inputPDFDocument.getDocument().createCOSStream();
  6. try (OutputStream out = concatStream.createOutputStream(COSName.FLATE_DECODE))
  7. {
  8. for (COSStream contentStream : contentStreams)
  9. {
  10. try (InputStream in = contentStream.createInputStream())
  11. {
  12. IOUtils.copy(in, out);
  13. out.flush();
  14. }
  15. }
  16. }
  17. return concatStream;
  18. }

代码示例来源:origin: apache/pdfbox

  1. IOUtils.copy(input, getStandardOutput());

相关文章