- 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 TypeMethodDescriptioncache()Caches the response body in memory after the first read.close()Closes the response body without consuming it.longGets the length of the response body in bytes.org.miaixz.bus.core.lang.MediaTypegetType()Gets theMediaTypeof the response body.nextOnIO()Specifies that the next download-related callback should be executed on an I/O thread.setOnProcess(Callback<Progress> onProcess) 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.toArray()Deserializes the response body into a schemaless list-like object.<T> TDeserializes the response body into an object of the specified type.byte[]toBytes()Reads the entire response body into a byte array.Converts the response body to a byte stream.org.miaixz.bus.core.io.ByteStringReads the entire response body into a ByteString.Converts the response body to a character stream using the response's charset.Downloads the response body to the specified file.Downloads the response body to a file at the specified path.Downloads the response body to the specified directory.Downloads the response body to the specified directory.<T> List<T> Deserializes the response body into a list of objects of the specified type.toString()Reads the entire response body into a string using the response's charset.toWapper()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
InputStreamof 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
ByteStringcontaining the response body.
-
toCharStream
Reader toCharStream()Converts the response body to a character stream using the response's charset.- Returns:
- A
Readerfor the response body.
-
toString
String toString()Reads the entire response body into a string using the response's charset. This method consumes the body. -
toWapper
CoverWapper toWapper()Deserializes the response body into a schemaless map-like object.- Returns:
- A
CoverWapperrepresenting the data structure.
-
toArray
CoverArray toArray()Deserializes the response body into a schemaless list-like object.- Returns:
- A
CoverArrayrepresenting the data structure.
-
toBean
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
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 theMediaTypeof 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
Bodyinstance for chaining.
-
setOnProcess
Sets a progress callback for monitoring the download of the response body.- Parameters:
onProcess- The progress callback function.- Returns:
- This
Bodyinstance for chaining.
-
stepBytes
Sets the interval in bytes for progress callback invocations. Defaults to 8KB (8192).- Parameters:
stepBytes- The step size in bytes.- Returns:
- This
Bodyinstance for chaining.
-
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
Bodyinstance 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
Bodyinstance for chaining.
-
toFile
Downloads the response body to a file at the specified path.- Parameters:
filePath- The absolute or relative path to the target file.- Returns:
- A
Downloadsobject to control the download process.
-
toFile
Downloads the response body to the specified file.- Parameters:
file- The target file.- Returns:
- A
Downloadsobject to control the download process.
-
toFolder
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
Downloadsobject to control the download process.
-
toFolder
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
Downloadsobject to control the download process.
-
cache
CoverResult.Body 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
Bodyinstance for chaining.
-
close
CoverResult.Body close()Closes the response body without consuming it.- Returns:
- This
Bodyinstance.
-