类 InputStreamResource

  • 所有已实现的接口:
    InputStreamSource, Resource

    public class InputStreamResource
    extends AbstractResource
    Copy from https://github.com/spring-projects/spring-framework.git, with less modifications Resource implementation for a given InputStream.

    Should only be used if no other specific Resource implementation is applicable. In particular, prefer ByteArrayResource or any of the file-based Resource implementations where possible.

    In contrast to other Resource implementations, this is a descriptor for an already opened resource - therefore returning true from isOpen(). Do not use an InputStreamResource if you need to keep the resource descriptor somewhere, or if you need to read from a stream multiple times.

    从以下版本开始:
    28.12.2003
    作者:
    Juergen Hoeller, Sam Brannen
    另请参阅:
    ByteArrayResource, ClassPathResource, FileSystemResource, UrlResource
    • 字段详细资料

      • inputStream

        private final java.io.InputStream inputStream
      • description

        private final java.lang.String description
      • read

        private boolean read
    • 构造器详细资料

      • InputStreamResource

        public InputStreamResource​(java.io.InputStream inputStream)
        Create a new InputStreamResource.
        参数:
        inputStream - the InputStream to use
      • InputStreamResource

        public InputStreamResource​(java.io.InputStream inputStream,
                                   java.lang.String description)
        Create a new InputStreamResource.
        参数:
        inputStream - the InputStream to use
        description - where the InputStream comes from
    • 方法详细资料

      • getInputStream

        public java.io.InputStream getInputStream()
                                           throws java.io.IOException,
                                                  java.lang.IllegalStateException
        This implementation throws IllegalStateException if attempting to read the underlying stream multiple times.
        返回:
        the input stream for the underlying resource (must not be null)
        抛出:
        java.io.FileNotFoundException - if the underlying resource does not exist
        java.io.IOException - if the content stream could not be opened
        java.lang.IllegalStateException
        另请参阅:
        Resource.isReadable()
      • getDescription

        public java.lang.String getDescription()
        This implementation returns a description that includes the passed-in description, if any.
        另请参阅:
        Object.toString()