Class IOUtils
java.lang.Object
org.apache.xmlgraphics.util.io.IOUtils
Utility class providing convenience methods for I/O operations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcloseQuietly(Closeable closeable) Closes aCloseableobject quietly, suppressing any exceptions that might occur during the close operation.static longcopy(InputStream input, OutputStream output) Copies all bytes from the provided input stream to the given output stream.static byte[]toByteArray(InputStream input) Converts the contents of the provided InputStream into a byte array.static StringConverts the contents of the provided Reader into a String.
-
Constructor Details
-
IOUtils
private IOUtils()
-
-
Method Details
-
copy
Copies all bytes from the provided input stream to the given output stream. The method operates using a buffer and is useful for transferring data between streams without modifying the contents.- Parameters:
input- theInputStreamto read data from, must not benulloutput- theOutputStreamto write data to, must not benull- Returns:
- the total number of bytes copied
- Throws:
IOException- if an I/O error occurs during reading or writing
-
toByteArray
Converts the contents of the provided InputStream into a byte array. This method reads all the data from the InputStream and writes it into a ByteArrayOutputStream, which is then converted to a byte array.- Parameters:
input- the InputStream to read data from, must not benull- Returns:
- a byte array containing all the data read from the InputStream
- Throws:
IOException- if an I/O error occurs while reading from the InputStream
-
toString
Converts the contents of the provided Reader into a String. This method reads characters from the Reader into a buffer and then appends them to a StringBuilder, which is returned as a String.- Parameters:
reader- the Reader to read data from, must not be null- Returns:
- a String containing all the characters read from the Reader
- Throws:
IOException- if an I/O error occurs while reading from the Reader
-
closeQuietly
Closes aCloseableobject quietly, suppressing any exceptions that might occur during the close operation. If the providedCloseableisnull, this method does nothing.- Parameters:
closeable- theCloseableobject to close; may benull.
-