Class DefaultAsyncTemplateStorage

  • All Implemented Interfaces:
    de.dytanic.cloudnet.common.INameable, TemplateStorage, java.lang.AutoCloseable
    Direct Known Subclasses:
    RemoteTemplateStorage

    public abstract class DefaultAsyncTemplateStorage
    extends java.lang.Object
    implements TemplateStorage
    • Constructor Detail

      • DefaultAsyncTemplateStorage

        public DefaultAsyncTemplateStorage()
    • Method Detail

      • deploy

        public boolean deploy​(@NotNull
                              @NotNull java.nio.file.Path directory,
                              @NotNull
                              @NotNull ServiceTemplate target,
                              @Nullable
                              @Nullable java.util.function.Predicate<java.nio.file.Path> fileFilter)
        Description copied from interface: TemplateStorage
        Deploys the following directory files to the target template storage. If the given file filter is not null, method will apply every single file to the given file filter and only deploy files that were allowed by the filter.
        Specified by:
        deploy in interface TemplateStorage
        Parameters:
        directory - the directory to be deployed
        target - the template to be deployed to
        fileFilter - the filter for files that should be deployed
        Returns:
        whether it was copied successfully
      • deploy

        public boolean deploy​(@NotNull
                              @NotNull java.nio.file.Path directory,
                              @NotNull
                              @NotNull ServiceTemplate target)
        Description copied from interface: TemplateStorage
        Copies the given directory into the given template.
        Specified by:
        deploy in interface TemplateStorage
        Parameters:
        directory - the directory to be deployed
        target - the template to be deployed to
        Returns:
        whether it was copied successfully
      • deploy

        public boolean deploy​(@NotNull
                              @NotNull java.io.InputStream inputStream,
                              @NotNull
                              @NotNull ServiceTemplate target)
        Description copied from interface: TemplateStorage
        Copies the given stream into the given template.
        Specified by:
        deploy in interface TemplateStorage
        Parameters:
        inputStream - the zipped data to be deployed
        target - the template to be deployed to
        Returns:
        whether it was copied successfully
      • copy

        public boolean copy​(@NotNull
                            @NotNull ServiceTemplate template,
                            @NotNull
                            @NotNull java.nio.file.Path directory)
        Description copied from interface: TemplateStorage
        Copies the given template into the given directory
        Specified by:
        copy in interface TemplateStorage
        Parameters:
        template - the template to copy the files from
        directory - the target directory to copy the files to
        Returns:
        whether it was copied successfully
      • asZipInputStream

        @Nullable
        public @Nullable java.util.zip.ZipInputStream asZipInputStream​(@NotNull
                                                                       @NotNull ServiceTemplate template)
                                                                throws java.io.IOException
        Description copied from interface: TemplateStorage
        Gets a template into a ZipInputStream.
        Specified by:
        asZipInputStream in interface TemplateStorage
        Parameters:
        template - the template to be zipped
        Returns:
        a new ZipInputStream or null if it the template doesn't exist
        Throws:
        java.io.IOException - if an I/O error occurred
      • zipTemplate

        @Nullable
        public @Nullable java.io.InputStream zipTemplate​(@NotNull
                                                         @NotNull ServiceTemplate template)
                                                  throws java.io.IOException
        Description copied from interface: TemplateStorage
        Zips a template into an InputStream.
        Specified by:
        zipTemplate in interface TemplateStorage
        Parameters:
        template - the template to be zipped
        Returns:
        a new InputStream or null if it the template doesn't exist
        Throws:
        java.io.IOException - if an I/O error occurred
      • delete

        public boolean delete​(@NotNull
                              @NotNull ServiceTemplate template)
        Description copied from interface: TemplateStorage
        Deletes the given template if it exists.
        Specified by:
        delete in interface TemplateStorage
        Parameters:
        template - the template to be deleted
        Returns:
        whether the template was successfully deleted, false if it doesn't exists
      • create

        public boolean create​(@NotNull
                              @NotNull ServiceTemplate template)
        Description copied from interface: TemplateStorage
        Creates the given template if it doesn't exists.
        Specified by:
        create in interface TemplateStorage
        Parameters:
        template - the template to be deleted
        Returns:
        whether the template was successfully created, false if it already exists
      • has

        public boolean has​(@NotNull
                           @NotNull ServiceTemplate template)
        Description copied from interface: TemplateStorage
        Checks whether the given template exists.
        Specified by:
        has in interface TemplateStorage
        Parameters:
        template - the template to be checked
        Returns:
        whether the template exists or not
      • appendOutputStream

        @Nullable
        public @Nullable java.io.OutputStream appendOutputStream​(@NotNull
                                                                 @NotNull ServiceTemplate template,
                                                                 @NotNull
                                                                 @NotNull java.lang.String path)
                                                          throws java.io.IOException
        Description copied from interface: TemplateStorage
        Creates a new OutputStream that will append its content to the file at the given path. If the file at the given path doesn't exist, it will be created. To finish your modifications, you'll need to close the OutputStream.
        Specified by:
        appendOutputStream in interface TemplateStorage
        Parameters:
        template - the template where the target file is located at
        path - the path to the file relative to the template
        Returns:
        a new OutputStream or null if it couldn't be opened
        Throws:
        java.io.IOException - if an I/O error occurred
      • newOutputStream

        @Nullable
        public @Nullable java.io.OutputStream newOutputStream​(@NotNull
                                                              @NotNull ServiceTemplate template,
                                                              @NotNull
                                                              @NotNull java.lang.String path)
                                                       throws java.io.IOException
        Description copied from interface: TemplateStorage
        Creates a new OutputStream that will override its content to the file at the given path. If the file at the given path doesn't exist, it will be created. To finish your modifications, you'll need to close the OutputStream.
        Specified by:
        newOutputStream in interface TemplateStorage
        Parameters:
        template - the template where the target file is located at
        path - the path to the file relative to the template
        Returns:
        a new OutputStream or null if it couldn't be opened
        Throws:
        java.io.IOException - if an I/O error occurred
      • createFile

        public boolean createFile​(@NotNull
                                  @NotNull ServiceTemplate template,
                                  @NotNull
                                  @NotNull java.lang.String path)
                           throws java.io.IOException
        Description copied from interface: TemplateStorage
        Creates a new file in the given template at the given path if it doesn't exist.
        Specified by:
        createFile in interface TemplateStorage
        Parameters:
        template - the template where the target file is located at
        path - the path to the file relative to the template
        Returns:
        whether the file was created successfully, false if it already exists
        Throws:
        java.io.IOException - if an I/O error occurred
      • createDirectory

        public boolean createDirectory​(@NotNull
                                       @NotNull ServiceTemplate template,
                                       @NotNull
                                       @NotNull java.lang.String path)
                                throws java.io.IOException
        Description copied from interface: TemplateStorage
        Creates a new directory in the given template at the given path if it doesn't exist.
        Specified by:
        createDirectory in interface TemplateStorage
        Parameters:
        template - the template where the target file is located at
        path - the path to the directory relative to the template
        Returns:
        whether the directory was created successfully, false if it already exists
        Throws:
        java.io.IOException - if an I/O error occurred
      • hasFile

        public boolean hasFile​(@NotNull
                               @NotNull ServiceTemplate template,
                               @NotNull
                               @NotNull java.lang.String path)
                        throws java.io.IOException
        Description copied from interface: TemplateStorage
        Checks whether the given path/directory exists in the given template, it doesn't matter if it is a directory or a file.
        Specified by:
        hasFile in interface TemplateStorage
        Parameters:
        template - the template where the target file is located at
        path - the path to the file relative to the template
        Returns:
        whether the file exists
        Throws:
        java.io.IOException - if an I/O error occurred
      • deleteFile

        public boolean deleteFile​(@NotNull
                                  @NotNull ServiceTemplate template,
                                  @NotNull
                                  @NotNull java.lang.String path)
                           throws java.io.IOException
        Description copied from interface: TemplateStorage
        Deletes a file in the given template at the given path if it doesn't exist.
        Specified by:
        deleteFile in interface TemplateStorage
        Parameters:
        template - the template where the target file is located at
        path - the path to the file relative to the template
        Returns:
        whether the file was deleted successfully, false if it already exists
        Throws:
        java.io.IOException - if an I/O error occurred
      • newInputStream

        @Nullable
        public @Nullable java.io.InputStream newInputStream​(@NotNull
                                                            @NotNull ServiceTemplate template,
                                                            @NotNull
                                                            @NotNull java.lang.String path)
                                                     throws java.io.IOException
        Description copied from interface: TemplateStorage
        Creates a new InputStream with the data of the file at the given path in the given template.
        Specified by:
        newInputStream in interface TemplateStorage
        Parameters:
        template - the template where the target file is located at
        path - the path to the file relative to the template
        Returns:
        the new InputStream or null if the file doesn't exist/is a directory
        Throws:
        java.io.IOException - if an I/O error occurred
      • getFileInfo

        @Nullable
        public @Nullable FileInfo getFileInfo​(@NotNull
                                              @NotNull ServiceTemplate template,
                                              @NotNull
                                              @NotNull java.lang.String path)
                                       throws java.io.IOException
        Description copied from interface: TemplateStorage
        Retrieves information about a specified file/directory.
        Specified by:
        getFileInfo in interface TemplateStorage
        Parameters:
        template - the template where the target file is located at
        path - the path to the file relative to the template
        Returns:
        the FileInfo or null if the file/directory doesn't exist
        Throws:
        java.io.IOException - if an I/O error occurred
      • listFiles

        public FileInfo[] listFiles​(@NotNull
                                    @NotNull ServiceTemplate template,
                                    @NotNull
                                    @NotNull java.lang.String dir,
                                    boolean deep)
                             throws java.io.IOException
        Description copied from interface: TemplateStorage
        Lists all files in the given directory.
        Specified by:
        listFiles in interface TemplateStorage
        Parameters:
        template - the template where the target file is located at
        dir - the directory
        deep - whether the contents of sub directories should also be discovered
        Returns:
        a list of all files in the given directory or null if the given directory doesn't exist/is not a directory
        Throws:
        java.io.IOException - if an I/O error occurred
      • listFiles

        public FileInfo[] listFiles​(@NotNull
                                    @NotNull ServiceTemplate template,
                                    boolean deep)
                             throws java.io.IOException
        Description copied from interface: TemplateStorage
        Lists all files in the root directory of the template.
        Specified by:
        listFiles in interface TemplateStorage
        Parameters:
        template - the template where the target file is located at
        deep - whether the contents of sub directories should also be discovered
        Returns:
        a list of all files in the given directory or null if the given directory doesn't exist/is not a directory
        Throws:
        java.io.IOException - if an I/O error occurred
      • getTemplates

        @NotNull
        public @NotNull java.util.Collection<ServiceTemplate> getTemplates()
        Description copied from interface: TemplateStorage
        Gets a list of all templates that exist in this storage. Modifications to the collection won't have any effect.
        Specified by:
        getTemplates in interface TemplateStorage
        Returns:
        a list of all templates
      • close

        public void close()
                   throws java.io.IOException
        Description copied from interface: TemplateStorage
        Closes this storage, after it has been closed, no more interaction to this storage should be done and might lead to errors.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface TemplateStorage
        Throws:
        java.io.IOException - if an I/O error occurred