Class IOUtils


  • public class IOUtils
    extends java.lang.Object
    Copied from Apache Commons IO revision 1686747.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int EOF
      Represents the end-of-file (or stream).
    • Constructor Summary

      Constructors 
      Constructor Description
      IOUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int copy​(java.io.Reader input, java.io.Writer output)
      Copies chars from a Reader to a Writer.
      static long copyLarge​(java.io.Reader input, java.io.Writer output)
      Copies chars from a large (over 2GB) Reader to a Writer.
      static long copyLarge​(java.io.Reader input, java.io.Writer output, char[] buffer)
      Copies chars from a large (over 2GB) Reader to a Writer.
      static java.lang.String toString​(java.io.Reader input)
      Gets the contents of a Reader as a String.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • EOF

        public static final int EOF
        Represents the end-of-file (or stream).
        See Also:
        Constant Field Values
    • Constructor Detail

      • IOUtils

        public IOUtils()
    • Method Detail

      • copy

        public static int copy​(java.io.Reader input,
                               java.io.Writer output)
                        throws java.io.IOException
        Copies chars from a Reader to a Writer.

        This method buffers the input internally, so there is no need to use a BufferedReader.

        Large streams (over 2GB) will return a chars copied value of -1 after the copy has completed since the correct number of chars cannot be returned as an int. For large streams use the copyLarge(Reader, Writer) method.

        Parameters:
        input - the Reader to read from
        output - the Writer to write to
        Returns:
        the number of characters copied, or -1 if > Integer.MAX_VALUE
        Throws:
        java.lang.NullPointerException - if the input or output is null
        java.io.IOException - if an I/O error occurs
        Since:
        1.1
      • copyLarge

        public static long copyLarge​(java.io.Reader input,
                                     java.io.Writer output)
                              throws java.io.IOException
        Copies chars from a large (over 2GB) Reader to a Writer.

        This method buffers the input internally, so there is no need to use a BufferedReader.

        The buffer size is given by DEFAULT_BUFFER_SIZE.

        Parameters:
        input - the Reader to read from
        output - the Writer to write to
        Returns:
        the number of characters copied
        Throws:
        java.lang.NullPointerException - if the input or output is null
        java.io.IOException - if an I/O error occurs
        Since:
        1.3
      • copyLarge

        public static long copyLarge​(java.io.Reader input,
                                     java.io.Writer output,
                                     char[] buffer)
                              throws java.io.IOException
        Copies chars from a large (over 2GB) Reader to a Writer.

        This method uses the provided buffer, so there is no need to use a BufferedReader.

        Parameters:
        input - the Reader to read from
        output - the Writer to write to
        buffer - the buffer to be used for the copy
        Returns:
        the number of characters copied
        Throws:
        java.lang.NullPointerException - if the input or output is null
        java.io.IOException - if an I/O error occurs
        Since:
        2.2
      • toString

        public static java.lang.String toString​(java.io.Reader input)
                                         throws java.io.IOException
        Gets the contents of a Reader as a String.

        This method buffers the input internally, so there is no need to use a BufferedReader.

        Parameters:
        input - the Reader to read from
        Returns:
        the requested String
        Throws:
        java.lang.NullPointerException - if the input is null
        java.io.IOException - if an I/O error occurs