[Kotlin][Client] replace java.nio.* to avoid crash on Android API 25 and bellow (#12529)

* [Kotlin][Client] replace java.nio.* to avoid crash on Android API 25 and bellow

* [Kotlin][Client] update sample projects

* [Kotlin][Client] update sample projects
This commit is contained in:
Bruno Coelho
2022-06-04 09:26:59 +01:00
committed by GitHub
parent 45a3b15b69
commit fe8187ba6d
20 changed files with 181 additions and 101 deletions

View File

@@ -118,12 +118,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
return null
}
if (T::class.java == File::class.java) {
// return tempfile
// return tempFile
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
f.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) }
return f as T
val tempFile = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
tempFile.deleteOnExit()
body.byteStream().use { inputStream ->
tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
}
val bodyContent = body.string()
if (bodyContent.isEmpty()) {