mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-05 18:52:41 +02:00
Removed splitFileName function as both file name and extension are known separately
This commit is contained in:
@@ -35,9 +35,7 @@ object MediaCompressorFileUtils {
|
|||||||
context: Context,
|
context: Context,
|
||||||
): File {
|
): File {
|
||||||
val extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(context.contentResolver.getType(uri)) ?: ""
|
val extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(context.contentResolver.getType(uri)) ?: ""
|
||||||
val fileName = UUID.randomUUID().toString() + ".$extension"
|
val tempFile = File.createTempFile(UUID.randomUUID().toString(), extension)
|
||||||
val (name, ext) = splitFileName(fileName)
|
|
||||||
val tempFile = File.createTempFile(name, ext)
|
|
||||||
|
|
||||||
context.contentResolver.openInputStream(uri)?.use { inputStream ->
|
context.contentResolver.openInputStream(uri)?.use { inputStream ->
|
||||||
FileOutputStream(tempFile).use { outputStream ->
|
FileOutputStream(tempFile).use { outputStream ->
|
||||||
@@ -54,13 +52,4 @@ object MediaCompressorFileUtils {
|
|||||||
) {
|
) {
|
||||||
input.copyTo(output, bufferSize = 1024 * 50)
|
input.copyTo(output, bufferSize = 1024 * 50)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun splitFileName(fileName: String): Pair<String, String> {
|
|
||||||
val i = fileName.lastIndexOf(".")
|
|
||||||
return if (i != -1) {
|
|
||||||
fileName.substring(0, i) to fileName.substring(i)
|
|
||||||
} else {
|
|
||||||
fileName to ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user