Package org.apache.any23.util

## Class FileUtils

- java.lang.Object
- - org.apache.any23.util.FileUtils

-     public class FileUtils
      extends Object

  Utility class for handling files.
  Author:
    Michele Mostarda (mostarda@fbk.eu)

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static void` | `cp​(File src, File dest)` | Copies a file `src` to the `dest`.
    `static void` | `cp​(InputStream is, File dest)` | Copies the content of the input stream within the given dest file.
    `static void` | `dumpContent​(File f, String content)` | Dumps the given string within a file.
    `static void` | `dumpContent​(File f, Throwable t)` | Dumps the stack trace of the given exception into the specified file.
    `static File[]` | `listFilesRecursively​(File dir, FilenameFilter filenameFilter)` | Lists the content of a dir applying the specified filter.
    `static File` | `mv​(File target, File dest)` | Moves a `target` file to a new `dest` location.
    `static String` | `readFileContent​(File f)` | Returns the content of a file a single string.
    `static String[]` | `readFileLines​(File f)` | Returns all the lines of a file.
    `static String` | `readResourceContent​(Class clazz, String resource)` | Reads a resource file and returns the content as a string.
    `static String` | `readResourceContent​(String resource)` | Reads a resource file and returns the content as a string.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### mv

          public static File mv​(File target,
                                File dest)

      Moves a `target` file to a new `dest` location.
      Parameters:
        `target` - file to be moved.
        `dest` - dest dir.
      Returns:
        destination file.

    - #### cp

          public static void cp​(InputStream is,
                                File dest)

      Copies the content of the input stream within the given dest file. The dest file must not exist.
      Parameters:
        `is` - `InputStream` to copy
        `dest` - detination to copy it to.

    - #### cp

          public static void cp​(File src,
                                File dest)
                         throws FileNotFoundException

      Copies a file `src` to the `dest`.
      Parameters:
        `src` - source file.
        `dest` - destination file.
      Throws:
        `FileNotFoundException` - if file cannot be copied or created.

    - #### dumpContent

          public static void dumpContent​(File f,
                                         String content)
                                  throws IOException

      Dumps the given string within a file.
      Parameters:
        `f` - file target.
        `content` - content to be dumped.
      Throws:
        `IOException` - if there is an error dumping the content

    - #### dumpContent

          public static void dumpContent​(File f,
                                         Throwable t)
                                  throws IOException

      Dumps the stack trace of the given exception into the specified file.
      Parameters:
        `f` - file to generate dump.
        `t` - exception to be dumped.
      Throws:
        `IOException` - if there is an error dumping the content

    - #### readResourceContent

          public static String readResourceContent​(Class clazz,
                                                   String resource)
                                            throws IOException

      Reads a resource file and returns the content as a string.
      Parameters:
        `clazz` - the class to use load the resource.
        `resource` - the resource to be load.
      Returns:
        the string representing the file content.
      Throws:
        `IOException` - if there is an error loading the resource

    - #### readResourceContent

          public static String readResourceContent​(String resource)
                                            throws IOException

      Reads a resource file and returns the content as a string.
      Parameters:
        `resource` - the resource to be load.
      Returns:
        the string representing the file content.
      Throws:
        `IOException` - if there is an error loading the resource

    - #### readFileContent

          public static String readFileContent​(File f)
                                        throws IOException

      Returns the content of a file a single string.
      Parameters:
        `f` - the file to read.
      Returns:
        the content of file.
      Throws:
        `IOException` - if an error occurs while locating or accessing the file.

    - #### readFileLines

          public static String[] readFileLines​(File f)
                                        throws IOException

      Returns all the lines of a file.
      Parameters:
        `f` - the file to read.
      Returns:
        a not `null` array with not `null` line strings.
      Throws:
        `IOException` - if an error occurs while locating or accessing the file.

    - #### listFilesRecursively

          public static File[] listFilesRecursively​(File dir,
                                                    FilenameFilter filenameFilter)

      Lists the content of a dir applying the specified filter.
      Parameters:
        `dir` - directory root.
        `filenameFilter` - filter to be applied.
      Returns:
        list of matching files.