Interface Resource

    • Field Detail

      • ALL_FILE_PATTERN

        static final Pattern ALL_FILE_PATTERN
        The constant ALL_FILE_PATTERN.
    • Method Detail

      • append

        default Resource append​(String content)
                         throws IOException

        Appends the given string content to the resource.

        Parameters:
        content - The content to append
        Returns:
        the resource
        Throws:
        IOException - the io exception
      • append

        Resource append​(byte[] byteArray)
                 throws IOException

        Appends the given byte array content to the resource.

        Parameters:
        byteArray - The content to append
        Returns:
        the resource
        Throws:
        IOException - the io exception
      • asFile

        Optional<File> asFile()
        Gets the resource as a File.
        Returns:
        A File representing the resource.
      • asPath

        default Optional<Path> asPath()
        As path optional.
        Returns:
        the optional
      • asURI

        Optional<URI> asURI()
        As uri optional.
        Returns:
        the optional
      • asURL

        default Optional<URL> asURL()
        Gets the resource as a URL.
        Returns:
        A URL representing the resource.
      • baseName

        String baseName()
        Gets the name (file name or directory name) of this resource.
        Returns:
        The name of the file or directory
      • canRead

        boolean canRead()
        Returns true if the resource is readable, false if not.
        Returns:
        True if can read from the resource
      • canWrite

        boolean canWrite()
        Returns true if the resource is writable, false if not.
        Returns:
        True if can write to the resource
      • childIterator

        default Iterator<Resource> childIterator​(String pattern,
                                                 boolean recursive)
        Iterator over the children
        Parameters:
        pattern - The pattern to determine what files we want
        recursive - should we iterator recursively?
        Returns:
        An iterator over the children
      • childIterator

        default Iterator<Resource> childIterator​(boolean recursive)
        Iterator over the children
        Parameters:
        recursive - should we iterator recursively?
        Returns:
        An iterator over the children
      • compressed

        Resource compressed()
        Sets is compressed.
        Returns:
        the resource
      • copy

        default void copy​(Resource copyTo)
                   throws IOException
        Copies the contents of this resource to another
        Parameters:
        copyTo - The resource to copy to
        Throws:
        IOException - Something went wrong copying.
      • delete

        default boolean delete()
        Deletes the resource
        Returns:
        true if the deletion was successful
      • delete

        default boolean delete​(boolean recursively)
        Deletes the resource
        Parameters:
        recursively - true if should recursively delete everything under this resource
        Returns:
        true if the deletion was successful
      • deleteOnExit

        default Resource deleteOnExit()
        Deletes the resource on ext
        Returns:
        the resource
      • descriptor

        String descriptor()
        Descriptor string.
        Returns:
        The string representation of the resource with protocol
      • exists

        boolean exists()
        Exists boolean.
        Returns:
        True if the resource exists, False if the resource does not exist.
      • getCharset

        Charset getCharset()

        Gets the charset for reading and writing. The charset if not specified will be automatically determined during read.

        Returns:
        The charset used for writing and default when reading
      • getChild

        Resource getChild​(String relativePath)

        Creates a new Resource that is relative to this resource.

        Parameters:
        relativePath - The relative path for the new resource.
        Returns:
        A new resource that is relative to this resource.
      • getChildren

        default List<Resource> getChildren()

        Lists all the resources that are directly under this resource.

        Returns:
        A list of all the resources one level under this resource.
      • getChildren

        default List<Resource> getChildren​(boolean recursive)

        Lists all the resources that are directly under this resource.

        Parameters:
        recursive - Gets all children recursively
        Returns:
        A list of all the resources one level under this resource.
      • getChildren

        default List<Resource> getChildren​(String pattern)

        Lists all the resources that are directly under this resource.

        Parameters:
        pattern - The file matching pattern
        Returns:
        A list of all the resources one level under this resource.
      • getChildren

        default List<Resource> getChildren​(String pattern,
                                           boolean recursive)

        Lists all the resources that are directly under this resource.

        Parameters:
        pattern - The file matching pattern
        recursive - Gets all children recursively
        Returns:
        A list of all the resources one level under this resource.
      • getChildren

        default List<Resource> getChildren​(Pattern pattern,
                                           boolean recursive)

        Lists all the resources that are directly under this resource.

        Parameters:
        pattern - The file matching pattern
        recursive - Gets all children recursively
        Returns:
        A list of all the resources one level under this resource.
      • getParent

        Resource getParent()
        Gets parent.
        Returns:
        The parent resource (directory for file, parent directory for a directory)
      • inputStream

        InputStream inputStream()
                         throws IOException

        Opens an input stream over this resource.

        Returns:
        An input stream over this resource.
        Throws:
        IOException - the io exception
      • isCompressed

        boolean isCompressed()
        Is compressed.
        Returns:
        True if the resources is gzipped compressed
      • isDirectory

        boolean isDirectory()
        Is directory.
        Returns:
        True if the resource is a directory
      • outputStream

        OutputStream outputStream()
                           throws IOException

        Opens an output stream over this resource.

        Returns:
        An output stream over this resource.
        Throws:
        IOException - the io exception
      • path

        String path()
        Gets path in the same mannar as File.getPath()
        Returns:
        The full path to the resource including name
      • readBytes

        default byte[] readBytes()
                          throws IOException

        Reads the resource into an array of bytes.

        Returns:
        An array of bytes representing the content of the resource.
        Throws:
        IOException - the io exception
      • readLines

        default List<String> readLines()
                                throws IOException
        Reads the complete resource in as text breaking it into lines based on the newline character
        Returns:
        A list of string representing the contents of the file.
        Throws:
        IOException - the io exception
      • readObject

        default <T> T readObject()
                          throws IOException
        Deserializes an object from a resource
        Type Parameters:
        T - the type parameter
        Returns:
        the t
        Throws:
        IOException - the exception
      • readToString

        default String readToString()
                             throws IOException

        Reads in the resource as a String using UTF-8.

        Returns:
        A string representing the contents of the file.
        Throws:
        IOException - the io exception
      • reader

        default Reader reader()
                       throws IOException
        Opens a reader using guessing the encoding and falling back to the default on the resource.
        Returns:
        A reader
        Throws:
        IOException - the io exception
      • setCharset

        Resource setCharset​(Charset charset)

        Sets the charset for reading and writing.

        Parameters:
        charset - The charset to use
        Returns:
        the charset
      • setCompression

        Resource setCompression​(Compression compression)
        Sets the compression algorithm.
        Parameters:
        compression - the compression algorithm
        Returns:
        this Resource
      • setIsCompressed

        Resource setIsCompressed​(boolean isCompressed)
        Sets is compressed.
        Parameters:
        isCompressed - the is compressed
        Returns:
        the is compressed
      • uncompressed

        Resource uncompressed()
        Uncompressed resource.
        Returns:
        the resource
      • write

        default Resource write​(byte[] content)
                        throws IOException

        Writes the given byte array to the resource overwriting any existing content.

        Parameters:
        content - The content to write.
        Returns:
        the resource
        Throws:
        IOException - the io exception
      • write

        default Resource write​(String content)
                        throws IOException

        Writes the given string to the resource overwriting any existing content.

        Parameters:
        content - The content to write.
        Returns:
        the resource
        Throws:
        IOException - the io exception
      • writeObject

        default Resource writeObject​(Object object)
                              throws IOException
        Serializes an object to the resource using Java Serialization.
        Parameters:
        object - The object to serialize
        Returns:
        the resource
        Throws:
        IOException - the exception
      • writer

        default Writer writer()
                       throws IOException
        Opens a writer for writing for writing to the resource
        Returns:
        A writer
        Throws:
        IOException - the io exception