org.springframework.core.io

Class DescriptiveResource

  • All Implemented Interfaces:
    InputStreamSource, Resource

    public class DescriptiveResource
    extends AbstractResource
    Simple Resource implementation that holds a resource description but does not point to an actually readable resource.

    To be used as placeholder if a Resource argument is expected by an API but not necessarily used for actual reading.

    Since:
    1.2.6
    Author:
    Juergen Hoeller
    • Constructor Detail

      • DescriptiveResource

        public DescriptiveResource(String description)
        Create a new DescriptiveResource.
        Parameters:
        description - the resource description
    • Method Detail

      • exists

        public boolean exists()
        Description copied from class: AbstractResource
        This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened. This will cover both directories and content resources.
        Specified by:
        exists in interface  Resource
        Overrides:
        exists in class  AbstractResource
      • getInputStream

        public InputStream getInputStream()
                                   throws IOException
        Description copied from interface: InputStreamSource
        Return an InputStream.

        It is expected that each call creates a fresh stream.

        This requirement is particularly important when you consider an API such as JavaMail, which needs to be able to read the stream multiple times when creating mail attachments. For such a use case, it is required that each getInputStream() call returns a fresh stream.

        Returns:
        the input stream for the underlying resource (must not be null)
        Throws:
        IOException - if the stream could not be opened
        See Also:
        org.springframework.mail.javamail.MimeMessageHelper#addAttachment(String, InputStreamSource)
      • getDescription

        public String getDescription()
        Description copied from interface: Resource
        Return a description for this resource, to be used for error output when working with the resource.

        Implementations are also encouraged to return this value from their toString method.

        See Also:
        Object.toString()