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

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

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

IOUtils.toByteArray介绍

[英]Reads the input stream and returns its contents as a byte array.
[中]读取输入流并将其内容作为字节数组返回。

代码示例

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

  1. public byte[] toByteArray() throws IOException
  2. {
  3. return IOUtils.toByteArray(this);
  4. }
  5. }

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

  1. private static byte[] getBytesFromStream(final COSStream stream) throws IOException
  2. {
  3. try (final InputStream is = stream.createInputStream())
  4. {
  5. return IOUtils.toByteArray(is);
  6. }
  7. }

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

  1. /**
  2. * Creates a signed timestamp token by the given input stream.
  3. *
  4. * @param content InputStream of the content to sign
  5. * @return the byte[] of the timestamp token
  6. * @throws IOException
  7. */
  8. public byte[] getTimeStampToken(InputStream content) throws IOException
  9. {
  10. return tsaClient.getTimeStampToken(IOUtils.toByteArray(content));
  11. }

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

  1. @Override
  2. public void actionPerformed(ActionEvent actionEvent)
  3. {
  4. try
  5. {
  6. byte[] bytes = IOUtils.toByteArray(cosStream.createInputStream());
  7. saveStream(bytes, fileFilter, extension);
  8. }
  9. catch (IOException e)
  10. {
  11. e.printStackTrace();
  12. }
  13. }
  14. });

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

  1. /**
  2. * Creates a new JPEG Image XObject from an input stream containing JPEG data.
  3. *
  4. * The input stream data will be preserved and embedded in the PDF file without modification.
  5. * @param document the document where the image will be created
  6. * @param stream a stream of JPEG data
  7. * @return a new Image XObject
  8. *
  9. * @throws IOException if the input stream cannot be read
  10. */
  11. public static PDImageXObject createFromStream(PDDocument document, InputStream stream)
  12. throws IOException
  13. {
  14. return createFromByteArray(document, IOUtils.toByteArray(stream));
  15. }

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

  1. @Override
  2. public void actionPerformed(ActionEvent actionEvent)
  3. {
  4. try
  5. {
  6. InputStream data = stream.createInputStream(stopFilters);
  7. saveStream(IOUtils.toByteArray(data), null, null);
  8. }
  9. catch (IOException e)
  10. {
  11. e.printStackTrace();
  12. }
  13. }
  14. });

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

  1. @Override
  2. public void actionPerformed(ActionEvent actionEvent)
  3. {
  4. try
  5. {
  6. byte[] bytes = IOUtils.toByteArray(cosStream.createRawInputStream());
  7. saveStream(bytes, null, null);
  8. }
  9. catch (IOException e)
  10. {
  11. e.printStackTrace();
  12. }
  13. }
  14. });

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

  1. @Override
  2. public void actionPerformed(ActionEvent actionEvent)
  3. {
  4. try
  5. {
  6. byte[] bytes = IOUtils.toByteArray(cosStream.createInputStream());
  7. File temp = File.createTempFile("pdfbox", "." + extension);
  8. temp.deleteOnExit();
  9. try (FileOutputStream outputStream = new FileOutputStream(temp))
  10. {
  11. outputStream.write(bytes);
  12. Desktop.getDesktop().open(temp);
  13. }
  14. }
  15. catch (IOException e)
  16. {
  17. e.printStackTrace();
  18. }
  19. }
  20. });

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

  1. response = IOUtils.toByteArray(input);

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

  1. try (FileInputStream fis = new FileInputStream(fileName))
  2. documentBytes = IOUtils.toByteArray(fis);

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

  1. @Override
  2. public byte[] getBytes() throws IOException
  3. {
  4. PDStream ff3Stream = getFontDescriptor().getFontFile3();
  5. return IOUtils.toByteArray(ff3Stream.createInputStream());
  6. }
  7. }

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

  1. @Override
  2. public byte[] getBytes() throws IOException
  3. {
  4. PDStream ff3Stream = getFontDescriptor().getFontFile3();
  5. return IOUtils.toByteArray(ff3Stream.createInputStream());
  6. }
  7. }

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

  1. /**
  2. * This will encrypt a stream, but not the dictionary as the dictionary is
  3. * encrypted by visitFromString() in COSWriter and we don't want to encrypt
  4. * it twice.
  5. *
  6. * @param stream The stream to decrypt.
  7. * @param objNum The object number.
  8. * @param genNum The object generation number.
  9. *
  10. * @throws IOException If there is an error getting the stream data.
  11. */
  12. public void encryptStream(COSStream stream, long objNum, int genNum) throws IOException
  13. {
  14. byte[] rawData = IOUtils.toByteArray(stream.createRawInputStream());
  15. ByteArrayInputStream encryptedStream = new ByteArrayInputStream(rawData);
  16. try (OutputStream output = stream.createRawOutputStream())
  17. {
  18. encryptData(objNum, genNum, encryptedStream, output, false /* encrypt */);
  19. }
  20. }

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

  1. protected final byte[] getMetaDataStreamAsBytes(PDMetadata metadata)
  2. {
  3. try (InputStream metaDataContent = metadata.createInputStream())
  4. {
  5. return IOUtils.toByteArray(metaDataContent);
  6. }
  7. catch (IOException e)
  8. {
  9. this.fContainer.push(new ValidationError(ERROR_METADATA_FORMAT_STREAM,
  10. this.font.getName() + ": Unable to read font metadata due to : " + e.getMessage(), e));
  11. return null;
  12. }
  13. }

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

  1. private void requestStreamText(String command) throws IOException
  2. {
  3. new DocumentCreator(command).execute();
  4. synchronized (stream)
  5. {
  6. InputStream is = stream.getStream(command);
  7. if (is == null)
  8. {
  9. JOptionPane.showMessageDialog(panel, command + " text not available (filter missing?)");
  10. return;
  11. }
  12. hexView.changeData(IOUtils.toByteArray(is));
  13. }
  14. }

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

  1. final int[] readCIDToGIDMap() throws IOException
  2. {
  3. int[] cid2gid = null;
  4. COSBase map = dict.getDictionaryObject(COSName.CID_TO_GID_MAP);
  5. if (map instanceof COSStream)
  6. {
  7. COSStream stream = (COSStream) map;
  8. InputStream is = stream.createInputStream();
  9. byte[] mapAsBytes = IOUtils.toByteArray(is);
  10. IOUtils.closeQuietly(is);
  11. int numberOfInts = mapAsBytes.length / 2;
  12. cid2gid = new int[numberOfInts];
  13. int offset = 0;
  14. for (int index = 0; index < numberOfInts; index++)
  15. {
  16. int gid = (mapAsBytes[offset] & 0xff) << 8 | mapAsBytes[offset + 1] & 0xff;
  17. cid2gid[index] = gid;
  18. offset += 2;
  19. }
  20. }
  21. return cid2gid;
  22. }
  23. }

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

  1. try
  2. byte[] bytes = IOUtils.toByteArray(stream.createInputStream());
  3. out = stream.createOutputStream(COSName.FLATE_DECODE);
  4. out.write(bytes);

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

  1. /**
  2. * Go through the elements of a COSArray containing each an COSStream to print in Hex.
  3. *
  4. * @param elements COSArray of elements containing a COS Stream
  5. * @param description to append on Print
  6. * @throws IOException
  7. */
  8. private void printStreamsFromArray(COSArray elements, String description) throws IOException
  9. {
  10. for (COSBase baseElem : elements)
  11. {
  12. COSObject streamObj = (COSObject) baseElem;
  13. if (streamObj.getObject() instanceof COSStream)
  14. {
  15. COSStream cosStream = (COSStream) streamObj.getObject();
  16. try (InputStream is = cosStream.createInputStream())
  17. {
  18. byte[] streamBytes = IOUtils.toByteArray(is);
  19. System.out.println(description + " (" + elements.indexOf(streamObj) + "): "
  20. + Hex.getString(streamBytes));
  21. }
  22. }
  23. }
  24. }

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

  1. private StyledDocument getContentStreamDocument(InputStream inputStream)
  2. {
  3. StyledDocument docu = new DefaultStyledDocument();
  4. PDFStreamParser parser;
  5. try
  6. {
  7. parser = new PDFStreamParser(IOUtils.toByteArray(inputStream));
  8. parser.parse();
  9. }
  10. catch (IOException e)
  11. {
  12. return null;
  13. }
  14. for (Object obj : parser.getTokens())
  15. {
  16. writeToken(obj, docu);
  17. }
  18. return docu;
  19. }

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

  1. byte[] mapAsBytes = IOUtils.toByteArray(is);
  2. IOUtils.closeQuietly(is);
  3. int numberOfInts = mapAsBytes.length / 2;

相关文章