Package org.apache.xmlgraphics.util.io
Class IOUtils
- java.lang.Object
-
- org.apache.xmlgraphics.util.io.IOUtils
-
public final class IOUtils extends java.lang.ObjectUtility class providing convenience methods for I/O operations.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcloseQuietly(java.io.Closeable closeable)Closes aCloseableobject quietly, suppressing any exceptions that might occur during the close operation.static longcopy(java.io.InputStream input, java.io.OutputStream output)Copies all bytes from the provided input stream to the given output stream.static byte[]toByteArray(java.io.InputStream input)Converts the contents of the provided InputStream into a byte array.static java.lang.StringtoString(java.io.Reader reader)Converts the contents of the provided Reader into a String.
-
-
-
Method Detail
-
copy
public static long copy(java.io.InputStream input, java.io.OutputStream output) throws java.io.IOExceptionCopies 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:
java.io.IOException- if an I/O error occurs during reading or writing
-
toByteArray
public static byte[] toByteArray(java.io.InputStream input) throws java.io.IOExceptionConverts 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:
java.io.IOException- if an I/O error occurs while reading from the InputStream
-
toString
public static java.lang.String toString(java.io.Reader reader) throws java.io.IOExceptionConverts 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:
java.io.IOException- if an I/O error occurs while reading from the Reader
-
closeQuietly
public static void closeQuietly(java.io.Closeable closeable)
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.
-
-