接口 InputStreamSource

所有超级接口:
Consumer<OutputStream>, ThrowingConsumer<OutputStream>
所有已知子接口:
ContextResource, Resource, WritableResource
所有已知实现类:
AbstractFileResolvingResource, AbstractResource, AppendableConsumerInputStreamSource, ByteArrayResource, ClassPathResource, ClassRelativeResourceLoader.ClassRelativeContextResource, DefaultResourceLoader.ClassPathContextResource, DescriptiveResource, EncodedResource, FileSystemResource, FileSystemResourceLoader.FileSystemContextResource, FileUrlResource, InputStreamResource, ModuleResource, PathResource, ResourceDecorator, UrlResource, WritableResourceDecorator
函数接口:
这是一个函数接口, 因此可用作 lambda 表达式或方法引用的赋值目标。

@FunctionalInterface public interface InputStreamSource extends ThrowingConsumer<OutputStream>
Simple interface for objects that are sources for an InputStream.

This is the base interface for Infra more extensive Resource interface.

For single-use streams, InputStreamResource can be used for any given InputStream. Infra ByteArrayResource or any file-based Resource implementation can be used as a concrete instance, allowing one to read the underlying content stream multiple times. This makes this interface useful as an abstract content source for mail attachments, for example.

从以下版本开始:
2.1.6 2019-07-08 00:12
作者:
Juergen Hoeller, Harry Yang
另请参阅:
  • 方法详细资料

    • getInputStream

      InputStream getInputStream() throws IOException
      Return an InputStream for the content of an underlying resource.

      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.

      返回:
      the input stream for the underlying resource (must not be null)
      抛出:
      FileNotFoundException - if the underlying resource does not exist
      IOException - if the content stream could not be opened
      另请参阅:
    • getReader

      default Reader getReader() throws IOException
      Get Reader
      抛出:
      IOException - If an input exception occurs
    • getReader

      default Reader getReader(String encoding) throws IOException
      Get Reader
      参数:
      encoding - Charset string
      抛出:
      IOException - If an input exception occurs
    • readableChannel

      default ReadableByteChannel readableChannel() throws IOException
      Return a ReadableByteChannel.

      It is expected that each call creates a fresh channel.

      The default implementation returns Channels.newChannel(InputStream) with the result of getInputStream().

      返回:
      the byte channel for the underlying resource (must not be null)
      抛出:
      FileNotFoundException - if the underlying resource doesn't exist
      IOException - if the content channel could not be opened
      另请参阅:
    • transferTo

      default long transferTo(OutputStream out) throws IOException
      Reads all bytes from this getInputStream() and writes the bytes to the given output stream in the order that they are read. On return, this input stream will be at end of stream. This method does not close either stream.

      This method may block indefinitely reading from the input stream, or writing to the output stream. The behavior for the case where the input and/or output stream is asynchronously closed, or the thread interrupted during the transfer, is highly input and output stream specific, and therefore not specified.

      If an I/O error occurs reading from the input stream or writing to the output stream, then it may do so after some bytes have been read or written. Consequently the input stream may not be at end of stream and one, or both, streams may be in an inconsistent state. It is strongly recommended that both streams be promptly closed if an I/O error occurs.

      参数:
      out - the output stream, non-null
      返回:
      the number of bytes transferred
      抛出:
      IOException - if an I/O error occurs when reading or writing
      NullPointerException - if out is null
      从以下版本开始:
      4.0
    • acceptWithException

      default void acceptWithException(OutputStream out) throws Exception
      从接口复制的说明: ThrowingConsumer
      Performs this operation on the given argument, possibly throwing a checked exception.
      指定者:
      acceptWithException 在接口中 ThrowingConsumer<OutputStream>
      参数:
      out - the output stream, non-null
      抛出:
      Exception - on error
      另请参阅: