Cutting off everything after '?' of icon's url for icon filename

This commit is contained in:
dankito 2020-05-16 23:38:50 +02:00
parent 14af1148f8
commit e7b448126b
1 changed files with 6 additions and 1 deletions

View File

@ -26,6 +26,7 @@ import java.io.File
import java.io.FileOutputStream import java.io.FileOutputStream
import java.math.BigDecimal import java.math.BigDecimal
import java.net.URL import java.net.URL
import java.net.URLEncoder
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
@ -197,7 +198,11 @@ open class BankingPresenter(
val bankIconsDir = File(dataFolder, "bank_icons") val bankIconsDir = File(dataFolder, "bank_icons")
bankIconsDir.mkdirs() bankIconsDir.mkdirs()
val bankIconFile = File(bankIconsDir, File(bankIconUrl).name) var iconFilename = File(bankIconUrl).name
if (iconFilename.contains('?')) {
iconFilename = iconFilename.substring(0, iconFilename.indexOf('?'))
}
val bankIconFile = File(bankIconsDir, URLEncoder.encode(iconFilename, Charsets.US_ASCII.name()))
URL(bankIconUrl).openConnection().getInputStream().buffered().use { iconInputStream -> URL(bankIconUrl).openConnection().getInputStream().buffered().use { iconInputStream ->
FileOutputStream(bankIconFile).use { fileOutputStream -> FileOutputStream(bankIconFile).use { fileOutputStream ->