Module bus.http

Interface CoverResult.Body

All Known Implementing Classes:
ResultBody
Enclosing interface:
CoverResult

public static interface CoverResult.Body
An interface for consuming the HTTP response body in various formats.
  • Method Summary

    Modifier and Type
    Method
    Description
    Caches the response body in memory after the first read.
    Closes the response body without consuming it.
    long
    Gets the length of the response body in bytes.
    org.miaixz.bus.core.lang.MediaType
    Gets the MediaType of the response body.
    Specifies that the next download-related callback should be executed on an I/O thread.
    Sets a progress callback for monitoring the download of the response body.
    Configures the progress callback to ignore the HTTP Range header, calculating progress from 0.
    stepBytes(long stepBytes)
    Sets the interval in bytes for progress callback invocations.
    stepRate(double stepRate)
    Sets the interval as a rate (percentage) for progress callback invocations.
    Deserializes the response body into a schemaless list-like object.
    <T> T
    toBean(Class<T> type)
    Deserializes the response body into an object of the specified type.
    byte[]
    Reads the entire response body into a byte array.
    Converts the response body to a byte stream.
    org.miaixz.bus.core.io.ByteString
    Reads the entire response body into a ByteString.
    Converts the response body to a character stream using the response's charset.
    toFile(File file)
    Downloads the response body to the specified file.
    toFile(String filePath)
    Downloads the response body to a file at the specified path.
    Downloads the response body to the specified directory.
    toFolder(String dirPath)
    Downloads the response body to the specified directory.
    <T> List<T>
    toList(Class<T> type)
    Deserializes the response body into a list of objects of the specified type.
    Reads the entire response body into a string using the response's charset.
    Deserializes the response body into a schemaless map-like object.
  • Method Details

    • toByteStream

      InputStream toByteStream()
      Converts the response body to a byte stream.
      Returns:
      An InputStream of the response body.
    • toBytes

      byte[] toBytes()
      Reads the entire response body into a byte array. This method consumes the body.
      Returns:
      A byte array containing the response body.
    • toByteString

      org.miaixz.bus.core.io.ByteString toByteString()
      Reads the entire response body into a ByteString. This method consumes the body.
      Returns:
      A ByteString containing the response body.
    • toCharStream

      Reader toCharStream()
      Converts the response body to a character stream using the response's charset.
      Returns:
      A Reader for the response body.
    • toString

      String toString()
      Reads the entire response body into a string using the response's charset. This method consumes the body.
      Overrides:
      toString in class Object
      Returns:
      The response body as a String.
    • toWapper

      CoverWapper toWapper()
      Deserializes the response body into a schemaless map-like object.
      Returns:
      A CoverWapper representing the data structure.
    • toArray

      CoverArray toArray()
      Deserializes the response body into a schemaless list-like object.
      Returns:
      A CoverArray representing the data structure.
    • toBean

      <T> T toBean(Class<T> type)
      Deserializes the response body into an object of the specified type.
      Type Parameters:
      T - The target generic type.
      Parameters:
      type - The class of the target object.
      Returns:
      An instance of the target type.
    • toList

      <T> List<T> toList(Class<T> type)
      Deserializes the response body into a list of objects of the specified type.
      Type Parameters:
      T - The target generic type for list elements.
      Parameters:
      type - The class of the elements in the list.
      Returns:
      A list of instances of the target type.
    • getType

      org.miaixz.bus.core.lang.MediaType getType()
      Gets the MediaType of the response body.
      Returns:
      The media type.
    • getLength

      long getLength()
      Gets the length of the response body in bytes.
      Returns:
      The length of the body.
    • nextOnIO

      CoverResult.Body nextOnIO()
      Specifies that the next download-related callback should be executed on an I/O thread.
      Returns:
      This Body instance for chaining.
    • setOnProcess

      CoverResult.Body setOnProcess(Callback<Progress> onProcess)
      Sets a progress callback for monitoring the download of the response body.
      Parameters:
      onProcess - The progress callback function.
      Returns:
      This Body instance for chaining.
    • stepBytes

      CoverResult.Body stepBytes(long stepBytes)
      Sets the interval in bytes for progress callback invocations. Defaults to 8KB (8192).
      Parameters:
      stepBytes - The step size in bytes.
      Returns:
      This Body instance for chaining.
    • stepRate

      CoverResult.Body stepRate(double stepRate)
      Sets the interval as a rate (percentage) for progress callback invocations.
      Parameters:
      stepRate - The step rate, from 0.0 to 1.0.
      Returns:
      This Body instance for chaining.
    • setRangeIgnored

      CoverResult.Body setRangeIgnored()
      Configures the progress callback to ignore the HTTP Range header, calculating progress from 0. This is useful when the total file size is known but the download is of a partial chunk.
      Returns:
      This Body instance for chaining.
    • toFile

      Downloads toFile(String filePath)
      Downloads the response body to a file at the specified path.
      Parameters:
      filePath - The absolute or relative path to the target file.
      Returns:
      A Downloads object to control the download process.
    • toFile

      Downloads toFile(File file)
      Downloads the response body to the specified file.
      Parameters:
      file - The target file.
      Returns:
      A Downloads object to control the download process.
    • toFolder

      Downloads toFolder(String dirPath)
      Downloads the response body to the specified directory. The filename is automatically resolved from the 'Content-Disposition' header or the URL.
      Parameters:
      dirPath - The path to the target directory.
      Returns:
      A Downloads object to control the download process.
    • toFolder

      Downloads toFolder(File dir)
      Downloads the response body to the specified directory. The filename is automatically resolved from the 'Content-Disposition' header or the URL.
      Parameters:
      dir - The target directory.
      Returns:
      A Downloads object to control the download process.
    • cache

      Caches the response body in memory after the first read. This allows multiple consumption methods (e.g., toBytes(), toString()) to be called. Note: Progress callbacks cannot be used when caching is enabled.
      Returns:
      This Body instance for chaining.
    • close

      Closes the response body without consuming it.
      Returns:
      This Body instance.