org.springframework.core.io

Class FileUrlResource

    • Constructor Detail

      • FileUrlResource

        public FileUrlResource(java.net.URL url)
        Create a new FileUrlResource based on the given URL object.

        Note that this does not enforce "file" as URL protocol. If a protocol is known to be resolvable to a file,

        Parameters:
        url - a URL
        See Also:
        ResourceUtils.isFileURL(URL), getFile()
      • FileUrlResource

        public FileUrlResource(java.lang.String location)
                        throws java.net.MalformedURLException
        Create a new FileUrlResource based on the given file location, using the URL protocol "file".

        The given parts will automatically get encoded if necessary.

        Parameters:
        location - the location (i.e. the file path within that protocol)
        Throws:
        java.net.MalformedURLException - if the given URL specification is not valid
        See Also:
        UrlResource.UrlResource(String, String), ResourceUtils.URL_PROTOCOL_FILE
    • Method Detail

      • getFile

        public java.io.File getFile()
                             throws java.io.IOException
        Description copied from class: UrlResource
        This implementation returns a File reference for the underlying URL/URI, provided that it refers to a file in the file system.
        Specified by:
        getFile in interface Resource
        Overrides:
        getFile in class UrlResource
        Throws:
        java.io.FileNotFoundException - if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file system
        java.io.IOException - in case of general resolution/reading failures
        See Also:
        ResourceUtils.getFile(java.net.URL, String)
      • getOutputStream

        public java.io.OutputStream getOutputStream()
                                             throws java.io.IOException
        Description copied from interface: WritableResource
        Return an OutputStream for the underlying resource, allowing to (over-)write its content.
        Specified by:
        getOutputStream in interface WritableResource
        Throws:
        java.io.IOException - if the stream could not be opened
        See Also:
        InputStreamSource.getInputStream()
      • writableChannel

        public java.nio.channels.WritableByteChannel writableChannel()
                                                              throws java.io.IOException
        Description copied from interface: WritableResource
        Return a WritableByteChannel.

        It is expected that each call creates a fresh channel.

        The default implementation returns Channels.newChannel(OutputStream) with the result of WritableResource.getOutputStream().

        Specified by:
        writableChannel in interface WritableResource
        Returns:
        the byte channel for the underlying resource (must not be null)
        Throws:
        java.io.FileNotFoundException - if the underlying resource doesn't exist
        java.io.IOException - if the content channel could not be opened
        See Also:
        WritableResource.getOutputStream()
      • createRelative

        public Resource createRelative(java.lang.String relativePath)
                                throws java.net.MalformedURLException
        Description copied from class: UrlResource
        This implementation creates a UrlResource, applying the given path relative to the path of the underlying URL of this resource descriptor.
        Specified by:
        createRelative in interface Resource
        Overrides:
        createRelative in class UrlResource
        Parameters:
        relativePath - the relative path (relative to this resource)
        Returns:
        the resource handle for the relative resource
        Throws:
        java.net.MalformedURLException
        See Also:
        URL.URL(java.net.URL, String)