Skip to content

Commit

Permalink
fix: fix a race condition when downloading files (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsramiel authored Nov 25, 2024
1 parent 3f2fedd commit e684f16
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.util.Log
import java.io.File
import java.net.HttpURLConnection
import java.net.URL
import java.util.UUID

class FileDescriptorProps(val id: Int, val length: Int, val offset: Int) {
companion object {
Expand All @@ -28,7 +29,7 @@ class FileDescriptorProps(val id: Int, val length: Int, val offset: Int) {
// Save the downloaded file to a temporary file
val inputStream = connection.inputStream
val tempFile =
File(context.cacheDir, "tempSoundFile")
File(context.cacheDir, "tempSoundFile_${UUID.randomUUID()}")
tempFile.outputStream().use { outputStream ->
inputStream.copyTo(outputStream)
}
Expand Down

0 comments on commit e684f16

Please sign in to comment.