How to use toString method of com.github.kittinunf.fuel.core.requests.DownloadRequest class

Best Fuel code snippet using com.github.kittinunf.fuel.core.requests.DownloadRequest.toString

Request.kt

Source:Request.kt Github

copy

Full Screen

...78 * @see com.github.kittinunf.fuel.core.extensions.cUrlString79 *80 * @return [String] the string representation81 */82 override fun toString(): String83 /**84 * Get the current values of the header, after normalisation of the header85 * @param header [String] the header name86 * @return the current values (or empty if none)87 */88 operator fun get(header: String): HeaderValues89 /**90 * Set the values of the header, overriding what's there, after normalisation of the header91 *92 * @param header [String] the header name93 * @param values [Collection<*>] the values to be transformed through #toString94 * @return self95 */96 operator fun set(header: String, values: Collection<*>): Request97 /**98 * Set the value of the header, overriding what's there, after normalisation of the header99 *100 * @param header [String] the header name101 * @param value [Any] the value to be transformed through #toString102 */103 operator fun set(header: String, value: Any): Request104 /**105 * Get the current values106 *107 * @see get(header: String)108 * @return [HeaderValues] the current values109 */110 fun header(header: String): HeaderValues111 /**112 * Replace the headers with the map provided113 *114 * @note In earlier versions the mapOf variant of this function worked differently than the vararg pairs variant,115 * which has been changed to make any call to header(...) always overwrite the values and any call to116 * appendHeader(...) will try to append the value.117 *118 * @see set(header: String, values: Collection<*>)119 * @see set(header: String, value: Any)120 *121 * @param map [Map<String, Any>] map of headers to replace. Value can be a list or single value122 * @return [Request] the modified request123 */124 fun header(map: Map<String, Any>): Request125 /**126 * Replace the headers with the pairs provided127 *128 * @note In earlier versions the mapOf variant of this function worked differently than the vararg pairs variant,129 * which has been changed to make any call to header(...) always overwrite the values and any call to130 * appendHeader(...) will try to append the value.131 *132 * @see set(header: String, values: Collection<*>)133 * @see set(header: String, value: Any)134 *135 * @param pairs [Pair<String, Any>] map of headers to replace. Value can be a list or single value136 * @return [Request] the modified request137 */138 fun header(vararg pairs: Pair<String, Any>): Request139 /**140 * Replace the header with the provided values141 *142 * @see set(header: String, values: Collection<*>)143 *144 * @param header [String] the header to set145 * @param values [List<Any>] the values to set the header to146 * @return [Request] the modified request147 */148 fun header(header: String, values: Collection<*>): Request149 /**150 * Replace the header with the provided value151 *152 * @see set(header: String, values: List<Any>)153 *154 * @param header [String] the header to set155 * @param value [Any] the value to set the header to156 * @return [Request] the modified request157 */158 fun header(header: String, value: Any): Request159 /**160 * Replace the header with the provided values161 *162 * @see set(header: String, values: List<Any>)163 *164 * @param header [String] the header to set165 * @param values [Any] the values to set the header to166 * @return [Request] the modified request167 */168 fun header(header: String, vararg values: Any): Request169 /**170 * Appends the value to the header or sets it if there was none yet171 *172 * @param header [String] the header name to append to173 * @param value [Any] the value to be transformed through #toString174 */175 fun appendHeader(header: String, value: Any): Request176 /**177 * Appends the value to the header or sets it if there was none yet178 *179 * @param header [String] the header name to append to180 * @param values [Any] the value to be transformed through #toString181 */182 fun appendHeader(header: String, vararg values: Any): Request183 /**184 * Append each pair, using the key as header name and value as header content185 *186 * @param pairs [Pair<String, Any>]187 */188 fun appendHeader(vararg pairs: Pair<String, Any>): Request189 /**190 * Execute the [Request] asynchronously, using the [handler], into a [ByteArray]191 *192 * @param handler [ResponseResultHandler] the handler to report the [Request], [Response] and Result of [ByteArray]193 * @return [CancellableRequest] the request in flight194 */...

Full Screen

Full Screen

DefaultRequest.kt

Source:DefaultRequest.kt Github

copy

Full Screen

...51 /**52 * Set the values of the header, overriding what's there, after normalisation of the header53 *54 * @param header [String] the header name55 * @param values [Collection<*>] the values to be transformed through #toString56 * @return self57 */58 override operator fun set(header: String, values: Collection<*>): Request {59 headers[header] = values.map { it.toString() }60 return request61 }62 /**63 * Set the value of the header, overriding what's there, after normalisation of the header64 *65 * @param header [String] the header name66 * @param value [Any] the value to be transformed through #toString67 */68 override operator fun set(header: String, value: Any): Request {69 when (value) {70 is Collection<*> -> this[header] = value71 else -> headers[header] = value.toString()72 }73 return request74 }75 /**76 * Get the current values77 *78 * @see get(header: String)79 * @return [HeaderValues] the current values80 */81 override fun header(header: String) = get(header)82 /**83 * Replace the headers with the map provided84 *85 * @note In earlier versions the mapOf variant of this function worked differently than the vararg pairs variant,86 * which has been changed to make any call to header(...) always overwrite the values and any call to87 * appendHeader(...) will try to append the value.88 *89 * @see set(header: String, values: Collection<*>)90 * @see set(header: String, value: Any)91 *92 * @param map [Map<String, Any>] map of headers to replace. Value can be a list or single value93 * @return [Request] the modified request94 */95 override fun header(map: Map<String, Any>): Request {96 headers.putAll(Headers.from(map))97 return request98 }99 /**100 * Replace the headers with the pairs provided101 *102 * @note In earlier versions the mapOf variant of this function worked differently than the vararg pairs variant,103 * which has been changed to make any call to header(...) always overwrite the values and any call to104 * appendHeader(...) will try to append the value.105 *106 * @see set(header: String, values: Collection<*>)107 * @see set(header: String, value: Any)108 *109 * @param pairs [Pair<String, Any>] map of headers to replace. Value can be a list or single value110 * @return [Request] the modified request111 */112 override fun header(vararg pairs: Pair<String, Any>): Request {113 headers.putAll(Headers.from(*pairs))114 return request115 }116 /**117 * Replace the header with the provided values118 *119 * @see set(header: String, values: Collection<*>)120 *121 * @param header [String] the header to set122 * @param values [List<Any>] the values to set the header to123 * @return [Request] the modified request124 */125 override fun header(header: String, values: Collection<*>) = set(header, values)126 /**127 * Replace the header with the provided value128 *129 * @see set(header: String, values: List<Any>)130 *131 * @param header [String] the header to set132 * @param value [Any] the value to set the header to133 * @return [Request] the modified request134 */135 override fun header(header: String, value: Any): Request = set(header, value)136 /**137 * Replace the header with the provided values138 *139 * @see set(header: String, values: List<Any>)140 *141 * @param header [String] the header to set142 * @param values [Any] the values to set the header to143 * @return [Request] the modified request144 */145 override fun header(header: String, vararg values: Any) = set(header, values.toList())146 /**147 * Appends the value to the header or sets it if there was none yet148 *149 * @param header [String] the header name to append to150 * @param value [Any] the value to be transformed through #toString151 */152 override fun appendHeader(header: String, value: Any): Request {153 headers.append(header, value)154 return request155 }156 /**157 * Appends the value to the header or sets it if there was none yet158 *159 * @param header [String] the header name to append to160 * @param values [Any] the value to be transformed through #toString161 */162 override fun appendHeader(header: String, vararg values: Any): Request {163 headers.append(header, values.toList())164 return request165 }166 /**167 * Append each pair, using the key as header name and value as header content168 *169 * @param pairs [Pair<String, Any>]170 */171 override fun appendHeader(vararg pairs: Pair<String, Any>): Request {172 pairs.forEach { pair -> appendHeader(pair.first, pair.second) }173 return request174 }175 /**176 * Sets the body to be read from a generic body source.177 *178 * @note in earlier versions the body callback would be called multiple times in order to maybe get the size. But179 * that would lead to closed streams being unable to be read. If the size is known, set it before anything else.180 *181 * @param openStream [BodySource] a function that yields a stream182 * @param calculateLength [Number?] size in +bytes+ if it is known183 * @param charset [Charset] the charset to write with184 * @param repeatable [Boolean] loads the body into memory upon reading185 *186 * @return [Request] the request187 */188 override fun body(openStream: BodySource, calculateLength: BodyLength?, charset: Charset, repeatable: Boolean): Request {189 _body = DefaultBody190 .from(openStream = openStream, calculateLength = calculateLength, charset = charset)191 .let { body -> if (repeatable) body.asRepeatable() else body }192 return request193 }194 /**195 * Sets the body from a generic stream196 *197 * @note the stream will be read from the position it's at. Make sure you rewind it if you want it to be read from198 * the start.199 *200 * @param stream [InputStream] a stream to read from201 * @param calculateLength [Number?] size in bytes if it is known202 * @param charset [Charset] the charset to write with203 * @param repeatable [Boolean] loads the body into memory upon reading204 *205 * @return [Request] the request206 */207 override fun body(stream: InputStream, calculateLength: BodyLength?, charset: Charset, repeatable: Boolean) =208 body(openStream = { stream }, calculateLength = calculateLength, charset = charset, repeatable = repeatable)209 /**210 * Sets the body from a byte array211 *212 * @param bytes [ByteArray] the bytes to write213 * @param charset [Charset] the charset to write with214 * @return [Request] the request215 */216 override fun body(bytes: ByteArray, charset: Charset) =217 body(stream = ByteArrayInputStream(bytes), calculateLength = { bytes.size.toLong() }, charset = charset, repeatable = true)218 /**219 * Sets the body from a string220 *221 * @param body [String] the string to write222 * @param charset [Charset] the charset to write with223 * @return [Request] the request224 */225 override fun body(body: String, charset: Charset): Request =226 body(bytes = body.toByteArray(charset), charset = charset)227 .let {228 if (header(Headers.CONTENT_TYPE).lastOrNull().isNullOrBlank())229 header(Headers.CONTENT_TYPE, "text/plain; charset=${charset.name()}")230 else it231 }232 /**233 * Sets the body to the contents of a file.234 *235 * @note this does *NOT* make this a multipart upload. For that you can use the upload request. This function can be236 * used if you want to upload the single contents of a text based file as an inline body.237 *238 * @note when charset is not UTF-8, this forces the client to use chunked encoding, because file.length() gives the239 * length of the file in bytes without considering the charset. If the charset is to be considered, the file needs240 * to be read in its entirety which defeats the purpose of using a file.241 *242 * @param file [File] the file to write to the body243 * @param charset [Charset] the charset to write with244 * @return [Request] the request245 */246 override fun body(file: File, charset: Charset): Request = when (charset) {247 Charsets.UTF_8 -> body({ FileInputStream(file) }, { file.length() }, charset)248 else -> body({ FileInputStream(file) }, null, charset)249 }.let {250 if (header(Headers.CONTENT_TYPE).lastOrNull().isNullOrBlank()) {251 val contentType = URLConnection.guessContentTypeFromName(file.name)252 header(Headers.CONTENT_TYPE, "$contentType; charset=${charset.name()}")253 } else {254 it255 }256 }257 /**258 * Sets the body to a defined [Body]259 *260 * @param body [Body] the body to assign261 * @return [Request] the request262 */263 override fun body(body: Body): Request {264 _body = body265 return request266 }267 /**268 * Add a [ProgressCallback] tracking the [Body] of the [Request]269 *270 * @see body271 * @see com.github.kittinunf.fuel.core.requests.UploadRequest.progress272 *273 * @return self274 */275 override fun requestProgress(handler: ProgressCallback): Request {276 executionOptions.requestProgress += handler277 return request278 }279 /**280 * Add a [ProgressCallback] tracking the [Body] of the [com.github.kittinunf.fuel.core.Response]281 *282 * @see com.github.kittinunf.fuel.core.requests.DownloadRequest.progress283 *284 * @return self285 */286 override fun responseProgress(handler: ProgressCallback): Request {287 executionOptions.responseProgress += handler288 return request289 }290 /**291 * Add a [InterruptCallback] to the [RequestExecutionOptions]292 *293 * @see RequestExecutionOptions.interruptCallbacks294 *295 * @return self296 */297 override fun interrupt(interrupt: InterruptCallback) = request.also {298 it.executionOptions.interruptCallbacks.plusAssign(interrupt)299 }300 /**301 * Overwrite the [Request] [timeout] in milliseconds302 *303 * @note [com.github.kittinunf.fuel.core.Client] must implement this behaviour304 * @note the default client sets [java.net.HttpURLConnection.setConnectTimeout]305 *306 * @param timeout [Int] timeout in milliseconds307 * @return self308 */309 override fun timeout(timeout: Int) = request.also {310 it.executionOptions.timeoutInMillisecond = timeout311 }312 /**313 * Overwrite the [Request] [timeout] in milliseconds314 *315 * @note [com.github.kittinunf.fuel.core.Client] must implement this behaviour316 * @note the default client sets [java.net.HttpURLConnection.setReadTimeout]317 *318 * @param timeout [Int] timeout in milliseconds319 * @return self320 */321 override fun timeoutRead(timeout: Int) = request.also {322 it.executionOptions.timeoutReadInMillisecond = timeout323 }324 /**325 * Follow redirects as handled by instances of RedirectInterceptors326 * i.e. [com.github.kittinunf.fuel.core.interceptors.redirectResponseInterceptor]327 *328 * @note The interceptor must implement this behaviour329 * @note The provided RedirectResponseInterceptor defaults to true330 *331 * @param allowRedirects [Boolean] true if allowing, false if not332 * @return self333 */334 override fun allowRedirects(allowRedirects: Boolean) = request.also {335 it.executionOptions.allowRedirects = allowRedirects336 }337 /**338 * Overwrite [RequestExecutionOptions] http cache usage flag339 *340 * @note [com.github.kittinunf.fuel.core.Client] must implement this behaviour341 * @note The default client sends `Cache-Control: none` if this flag is false, defaults to true342 *343 * @see java.net.HttpURLConnection.setUseCaches344 * @param useHttpCache [Boolean] true if suggest client to allow cached responses, false otherwise345 */346 override fun useHttpCache(useHttpCache: Boolean) = request.also {347 it.executionOptions.useHttpCache = useHttpCache348 }349 /**350 * Overwrite [RequestExecutionOptions] response validator block351 *352 * @note The default responseValidator is to throw [com.github.kittinunf.fuel.core.HttpException]353 * @note if the response http status code is not in the range of (100 - 399) which should consider as failure response354 *355 * @param validator [ResponseValidator]356 * @return [Request] the modified request357 */358 override fun validate(validator: ResponseValidator) = request.also {359 it.executionOptions.responseValidator = validator360 }361 /**362 * Attach tag to the request363 *364 * @note tag is a generic purpose tagging for Request. This can be used to attach arbitrarily object to the Request instance.365 * @note Tags internally is represented as hashMap that uses class as a key.366 *367 * @param t [Any]368 * @return [Request] the modified request369 */370 override fun tag(t: Any) = request.also {371 tags[t::class] = t372 }373 /**374 * Return corresponding tag from the request375 *376 * @note tag is a generic purpose tagging for Request. This can be used to attach arbitrarily object to the Request instance.377 * @note Tags internally is represented as hashMap that uses class as a key.378 *379 * @param clazz [KClass]380 * @return [Any] previously attached tag if any, null otherwise381 */382 override fun <T : Any> getTag(clazz: KClass<T>) = tags[clazz] as? T383 override val request: Request get() = this384 /**385 * Returns a string representation of the request.386 *387 * @see com.github.kittinunf.fuel.core.extensions.httpString388 * @see com.github.kittinunf.fuel.core.extensions.cUrlString389 *390 * @return [String] the string representation391 */392 override fun toString(): String = buildString {393 appendln("--> $method $url")394 appendln("Body : ${body.asString(header(Headers.CONTENT_TYPE).lastOrNull())}")395 appendln("Headers : (${headers.size})")396 val appendHeaderWithValue = { key: String, value: String -> appendln("$key : $value") }397 headers.transformIterate(appendHeaderWithValue)398 }399 override fun response(handler: ResponseResultHandler<ByteArray>) =400 response(ByteArrayDeserializer(), handler)401 override fun response(handler: ResultHandler<ByteArray>) =402 response(ByteArrayDeserializer(), handler)403 override fun response(handler: ResponseHandler<ByteArray>) =404 response(ByteArrayDeserializer(), handler)405 override fun response(handler: Handler<ByteArray>) =406 response(ByteArrayDeserializer(), handler)...

Full Screen

Full Screen

DownLoadAppService.kt

Source:DownLoadAppService.kt Github

copy

Full Screen

...157 notifyManager.cancel(NOTIFY_ID_DOWNLOAD)158 installApp()159 downloadFinishFlag = true160 }, {161 Logger.i(it.message.toString())162 downloadFinishFlag = false163 })164 )165 }166 private fun updateProgress(progress: Float) {167 customRemoteViews.setProgressBar(168 R.id.notify_progress,169 100,170 ceil(progress).toInt(),171 false172 )173 customRemoteViews.setTextViewText(174 R.id.tvProgress,175 "${ceil(progress).toInt()}%"...

Full Screen

Full Screen

Extensions.kt

Source:Extensions.kt Github

copy

Full Screen

...128 val returnEmptyInputStream: () -> InputStream = { ByteArrayInputStream(ByteArray(0)) }129 (this as DownloadRequest).streamDestination { _, _ -> Pair(outputStream, returnEmptyInputStream) }130 .response()131 }132 val headReq = headRequest(this.url.toString(), null)133 val response = headReq.response()134 .second135 val httpStatus = httpStatusFromCode(response.statusCode)136 val headers = headersToMultiMap(response.headers)137 return ResponseEntity(responseBody, headers, httpStatus)138}139fun File.md5sum(): String140{141 val md = MessageDigest.getInstance("MD5")142 FileInputStream(this).use { fis ->143 DigestInputStream(fis, md).use { dis ->144 dis.readBytes()145 }146 }...

Full Screen

Full Screen

DownloadRequest.kt

Source:DownloadRequest.kt Github

copy

Full Screen

...13typealias StreamDestinationCallback = (Response, Request) -> Pair<OutputStream, DestinationAsStreamCallback>14typealias DestinationAsStreamCallback = () -> InputStream15class DownloadRequest private constructor(private val wrapped: Request) : Request by wrapped {16 override val request: DownloadRequest = this17 override fun toString() = "Download[\n\r\t$wrapped\n\r]"18 private lateinit var destinationCallback: StreamDestinationCallback19 init {20 executionOptions += this::transformResponse21 }22 @Deprecated("Use fileDestination with (Request, Response) -> File")23 fun destination(destination: LegacyDestinationCallback) =24 fileDestination { response: Response, request: Request -> destination(response, request.url) }25 /**26 * Set the destination callback27 *28 * @note destination *MUST* be writable or this may or may not silently fail, dependent on the JVM/engine this is29 * called on. For example, Android silently fails and hangs if used an inaccessible temporary directory, which30 * is syntactically valid.31 *...

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1val downloadString = downloadRequest.toString()2val downloadString = downloadRequest.toString()3val downloadString = downloadRequest.toString()4val downloadString = downloadRequest.toString()5val downloadString = downloadRequest.toString()6val downloadString = downloadRequest.toString()7val downloadString = downloadRequest.toString()8val downloadString = downloadRequest.toString()9val downloadString = downloadRequest.toString()10val downloadString = downloadRequest.toString()11val downloadString = downloadRequest.toString()

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1File.createTempFile("download", ".png")2}3val downloadRequestString = downloadRequest.toString()4val uploadRequestString = uploadRequest.toString()5val streamingRequestString = streamingRequest.toString()6val cancellableRequestString = cancellableRequest.toString()7val requestString = request.toString()8val blobRequestString = blobRequest.toString()9val dataRequestString = dataRequest.toString()10val stringRequestString = stringRequest.toString()11val jsonRequestString = jsonRequest.toString()12val byteArrayRequestString = byteArrayRequest.toString()13val objectRequestString = objectRequest.toString()

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1val downloadRequestString = downloadRequest.toString()2val downloadRequestString = downloadRequest.toString()3val downloadRequestString = downloadRequest.toString()4val downloadRequestString = downloadRequest.toString()5val downloadRequestString = downloadRequest.toString()6val downloadRequestString = downloadRequest.toString()7val downloadRequestString = downloadRequest.toString()8val downloadRequestString = downloadRequest.toString()9val downloadRequestString = downloadRequest.toString()10val downloadRequestString = downloadRequest.toString()11val downloadRequestString = downloadRequest.toString()12val downloadRequestString = downloadRequest.toString()

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1val downloadRequestToString = downloadRequest.toString()2println(downloadRequestToString)3val downloadRequestToString = downloadRequest.toString()4println(downloadRequestToString)5val downloadRequestToString = downloadRequest.toString()6println(downloadRequestToString)7val downloadRequestToString = downloadRequest.toString()8println(downloadRequestToString)9val downloadRequestToString = downloadRequest.toString()10println(downloadRequestToString)11val downloadRequestToString = downloadRequest.toString()12println(downloadRequestToString)13val downloadRequestToString = downloadRequest.toString()14println(downloadRequestToString)15val downloadRequestToString = downloadRequest.toString()16println(downloadRequestToString)

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1println(downloadRequest.toString())2println(uploadRequest.toString())3println(headRequest.toString())4println(patchRequest.toString())5println(putRequest.toString())6println(deleteRequest.toString())7println(traceRequest.toString())8println(optionsRequest.toString())9println(connectRequest.toString())

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Fuel automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful