Package org.apache.pdfbox.io
Class IOUtils
java.lang.Object
org.apache.pdfbox.io.IOUtils
This class contains various I/O-related methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic IOException
closeAndLogException
(Closeable closeable, org.apache.commons.logging.Log logger, String resourceName, IOException initialException) Try to close an IO resource and log and return if there was an exception.static void
closeQuietly
(Closeable closeable) Null safe close of the givenCloseable
suppressing any exception.static long
copy
(InputStream input, OutputStream output) Copies all the contents from the given input stream to the given output stream.static long
populateBuffer
(InputStream in, byte[] buffer) Populates the given buffer with data read from the input stream.static byte[]
Reads the input stream and returns its contents as a byte array.
-
Method Details
-
toByteArray
Reads the input stream and returns its contents as a byte array.- Parameters:
in
- the input stream to read from.- Returns:
- the byte array
- Throws:
IOException
- if an I/O error occurs
-
copy
Copies all the contents from the given input stream to the given output stream.- Parameters:
input
- the input streamoutput
- the output stream- Returns:
- the number of bytes that have been copied
- Throws:
IOException
- if an I/O error occurs
-
populateBuffer
Populates the given buffer with data read from the input stream. If the data doesn't fit the buffer, only the data that fits in the buffer is read. If the data is less than fits in the buffer, the buffer is not completely filled.- Parameters:
in
- the input stream to read frombuffer
- the buffer to fill- Returns:
- the number of bytes written to the buffer
- Throws:
IOException
- if an I/O error occurs
-
closeQuietly
Null safe close of the givenCloseable
suppressing any exception.- Parameters:
closeable
- to be closed
-
closeAndLogException
public static IOException closeAndLogException(Closeable closeable, org.apache.commons.logging.Log logger, String resourceName, IOException initialException) Try to close an IO resource and log and return if there was an exception.An exception is only returned if the IOException passed in is null.
- Parameters:
closeable
- to be closedlogger
- the logger to be used so that logging appears under that log instanceresourceName
- the name to appear in the log outputinitialException
- if set, this exception will be returned even where there is another exception while closing the IO resource * @return the IOException is there was any but only if initialException is null
-