Class Resource

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, ResourceFactory
    Direct Known Subclasses:
    EmptyResource, FileResource, PathResource, ResourceCollection, URLResource

    @Deprecated(since="2021-05-27")
    public abstract class Resource
    extends java.lang.Object
    implements ResourceFactory, java.io.Closeable
    Deprecated.
    The Eclipse Jetty and Apache Felix Http Jetty packages are no longer supported.
    Abstract resource class.

    This class provides a resource abstraction, where a resource may be a file, a URL or an entry in a jar file.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static boolean __defaultUseCaches
      Deprecated.
       
    • Constructor Summary

      Constructors 
      Constructor Description
      Resource()
      Deprecated.
       
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      abstract Resource addPath​(java.lang.String path)
      Deprecated.
      Returns the resource contained inside the current resource with the given name.
      abstract void close()
      Deprecated.
      Release any temporary resources held by the resource.
      void copyTo​(java.io.File destination)
      Deprecated.
      Copy the Resource to the new destination file.
      abstract boolean delete()
      Deprecated.
      Deletes the given resource
      java.lang.String encode​(java.lang.String uri)
      Deprecated.
      use URIUtil or UrlEncoded instead
      abstract boolean exists()
      Deprecated.
       
      java.net.URI getAlias()
      Deprecated.
       
      java.util.Collection<Resource> getAllResources()
      Deprecated.
       
      java.lang.Object getAssociate()
      Deprecated.
       
      static boolean getDefaultUseCaches()
      Deprecated.
       
      abstract java.io.File getFile()
      Deprecated.
      File representing the given resource.
      abstract java.io.InputStream getInputStream()
      Deprecated.
      Input stream to the resource
      java.lang.String getListHTML​(java.lang.String base, boolean parent)
      Deprecated.
      use getListHTML(String, boolean, String) instead and supply raw query string.
      java.lang.String getListHTML​(java.lang.String base, boolean parent, java.lang.String query)
      Deprecated.
      Get the resource list as a HTML directory listing.
      abstract java.lang.String getName()
      Deprecated.
      The name of the resource.
      abstract java.nio.channels.ReadableByteChannel getReadableByteChannel()
      Deprecated.
      Readable ByteChannel for the resource.
      Resource getResource​(java.lang.String path)
      Deprecated.
      Get a resource from within this resource.
      java.net.URI getURI()
      Deprecated.
      URI representing the resource.
      abstract java.net.URL getURL()
      Deprecated.
      use {getURI().toURL() instead.
      java.lang.String getWeakETag()
      Deprecated.
      Generate a weak ETag reference for this Resource.
      java.lang.String getWeakETag​(java.lang.String suffix)
      Deprecated.
       
      boolean isAlias()
      Deprecated.
       
      abstract boolean isContainedIn​(Resource r)
      Deprecated.
       
      static boolean isContainedIn​(Resource r, Resource containingResource)
      Deprecated.
       
      abstract boolean isDirectory()
      Deprecated.
       
      boolean isSame​(Resource resource)
      Deprecated.
      Return true if the passed Resource represents the same resource as the Resource.
      abstract long lastModified()
      Deprecated.
      Time resource was last modified.
      abstract long length()
      Deprecated.
      Length of the resource.
      abstract java.lang.String[] list()
      Deprecated.
      list of resource names contained in the given resource.
      static Resource newClassPathResource​(java.lang.String resource)
      Deprecated.
      Find a classpath resource.
      static Resource newClassPathResource​(java.lang.String name, boolean useCaches, boolean checkParents)
      Deprecated.
      Find a classpath resource.
      static Resource newResource​(java.io.File file)
      Deprecated.
       
      static Resource newResource​(java.lang.String resource)
      Deprecated.
      Construct a resource from a string.
      static Resource newResource​(java.lang.String resource, boolean useCaches)
      Deprecated.
      Construct a resource from a string.
      static Resource newResource​(java.net.URI uri)
      Deprecated.
      Construct a resource from a uri.
      static Resource newResource​(java.net.URL url)
      Deprecated.
      Construct a resource from a url.
      static Resource newResource​(java.nio.file.Path path)
      Deprecated.
      Construct a Resource from provided path
      static Resource newSystemResource​(java.lang.String resource)
      Deprecated.
      Construct a system resource from a string.
      void release()
      Deprecated.
      abstract boolean renameTo​(Resource dest)
      Deprecated.
      Rename the given resource
      void setAssociate​(java.lang.Object o)
      Deprecated.
       
      static void setDefaultUseCaches​(boolean useCaches)
      Deprecated.
      Change the default setting for url connection caches.
      static java.net.URL toURL​(java.io.File file)
      Deprecated.
      Generate a properly encoded URL from a File instance.
      void writeTo​(java.io.OutputStream out, long start, long count)
      Deprecated.
       
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • __defaultUseCaches

        public static boolean __defaultUseCaches
        Deprecated.
    • Constructor Detail

      • Resource

        public Resource()
        Deprecated.
    • Method Detail

      • setDefaultUseCaches

        public static void setDefaultUseCaches​(boolean useCaches)
        Deprecated.
        Change the default setting for url connection caches. Subsequent URLConnections will use this default.
        Parameters:
        useCaches - true to enable URL connection caches, false otherwise.
      • getDefaultUseCaches

        public static boolean getDefaultUseCaches()
        Deprecated.
      • newResource

        public static Resource newResource​(java.net.URI uri)
                                    throws java.net.MalformedURLException
        Deprecated.
        Construct a resource from a uri.
        Parameters:
        uri - A URI.
        Returns:
        A Resource object.
        Throws:
        java.net.MalformedURLException - Problem accessing URI
      • newResource

        public static Resource newResource​(java.net.URL url)
        Deprecated.
        Construct a resource from a url.
        Parameters:
        url - A URL.
        Returns:
        A Resource object.
      • newResource

        public static Resource newResource​(java.lang.String resource)
                                    throws java.io.IOException
        Deprecated.
        Construct a resource from a string.
        Parameters:
        resource - A URL or filename.
        Returns:
        A Resource object.
        Throws:
        java.net.MalformedURLException - Problem accessing URI
        java.io.IOException
      • newResource

        public static Resource newResource​(java.lang.String resource,
                                           boolean useCaches)
                                    throws java.io.IOException
        Deprecated.
        Construct a resource from a string.
        Parameters:
        resource - A URL or filename.
        useCaches - controls URLConnection caching
        Returns:
        A Resource object.
        Throws:
        java.net.MalformedURLException - Problem accessing URI
        java.io.IOException
      • newResource

        public static Resource newResource​(java.io.File file)
        Deprecated.
      • newResource

        public static Resource newResource​(java.nio.file.Path path)
        Deprecated.
        Construct a Resource from provided path
        Parameters:
        path - the path
        Returns:
        the Resource for the provided path
        Since:
        9.4.10
      • newSystemResource

        public static Resource newSystemResource​(java.lang.String resource)
                                          throws java.io.IOException
        Deprecated.
        Construct a system resource from a string. The resource is tried as classloader resource before being treated as a normal resource.
        Parameters:
        resource - Resource as string representation
        Returns:
        The new Resource
        Throws:
        java.io.IOException - Problem accessing resource.
      • newClassPathResource

        public static Resource newClassPathResource​(java.lang.String resource)
        Deprecated.
        Find a classpath resource.
        Parameters:
        resource - the relative name of the resource
        Returns:
        Resource or null
      • newClassPathResource

        public static Resource newClassPathResource​(java.lang.String name,
                                                    boolean useCaches,
                                                    boolean checkParents)
        Deprecated.
        Find a classpath resource. The Class.getResource(String) method is used to lookup the resource. If it is not found, then the Loader.getResource(String) method is used. If it is still not found, then ClassLoader.getSystemResource(String) is used. Unlike ClassLoader.getSystemResource(String) this method does not check for normal resources.
        Parameters:
        name - The relative name of the resource
        useCaches - True if URL caches are to be used.
        checkParents - True if forced searching of parent Classloaders is performed to work around loaders with inverted priorities
        Returns:
        Resource or null
      • isContainedIn

        public static boolean isContainedIn​(Resource r,
                                            Resource containingResource)
                                     throws java.net.MalformedURLException
        Deprecated.
        Throws:
        java.net.MalformedURLException
      • isContainedIn

        public abstract boolean isContainedIn​(Resource r)
                                       throws java.net.MalformedURLException
        Deprecated.
        Throws:
        java.net.MalformedURLException
      • isSame

        public boolean isSame​(Resource resource)
        Deprecated.
        Return true if the passed Resource represents the same resource as the Resource. For many resource types, this is equivalent to Object.equals(Object), however for resources types that support aliasing, this maybe some other check (e.g. Files.isSameFile(Path, Path)).
        Parameters:
        resource - The resource to check
        Returns:
        true if the passed resource represents the same resource.
      • release

        public final void release()
        Deprecated.
        Release any temporary resources held by the resource.
      • close

        public abstract void close()
        Deprecated.
        Release any temporary resources held by the resource.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • exists

        public abstract boolean exists()
        Deprecated.
        Returns:
        true if the represented resource exists.
      • isDirectory

        public abstract boolean isDirectory()
        Deprecated.
        Returns:
        true if the represented resource is a container/directory. if the resource is not a file, resources ending with "/" are considered directories.
      • lastModified

        public abstract long lastModified()
        Deprecated.
        Time resource was last modified.
        Returns:
        the last modified time as milliseconds since unix epoch
      • length

        public abstract long length()
        Deprecated.
        Length of the resource.
        Returns:
        the length of the resource
      • getURL

        @Deprecated
        public abstract java.net.URL getURL()
        Deprecated.
        use {getURI().toURL() instead.
        URL representing the resource.
        Returns:
        a URL representing the given resource
      • getURI

        public java.net.URI getURI()
        Deprecated.
        URI representing the resource.
        Returns:
        an URI representing the given resource
      • getFile

        public abstract java.io.File getFile()
                                      throws java.io.IOException
        Deprecated.
        File representing the given resource.
        Returns:
        an File representing the given resource or NULL if this is not possible.
        Throws:
        java.io.IOException - if unable to get the resource due to permissions
      • getName

        public abstract java.lang.String getName()
        Deprecated.
        The name of the resource.
        Returns:
        the name of the resource
      • getInputStream

        public abstract java.io.InputStream getInputStream()
                                                    throws java.io.IOException
        Deprecated.
        Input stream to the resource
        Returns:
        an input stream to the resource
        Throws:
        java.io.IOException - if unable to open the input stream
      • getReadableByteChannel

        public abstract java.nio.channels.ReadableByteChannel getReadableByteChannel()
                                                                              throws java.io.IOException
        Deprecated.
        Readable ByteChannel for the resource.
        Returns:
        an readable bytechannel to the resource or null if one is not available.
        Throws:
        java.io.IOException - if unable to open the readable bytechannel for the resource.
      • delete

        public abstract boolean delete()
                                throws java.lang.SecurityException
        Deprecated.
        Deletes the given resource
        Returns:
        true if resource was found and successfully deleted, false if resource didn't exist or was unable to be deleted.
        Throws:
        java.lang.SecurityException - if unable to delete due to permissions
      • renameTo

        public abstract boolean renameTo​(Resource dest)
                                  throws java.lang.SecurityException
        Deprecated.
        Rename the given resource
        Parameters:
        dest - the destination name for the resource
        Returns:
        true if the resource was renamed, false if the resource didn't exist or was unable to be renamed.
        Throws:
        java.lang.SecurityException - if unable to rename due to permissions
      • list

        public abstract java.lang.String[] list()
        Deprecated.
        list of resource names contained in the given resource. Ordering is unspecified, so callers may wish to sort the return value to ensure deterministic behavior.
        Returns:
        a list of resource names contained in the given resource, or null. Note: The resource names are not URL encoded.
      • addPath

        public abstract Resource addPath​(java.lang.String path)
                                  throws java.io.IOException,
                                         java.net.MalformedURLException
        Deprecated.
        Returns the resource contained inside the current resource with the given name.
        Parameters:
        path - The path segment to add, which is not encoded. The path may be non canonical, but if so then the resulting Resource will return true from isAlias().
        Returns:
        the Resource for the resolved path within this Resource.
        Throws:
        java.io.IOException - if unable to resolve the path
        java.net.MalformedURLException - if the resolution of the path fails because the input path parameter is malformed, or a relative path attempts to access above the root resource.
      • encode

        @Deprecated
        public java.lang.String encode​(java.lang.String uri)
        Deprecated.
        use URIUtil or UrlEncoded instead
        Parameters:
        uri - the uri to encode
        Returns:
        null (this is deprecated)
      • getAssociate

        public java.lang.Object getAssociate()
        Deprecated.
      • setAssociate

        public void setAssociate​(java.lang.Object o)
        Deprecated.
      • isAlias

        public boolean isAlias()
        Deprecated.
        Returns:
        true if this Resource is an alias to another real Resource
      • getAlias

        public java.net.URI getAlias()
        Deprecated.
        Returns:
        The canonical Alias of this resource or null if none.
      • getListHTML

        @Deprecated
        public java.lang.String getListHTML​(java.lang.String base,
                                            boolean parent)
                                     throws java.io.IOException
        Deprecated.
        use getListHTML(String, boolean, String) instead and supply raw query string.
        Get the resource list as a HTML directory listing.
        Parameters:
        base - The base URL
        parent - True if the parent directory should be included
        Returns:
        String of HTML
        Throws:
        java.io.IOException - if unable to get the list of resources as HTML
      • getListHTML

        public java.lang.String getListHTML​(java.lang.String base,
                                            boolean parent,
                                            java.lang.String query)
                                     throws java.io.IOException
        Deprecated.
        Get the resource list as a HTML directory listing.
        Parameters:
        base - The base URL
        parent - True if the parent directory should be included
        query - query params
        Returns:
        String of HTML
        Throws:
        java.io.IOException
      • writeTo

        public void writeTo​(java.io.OutputStream out,
                            long start,
                            long count)
                     throws java.io.IOException
        Deprecated.
        Parameters:
        out - the output stream to write to
        start - First byte to write
        count - Bytes to write or -1 for all of them.
        Throws:
        java.io.IOException - if unable to copy the Resource to the output
      • copyTo

        public void copyTo​(java.io.File destination)
                    throws java.io.IOException
        Deprecated.
        Copy the Resource to the new destination file.

        Will not replace existing destination file.

        Parameters:
        destination - the destination file to create
        Throws:
        java.io.IOException - if unable to copy the resource
      • getWeakETag

        public java.lang.String getWeakETag()
        Deprecated.
        Generate a weak ETag reference for this Resource.
        Returns:
        the weak ETag reference for this resource.
      • getWeakETag

        public java.lang.String getWeakETag​(java.lang.String suffix)
        Deprecated.
      • getAllResources

        public java.util.Collection<Resource> getAllResources()
        Deprecated.
      • toURL

        public static java.net.URL toURL​(java.io.File file)
                                  throws java.net.MalformedURLException
        Deprecated.
        Generate a properly encoded URL from a File instance.
        Parameters:
        file - Target file.
        Returns:
        URL of the target file.
        Throws:
        java.net.MalformedURLException - if unable to convert File to URL