Class FileHelper

    • Method Detail

      • saveFile

        public Map<String,​ObjectsaveFile​(String fileURI,
                                                 String text)
                                          throws IOException
        Saves text to given file in UTF-8 format
        Parameters:
        fileURI - the file URI. Must point to an existing file.
        text - the UTF-8 file content
        Returns:
        A result map.
        Throws:
        IOException - If an error occurred while saving
      • addFolder

        public Map<String,​ObjectaddFolder​(String parentURI,
                                                  String name,
                                                  boolean renameIfExists)
                                           throws IOException
        Create a folder
        Parameters:
        parentURI - the parent URI, relative to the root
        name - the name of the new folder to create
        renameIfExists - true if the folder have to be renamed if the folder with same name already exits.
        Returns:
        The result Map with the name and uri of created folder, or a boolean "success" to false if an error occurs.
        Throws:
        IOException - If an error occurred adding the folder
      • addOrUpdateFile

        public Map<String,​ObjectaddOrUpdateFile​(Part part,
                                                        FileSource parentDir,
                                                        String mode,
                                                        boolean unzip)
                                                 throws IOException
        Add or update a file
        Parameters:
        part - The file multipart to upload
        parentDir - The parent directory
        mode - The insertion mode: 'add-rename' or 'update' or null.
        unzip - true to unzip .zip file
        Returns:
        the result map
        Throws:
        IOException - If an error occurred manipulating the file
      • delete

        public void delete​(Path path,
                           DirectoryStream.Filter<Path> fileFilter,
                           boolean recursiveDelete,
                           boolean deleteEmptyDirs)
                    throws IOException
        Delete all files corresponding to the file filter into the file tree.
        Parameters:
        path - the path to delete (can be a file or a directory)
        fileFilter - the file filter to apply
        recursiveDelete - if true, the file tree will be explored to delete files
        deleteEmptyDirs - if true, empty dirs will be deleted
        Throws:
        IOException - if an error occured while exploring or deleting files
      • renameFile

        public Map<String,​ObjectrenameFile​(String fileUri,
                                                   String name)
                                            throws IOException
        Rename a file or a folder
        Parameters:
        fileUri - the relative URI of the file or folder to rename
        name - the new name of the file/folder
        Returns:
        The result Map with the name, path of the renamed file/folder, or a boolean "already-exist" is a file/folder already exists with this name.
        Throws:
        IOException - if an error occurs while renaming the file/folder
      • hasChild

        public boolean hasChild​(String parentUri,
                                String name)
                         throws IOException
        Tests if a file/folder with given name exists
        Parameters:
        parentUri - the parent folder URI
        name - the name of the child
        Returns:
        true if the file exists
        Throws:
        IOException - if an error occurred
      • copySource

        public Map<String,​ObjectcopySource​(String srcUri,
                                                   String parentTargetUri)
                                            throws IOException
        Copy a file or folder
        Parameters:
        srcUri - The URI of file/folder to copy
        parentTargetUri - The URI of parent target file
        Returns:
        a result map with the name and uri of copied file in case of success.
        Throws:
        IOException - If an error occured manipulating the source
      • moveSource

        public Map<String,​ObjectmoveSource​(String srcUri,
                                                   String parentTargetUri)
                                            throws IOException
        Move a file or folder
        Parameters:
        srcUri - The URI of file/folder to move
        parentTargetUri - The URI of parent target file
        Returns:
        a result map with the name and uri of moved file in case of success.
        Throws:
        IOException - If an error occurred manipulating the source
      • moveParameterFile

        public Map<String,​ObjectmoveParameterFile​(String srcRelPath,
                                                          String parentRelPath)
                                                   throws IOException
        Move a file or folder inside a given directory
        Parameters:
        srcRelPath - The relative URI of file/folder to move
        parentRelPath - The URI relative of parent target file
        Returns:
        a result map with the name and uri of moved file in case of success.
        Throws:
        IOException - If an error occurred manipulating the source