IOUtils (Grails 6.0.0)

Package: grails.io

## [Groovy] Class IOUtils

- grails.io.IOUtils

-     @groovy.transform.CompileStatic
      class IOUtils
      extends SpringIOUtils

  Utility methods for performing I/O operations.

  Authors:
    Graeme Rocher
  Since:
    2.4

- - ### Nested Class Summary

    Nested classes
    Modifiers | Name | Description
    --- | --- | ---
    `class` | `IOUtils.1` |

  - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static java.lang.String` | `RESOURCE_JAR_PREFIX` |
    `static java.lang.String` | `RESOURCE_WAR_PREFIX` |
    `private static java.lang.String` | `applicationDirectory` |

  - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class SpringIOUtils` | `BUFFER_SIZE, CHARS, algorithms, saxParserFactory`

  - ### Constructor Summary

    Constructors
    Constructor and description
    `IOUtils ()`

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `static void` | `copy(java.io.InputStream input, java.io.Writer output, java.lang.String encoding)` Copy an InputStream to the given writer with the given encoding
    `` | `static java.lang.String` | `findApplicationDirectory()` Finds the directory where the Application class is contained
    `` | `static java.io.File` | `findApplicationDirectoryFile()`
    `` | `static java.io.File` | `findApplicationDirectoryFile(java.lang.Class targetClass)` Finds the application directory for the given class
    `` | `static java.net.URL` | `findClassResource(java.lang.Class targetClass)` Returns the URL resource for the location on disk of the given class or null if it cannot be found
    `` | `private static java.io.File` | `findGrailsApp(java.io.File file)`
    `` | `static java.io.File` | `findJarFile(java.lang.Class targetClass)` Finds a JAR file for the given class
    `` | `static java.io.File` | `findJarFile(Resource resource)` Finds a JAR for the given resource
    `` | `static java.io.File` | `findJarFile(java.net.URL resource)` Finds a JAR for the given resource
    `` | `static java.net.URL` | `findJarResource(java.lang.Class targetClass)` Returns the URL resource for the location on disk of the given class or null if it cannot be found
    `` | `static java.net.URL` | `findResourceRelativeToClass(java.lang.Class targetClass, java.lang.String path)` Finds a URL within a JAR relative (from the root) to the given class
    `` | `static java.net.URL` | `findRootResource(java.lang.Class targetClass)` Returns a URL that represents the root classpath resource where the given class was loaded from
    `` | `static java.net.URL` | `findRootResourcesURL(java.lang.Class targetClass)` This method differs from findRootResource(java.lang.Class) in that it will find the root URL where to load resources defined in src/main/resources
    `` | `static java.io.File` | `findSourceFile(java.lang.String className)` Finds a source file for the given class name
    `` | `static boolean` | `isWithinBinary(java.net.URL url)` Whether the given URL is within a binary like a JAR or WAR file
    `` | `static java.io.BufferedInputStream` | `openStream(java.io.File file)` Gracefully opens a stream for a file, throwing exceptions where appropriate.
    `` | `static java.lang.String` | `toString(java.io.Reader reader)` Convert a reader to a String, reading the data from the reader
    `` | `static java.lang.String` | `toString(java.io.InputStream stream, java.lang.String encoding)` Convert a stream to a String, reading the data from the stream

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class SpringIOUtils` | `addAll, byteArrayToHexString, closeQuietly, compute, computeChecksum, copy, copy, copy, copy, copy, copy, copy, copyAll, copyToByteArray, copyToByteArray, copyToString, createParserFactory, createXmlSlurper, getMessageDigest, newSAXParser`

- - ### Field Detail

    - #### public static final java.lang.String RESOURCE_JAR_PREFIX

    - #### public static final java.lang.String RESOURCE_WAR_PREFIX

    - #### private static java.lang.String applicationDirectory

  - ### Constructor Detail

    - #### IOUtils()

  - ### Method Detail

    - #### static void copy(java.io.InputStream input, java.io.Writer output, java.lang.String encoding)

      Copy an InputStream to the given writer with the given encoding

      Parameters:
        `input` - The input
        `output` - The writer
        `encoding` - The encoding

    - #### @groovy.transform.Memoized static java.lang.String findApplicationDirectory()

      Finds the directory where the Application class is contained

      Returns:
        The application directory

    - #### @groovy.transform.Memoized static java.io.File findApplicationDirectoryFile()

    - #### static java.io.File findApplicationDirectoryFile(java.lang.Class targetClass)

      Finds the application directory for the given class

      Parameters:
        `targetClass` - The target class
      Returns:
        The application directory or null if it can't be found

    - #### static java.net.URL findClassResource(java.lang.Class targetClass)

      Returns the URL resource for the location on disk of the given class or null if it cannot be found

      Parameters:
        `targetClass` - The target class
      Returns:
        The URL to class file or null

    - #### private static java.io.File findGrailsApp(java.io.File file)

    - #### static java.io.File findJarFile(java.lang.Class targetClass)

      Finds a JAR file for the given class

      Parameters:
        `targetClass` - The target class
      Returns:
        The JAR file

    - #### static java.io.File findJarFile(Resource resource)

      Finds a JAR for the given resource

      Parameters:
        `resource` - The resource
      Returns:
        The JAR file or null if it can't be found

    - #### static java.io.File findJarFile(java.net.URL resource)

      Finds a JAR for the given resource

      Parameters:
        `resource` - The resource
      Returns:
        The JAR file or null if it can't be found

    - #### static java.net.URL findJarResource(java.lang.Class targetClass)

      Returns the URL resource for the location on disk of the given class or null if it cannot be found

      Parameters:
        `targetClass` - The target class
      Returns:
        The URL to class file or null

    - #### static java.net.URL findResourceRelativeToClass(java.lang.Class targetClass, java.lang.String path)

      Finds a URL within a JAR relative (from the root) to the given class @return

      Parameters:
        targetClass
        path

    - #### static java.net.URL findRootResource(java.lang.Class targetClass)

      Returns a URL that represents the root classpath resource where the given class was loaded from

      Parameters:
        `targetClass` - The target class
      Returns:
        The URL to class file or null

    - #### static java.net.URL findRootResourcesURL(java.lang.Class targetClass)

      This method differs from findRootResource(java.lang.Class) in that it will find the root URL where to load resources defined in src/main/resources At development time this with be build/main/resources, but in production it will be relative to the class. @return

      Parameters:
        targetClass
        path

    - #### @groovy.transform.Memoized static java.io.File findSourceFile(java.lang.String className)

      Finds a source file for the given class name

      Parameters:
        `className` - The class name
      Returns:
        The source file

    - #### static boolean isWithinBinary(java.net.URL url)

      Whether the given URL is within a binary like a JAR or WAR file

      Parameters:
        `url` - The URL
      Returns:
        True if it is

    - #### static java.io.BufferedInputStream openStream(java.io.File file)

      Gracefully opens a stream for a file, throwing exceptions where appropriate. Based off the commons-io method

      Parameters:
        `file` - The file
      Returns:
        The stream

    - #### static java.lang.String toString(java.io.Reader reader)

      Convert a reader to a String, reading the data from the reader

      Parameters:
        `reader` - The reader
      Returns:
        The string

    - #### static java.lang.String toString(java.io.InputStream stream, java.lang.String encoding)

      Convert a stream to a String, reading the data from the stream

      Parameters:
        `stream` - The stream
      Returns:
        The string