Class UtilIO


  • public final class UtilIO
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void copy​(java.io.Reader reader, java.lang.Appendable out)
      Copy a Reader to an Appendable.
      static java.lang.String readString​(byte[] bytes)
      Convert a byte array to a string; consistently uses \n line endings in java.
      static java.lang.String readString​(byte[] bytes, int offset, int length)
      Convert a byte array to a string; consistently uses \n line endings in java.
      static java.lang.String readString​(byte[] bytes, int offset, int length, java.lang.String charset)
      Convert a byte array to a string; consistently uses \n line endings in java.
      static java.lang.String readString​(byte[] bytes, int offset, int length, java.nio.charset.Charset charset)
      Convert a byte array to a string, consistently uses \n line endings in java.
      static java.lang.String readString​(byte[] bytes, java.lang.String charset)
      Convert a byte array to a string; consistently uses \n line endings in java.
      static java.lang.String readString​(byte[] bytes, java.nio.charset.Charset charset)
      Convert a byte array to a string, consistently uses \n line endings in java.
      static java.lang.String readString​(java.io.InputStream stream)
      Convert an InputStream to a string; consistently uses \n line endings in java.
      static java.lang.String readString​(java.io.InputStream stream, java.lang.String charset)
      Convert an InputStream to a string; consistently uses \n line endings in java.
      static java.lang.String readString​(java.io.InputStream stream, java.nio.charset.Charset charset)
      Convert an InputStream to a string; consistently uses \n line endings in java.
      static java.lang.String readString​(java.io.Reader reader)
      Convert an Reader to a string; consistently uses \n line endings in java.
      static void writeString​(java.io.File file, java.lang.String value)
      Convert a \n string to a platform encoding.
      static void writeString​(java.io.OutputStream out, java.lang.String value)
      Convert a \n string to a platform encoding.
      static void writeString​(java.io.OutputStream out, java.lang.String charset, java.lang.String value)
      Convert a \n string to a platform encoding.
      static void writeString​(java.io.OutputStream out, java.nio.charset.Charset charset, java.lang.String value)
      Convert a \n string to a platform encoding.
      • Methods inherited from class java.lang.Object

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

      • copy

        public static void copy​(java.io.Reader reader,
                                java.lang.Appendable out)
                         throws java.io.IOException
        Copy a Reader to an Appendable.
        Parameters:
        reader - the Reader to copy from
        out - the Appendable to copy to
        Throws:
        java.io.IOException - if an error occurs
      • readString

        public static java.lang.String readString​(byte[] bytes)
        Convert a byte array to a string; consistently uses \n line endings in java. This uses a default UTF-8 charset.
        Parameters:
        bytes - the array of bytes to convert
        Returns:
        the converted string, with platform line endings converted to \n
      • readString

        public static java.lang.String readString​(byte[] bytes,
                                                  int offset,
                                                  int length)
        Convert a byte array to a string; consistently uses \n line endings in java. The conversion is limited to the specified offset/length pair, and uses a default UTF-8 charset.
        Parameters:
        bytes - the array of bytes to convert
        offset - the start of the conversion
        length - how many bytes to convert
        Returns:
        the converted string, with platform line endings converted to \n
      • readString

        public static java.lang.String readString​(byte[] bytes,
                                                  java.lang.String charset)
        Convert a byte array to a string; consistently uses \n line endings in java. The conversion is limited to the specified offset/length pair, and uses the requested charset to decode the bytes.
        Parameters:
        bytes - the array of bytes to convert
        charset - the charset to use to convert the raw bytes
        Returns:
        the converted string, with platform line endings converted to \n
      • readString

        public static java.lang.String readString​(byte[] bytes,
                                                  int offset,
                                                  int length,
                                                  java.lang.String charset)
        Convert a byte array to a string; consistently uses \n line endings in java. The conversion is limited to the specified offset/length pair, and uses the requested charset to decode the bytes.
        Parameters:
        bytes - the array of bytes to convert
        offset - the start of the conversion
        length - how many bytes to convert
        charset - the charset to use to convert the raw bytes
        Returns:
        the converted string, with platform line endings converted to \n
      • readString

        public static java.lang.String readString​(byte[] bytes,
                                                  java.nio.charset.Charset charset)
        Convert a byte array to a string, consistently uses \n line endings in java. The specified charset is used to decode the bytes.
        Parameters:
        bytes - the array of bytes to convert
        charset - the charset to use to convert the raw bytes
        Returns:
        the converted string, with platform line endings converted to \n
      • readString

        public static java.lang.String readString​(byte[] bytes,
                                                  int offset,
                                                  int length,
                                                  java.nio.charset.Charset charset)
        Convert a byte array to a string, consistently uses \n line endings in java. The conversion is limited to the specified offset/length pair, and uses the requested charset to decode the bytes.
        Parameters:
        bytes - the array of bytes to convert
        offset - the start of the conversion
        length - how many bytes to convert
        charset - the charset to use to convert the raw bytes
        Returns:
        the converted string, with platform line endings converted to \n
      • readString

        public static java.lang.String readString​(java.io.InputStream stream)
                                           throws java.io.IOException
        Convert an InputStream to a string; consistently uses \n line endings in java. This uses a default UTF-8 charset.
        Parameters:
        stream - the stream of bytes to convert
        Returns:
        the converted string, with platform line endings converted to \n
        Throws:
        java.io.IOException
      • readString

        public static java.lang.String readString​(java.io.InputStream stream,
                                                  java.lang.String charset)
                                           throws java.io.IOException
        Convert an InputStream to a string; consistently uses \n line endings in java. This uses a default UTF-8 charset.
        Parameters:
        stream - the stream of bytes to convert
        charset - the charset to use to convert the raw bytes
        Returns:
        the converted string, with platform line endings converted to \n
        Throws:
        java.io.IOException
      • readString

        public static java.lang.String readString​(java.io.InputStream stream,
                                                  java.nio.charset.Charset charset)
                                           throws java.io.IOException
        Convert an InputStream to a string; consistently uses \n line endings in java. This uses a default UTF-8 charset.
        Parameters:
        stream - the stream of bytes to convert
        charset - the charset to use to convert the raw bytes
        Returns:
        the converted string, with platform line endings converted to \n
        Throws:
        java.io.IOException
      • readString

        public static java.lang.String readString​(java.io.Reader reader)
                                           throws java.io.IOException
        Convert an Reader to a string; consistently uses \n line endings in java.
        Parameters:
        reader - the stream of characters convert
        Returns:
        the converted string, with platform line endings converted to \n
        Throws:
        java.io.IOException
      • writeString

        public static void writeString​(java.io.File file,
                                       java.lang.String value)
                                throws java.io.IOException
        Convert a \n string to a platform encoding. This uses a default UTF-8 charset.
        Parameters:
        file - where to write the converted bytes to
        value - the value to write
        Throws:
        java.io.IOException
      • writeString

        public static void writeString​(java.io.OutputStream out,
                                       java.lang.String value)
                                throws java.io.IOException
        Convert a \n string to a platform encoding. This uses a default UTF-8 charset.
        Parameters:
        out - where to write the converted bytes to
        value - the value to write
        Throws:
        java.io.IOException
      • writeString

        public static void writeString​(java.io.OutputStream out,
                                       java.lang.String charset,
                                       java.lang.String value)
                                throws java.io.IOException
        Convert a \n string to a platform encoding. This uses the specified charset to extract the raw bytes.
        Parameters:
        out - where to write the converted bytes to
        charset - the charset to use to convert the raw bytes
        value - the value to write
        Throws:
        java.io.IOException
      • writeString

        public static void writeString​(java.io.OutputStream out,
                                       java.nio.charset.Charset charset,
                                       java.lang.String value)
                                throws java.io.IOException
        Convert a \n string to a platform encoding. This uses the specified charset to extract the raw bytes.
        Parameters:
        out - where to write the converted bytes to
        charset - the charset to use to convert the raw bytes
        value - the value to write
        Throws:
        java.io.IOException