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

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

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

IOUtils.closeQuietly介绍

[英]Null safe close of the given Closeable suppressing any exception.
[中]给定可关闭对象的空安全关闭,禁止任何异常。

代码示例

代码示例来源: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. private static List<File> listFiles(String path) throws IOException
  2. {
  3. List<File> files = new ArrayList<>();
  4. File f = new File(path);
  5. if (f.isFile())
  6. {
  7. FileReader fr = new FileReader(f);
  8. BufferedReader buf = new BufferedReader(fr);
  9. while (buf.ready())
  10. {
  11. File fn = new File(buf.readLine());
  12. if (fn.exists())
  13. {
  14. files.add(fn);
  15. } // else warn ?
  16. }
  17. IOUtils.closeQuietly(buf);
  18. }
  19. else
  20. {
  21. File[] fileList = f.listFiles();
  22. if (fileList != null)
  23. {
  24. files.addAll(Arrays.asList(fileList));
  25. }
  26. }
  27. return files;
  28. }
  29. }

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

  1. IOUtils.closeQuietly(output);
  2. IOUtils.closeQuietly(input);

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

  1. /**
  2. * This will parse the stream and populate the COSDocument object.
  3. *
  4. * @throws IOException If there is an error reading from the stream or corrupt data
  5. * is found.
  6. */
  7. public void parse() throws IOException
  8. {
  9. // set to false if all is processed
  10. boolean exceptionOccurred = true;
  11. try
  12. {
  13. if (!parseFDFHeader())
  14. {
  15. throw new IOException( "Error: Header doesn't contain versioninfo" );
  16. }
  17. initialParse();
  18. exceptionOccurred = false;
  19. }
  20. finally
  21. {
  22. if (exceptionOccurred && document != null)
  23. {
  24. IOUtils.closeQuietly(document);
  25. document = null;
  26. }
  27. }
  28. }
  29. }

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

  1. IOUtils.closeQuietly(is);
  2. is = new ByteArrayInputStream(os.toByteArray());
  3. os.reset();

代码示例来源: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/pdfbox

  1. IOUtils.closeQuietly(out);
  2. if (ios != null)

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

  1. IOUtils.closeQuietly(document);
  2. document = null;

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

  1. IOUtils.closeQuietly(randomAccess);
  2. randomAccess = scratchFile.createBuffer();
  3. OutputStream out = new RandomAccessOutputStream(randomAccess);

代码示例来源: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. IOUtils.closeQuietly(out);

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

  1. IOUtils.closeQuietly(scratchFile);
  2. throw ioe;
  3. IOUtils.closeQuietly(raFile);
  4. throw ioe;

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

  1. org.apache.pdfbox.io.IOUtils.closeQuietly(data);
  2. } else {
  3. InputStream data = pdImage.createInputStream(JP2);
  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{
  11. ImageIOUtil.writeImage(image, suffix, out);

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

  1. IOUtils.closeQuietly(keyStoreStream);

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

  1. IOUtils.closeQuietly(input);

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

  1. IOUtils.closeQuietly(source);

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

  1. IOUtils.closeQuietly(randomAccess);
  2. randomAccess = scratchFile.createBuffer();
  3. OutputStream randomOut = new RandomAccessOutputStream(randomAccess);

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

  1. IOUtils.closeQuietly(scratchFile);
  2. throw ioe;

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

  1. IOUtils.closeQuietly(is);
  2. int numberOfInts = mapAsBytes.length / 2;
  3. cid2gid = new Object[numberOfInts][4];

相关文章