Class IOUtils

java.lang.Object
org.apache.xmlgraphics.util.io.IOUtils

public final class IOUtils extends Object
Utility class providing convenience methods for I/O operations.
  • Constructor Details

    • IOUtils

      private IOUtils()
  • Method Details

    • copy

      public static long copy(InputStream input, OutputStream output) throws IOException
      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 - the InputStream to read data from, must not be null
      output - the OutputStream to write data to, must not be null
      Returns:
      the total number of bytes copied
      Throws:
      IOException - if an I/O error occurs during reading or writing
    • toByteArray

      public static byte[] toByteArray(InputStream input) throws IOException
      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 be null
      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

      public static String toString(Reader reader) throws IOException
      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

      public static void closeQuietly(Closeable closeable)
      Closes a Closeable object quietly, suppressing any exceptions that might occur during the close operation. If the provided Closeable is null, this method does nothing.
      Parameters:
      closeable - the Closeable object to close; may be null.