类 DefaultPartHttpMessageReader

java.lang.Object
cn.taketoday.http.codec.LoggingCodecSupport
cn.taketoday.http.codec.multipart.DefaultPartHttpMessageReader
所有已实现的接口:
HttpMessageReader<Part>

public class DefaultPartHttpMessageReader extends LoggingCodecSupport implements HttpMessageReader<Part>
Default HttpMessageReader for parsing "multipart/form-data" requests to a stream of Parts.

In default, non-streaming mode, this message reader stores the contents of parts smaller than maxInMemorySize in memory, and parts larger than that to a temporary file in fileStorageDirectory.

In streaming mode, the contents of the part is streamed directly from the parsed input buffer stream, and not stored in memory nor file.

This reader can be provided to MultipartHttpMessageReader in order to aggregate all parts into a Map.

从以下版本开始:
4.0
作者:
Arjen Poutsma, Harry Yang
  • 字段详细资料

    • maxHeadersSize

      private int maxHeadersSize
    • maxInMemorySize

      private int maxInMemorySize
    • maxDiskUsagePerPart

      private long maxDiskUsagePerPart
    • maxParts

      private int maxParts
    • streaming

      private boolean streaming
    • headersCharset

      private Charset headersCharset
    • blockingOperationScheduler

      private reactor.core.scheduler.Scheduler blockingOperationScheduler
    • fileStorage

      private FileStorage fileStorage
  • 构造器详细资料

    • DefaultPartHttpMessageReader

      public DefaultPartHttpMessageReader()
  • 方法详细资料

    • setMaxHeadersSize

      public void setMaxHeadersSize(int byteCount)
      Configure the maximum amount of memory that is allowed per headers section of each part. When the limit
      参数:
      byteCount - the maximum amount of memory for headers
    • getMaxInMemorySize

      public int getMaxInMemorySize()
      Get the configured maximum in-memory size.
    • setMaxInMemorySize

      public void setMaxInMemorySize(int maxInMemorySize)
      Configure the maximum amount of memory allowed per part. When the limit is exceeded:
      • file parts are written to a temporary file.
      • non-file parts are rejected with DataBufferLimitException.

      By default this is set to 256K.

      Note that this property is ignored when streaming is enabled.

      参数:
      maxInMemorySize - the in-memory limit in bytes; if set to -1 the entire contents will be stored in memory
    • setMaxDiskUsagePerPart

      public void setMaxDiskUsagePerPart(long maxDiskUsagePerPart)
      Configure the maximum amount of disk space allowed for file parts.

      By default this is set to -1, meaning that there is no maximum.

      Note that this property is ignored when streaming is enabled, , or when maxInMemorySize is set to -1.

    • setMaxParts

      public void setMaxParts(int maxParts)
      Specify the maximum number of parts allowed in a given multipart request.

      By default this is set to -1, meaning that there is no maximum.

    • setFileStorageDirectory

      public void setFileStorageDirectory(Path fileStorageDirectory) throws IOException
      Set the directory used to store parts larger than maxInMemorySize. By default, a directory named multipart is created under the system temporary directory.

      Note that this property is ignored when streaming is enabled, or when maxInMemorySize is set to -1.

      抛出:
      IOException - if an I/O error occurs, or the parent directory does not exist
    • setBlockingOperationScheduler

      public void setBlockingOperationScheduler(reactor.core.scheduler.Scheduler blockingOperationScheduler)
      Set the Reactor Scheduler to be used for creating files and directories, and writing to files. By default, Schedulers.boundedElastic() is used, but this property allows for changing it to an externally managed scheduler.

      Note that this property is ignored when streaming is enabled, or when maxInMemorySize is set to -1.

      另请参阅:
      • Schedulers.newBoundedElastic(int, int, java.lang.String)
    • getBlockingOperationScheduler

      private reactor.core.scheduler.Scheduler getBlockingOperationScheduler()
    • setStreaming

      public void setStreaming(boolean streaming)
      When set to true, the part content is streamed directly from the parsed input buffer stream, and not stored in memory nor file. When false, parts are backed by in-memory and/or file storage. Defaults to false.

      NOTE that with streaming enabled, the Flux<Part> that is produced by this message reader must be consumed in the original order, i.e. the order of the HTTP message. Additionally, the body contents must either be completely consumed or canceled before moving to the next part.

      Also note that enabling this property effectively ignores maxInMemorySize, maxDiskUsagePerPart, fileStorageDirectory, and fileCreationScheduler.

    • setHeadersCharset

      public void setHeadersCharset(Charset headersCharset)
      Set the character set used to decode headers. Defaults to UTF-8 as per RFC 7578.
      参数:
      headersCharset - the charset to use for decoding headers
      另请参阅:
    • getReadableMediaTypes

      public List<MediaType> getReadableMediaTypes()
      从接口复制的说明: HttpMessageReader
      Return the list of media types supported by this reader. The list may not apply to every possible target element type and calls to this method should typically be guarded via canWrite(elementType, null). The list may also exclude media types supported only for a specific element type. Alternatively, use HttpMessageReader.getReadableMediaTypes(ResolvableType) for a more precise list.
      指定者:
      getReadableMediaTypes 在接口中 HttpMessageReader<Part>
      返回:
      the general list of supported media types
    • canRead

      public boolean canRead(cn.taketoday.core.ResolvableType elementType, @Nullable MediaType mediaType)
      从接口复制的说明: HttpMessageReader
      Whether the given object type is supported by this reader.
      指定者:
      canRead 在接口中 HttpMessageReader<Part>
      参数:
      elementType - the type of object to check
      mediaType - the media type for the read (possibly null)
      返回:
      true if readable, false otherwise
    • readMono

      public reactor.core.publisher.Mono<Part> readMono(cn.taketoday.core.ResolvableType elementType, ReactiveHttpInputMessage message, Map<String,Object> hints)
      从接口复制的说明: HttpMessageReader
      Read from the input message and decode to a single object.
      指定者:
      readMono 在接口中 HttpMessageReader<Part>
      参数:
      elementType - the type of objects in the stream which must have been previously checked via HttpMessageReader.canRead(ResolvableType, MediaType)
      message - the message to read from
      hints - additional information about how to read and decode the input
      返回:
      the decoded object
    • read

      public reactor.core.publisher.Flux<Part> read(cn.taketoday.core.ResolvableType elementType, ReactiveHttpInputMessage message, Map<String,Object> hints)
      从接口复制的说明: HttpMessageReader
      Read from the input message and decode to a stream of objects.
      指定者:
      read 在接口中 HttpMessageReader<Part>
      参数:
      elementType - the type of objects in the stream which must have been previously checked via HttpMessageReader.canRead(ResolvableType, MediaType)
      message - the message to read from
      hints - additional information about how to read and decode the input
      返回:
      the decoded stream of elements
    • tooManyParts

      private boolean tooManyParts(AtomicInteger partCount)