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); } }
private static List<File> listFiles(String path) throws IOException { List<File> files = new ArrayList<>(); File f = new File(path); if (f.isFile()) { FileReader fr = new FileReader(f); BufferedReader buf = new BufferedReader(fr); while (buf.ready()) { File fn = new File(buf.readLine()); if (fn.exists()) { files.add(fn); } // else warn ? } IOUtils.closeQuietly(buf); } else { File[] fileList = f.listFiles(); if (fileList != null) { files.addAll(Arrays.asList(fileList)); } } return files; } }
IOUtils.closeQuietly(output); IOUtils.closeQuietly(input);
/** * This will parse the stream and populate the COSDocument object. * * @throws IOException If there is an error reading from the stream or corrupt data * is found. */ public void parse() throws IOException { // set to false if all is processed boolean exceptionOccurred = true; try { if (!parseFDFHeader()) { throw new IOException( "Error: Header doesn't contain versioninfo" ); } initialParse(); exceptionOccurred = false; } finally { if (exceptionOccurred && document != null) { IOUtils.closeQuietly(document); document = null; } } } }
IOUtils.closeQuietly(is); is = new ByteArrayInputStream(os.toByteArray()); os.reset();
/** * 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(); }
IOUtils.closeQuietly(out); if (ios != null)
IOUtils.closeQuietly(document); document = null;
IOUtils.closeQuietly(randomAccess); randomAccess = scratchFile.createBuffer(); OutputStream out = new RandomAccessOutputStream(randomAccess);
final int[] readCIDToGIDMap() throws IOException { int[] cid2gid = null; COSBase map = dict.getDictionaryObject(COSName.CID_TO_GID_MAP); if (map instanceof COSStream) { COSStream stream = (COSStream) map; InputStream is = stream.createInputStream(); byte[] mapAsBytes = IOUtils.toByteArray(is); IOUtils.closeQuietly(is); int numberOfInts = mapAsBytes.length / 2; cid2gid = new int[numberOfInts]; int offset = 0; for (int index = 0; index < numberOfInts; index++) { int gid = (mapAsBytes[offset] & 0xff) << 8 | mapAsBytes[offset + 1] & 0xff; cid2gid[index] = gid; offset += 2; } } return cid2gid; } }
IOUtils.closeQuietly(out);
IOUtils.closeQuietly(scratchFile); throw ioe; IOUtils.closeQuietly(raFile); throw ioe;
org.apache.pdfbox.io.IOUtils.closeQuietly(data); } else { InputStream data = pdImage.createInputStream(JP2); 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{ ImageIOUtil.writeImage(image, suffix, out);
IOUtils.closeQuietly(keyStoreStream);
IOUtils.closeQuietly(input);
IOUtils.closeQuietly(source);
IOUtils.closeQuietly(randomAccess); randomAccess = scratchFile.createBuffer(); OutputStream randomOut = new RandomAccessOutputStream(randomAccess);
IOUtils.closeQuietly(scratchFile); throw ioe;
IOUtils.closeQuietly(is); int numberOfInts = mapAsBytes.length / 2; cid2gid = new Object[numberOfInts][4];