Package com.castlabs.utils

# Class FileHelper

java.lang.Object
com.castlabs.utils.FileHelper

public class FileHelper extends Object
The file helper contains utility functions to work with files and folders, including recursive listings, recursive deletes and file and folder copy.

Since:
  2.0.0

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static String`
  `convertToLocalFilePath(Uri uri)`
  Converts remote URI to local file path
  `static void`
  `copy(File sourceLocation, File targetLocation)`
  Copies files and directories.
  `static String`
  `decodeApid(String encodedApi)`
  Decodes the given apid
  `static void`
  `deleteRecursive(File fileOrDirectory)`
  Recursively delete the given file or directory
  `static String`
  `encodeApid(String apid)`
  Encodes teh given apid
  `static String`
  `encodeFileName(String fileName)`
  Remove illegal characters from file names
  `static List<File>`
  `listFiles(File rootDir, FileFilter filter, boolean recursive)`
  List all the files in a given folder.
  `static List<String>`
  `readLines(File file)`
  Reads all lines from the specified file and returns them as a list of strings.

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

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

- ## Method Details

  - ### encodeFileName

    public static String encodeFileName(String fileName)
    Remove illegal characters from file names
    Parameters:
      `fileName` - the file name
    Returns:
      the cleaned file name

  - ### listFiles

    public static List<File> listFiles(File rootDir, FileFilter filter, boolean recursive)
    List all the files in a given folder. If the root folder is not a directory or does not exists, an empty list is returned. If a file filter is given here, the filter is only applied to files in the result list. It is not used to filter folder during recursive search.
    Parameters:
      `rootDir` - the root folder
      `filter` - the file filter applied to limit the results (optional)
      `recursive` - if true, the folder is searched recursively
    Returns:
      list of files in the given root folder

  - ### copy

    public static void copy(File sourceLocation, File targetLocation) throws IOException
    Copies files and directories.
    Parameters:
      `sourceLocation` - the source file or directory
      `targetLocation` - the target
    Throws:
      `IOException` - in case an error occurred

  - ### encodeApid

    public static String encodeApid(String apid)
    Encodes teh given apid
    Parameters:
      `apid` - the apid
    Returns:
      encoded apid

  - ### decodeApid

    public static String decodeApid(String encodedApi)
    Decodes the given apid
    Parameters:
      `encodedApi` - the encoded apid
    Returns:
      the decoded apid

  - ### deleteRecursive

    public static void deleteRecursive(File fileOrDirectory)
    Recursively delete the given file or directory
    Parameters:
      `fileOrDirectory` - the file or directory

  - ### readLines

    public static List<String> readLines(File file) throws IOException
    Reads all lines from the specified file and returns them as a list of strings.
    Parameters:
      `file` - the source file
    Returns:
      list of lines of the given file
    Throws:
      `IOException` - in case of an error while reading the file
    Since:
      2.1.7

  - ### convertToLocalFilePath

    @NonNull public static String convertToLocalFilePath(@NonNull Uri uri)
    Converts remote URI to local file path
    Parameters:
      `uri` - the URI
    Returns:
      local file path