Implemented if a message contains large binary parts, e.g. when retrieving account transactions, these binary parts get extracted directly. For small binary parts iterating over string is faster then creating substring

This commit is contained in:
dankito 2020-05-21 01:00:12 +02:00
parent 4a890a0ba7
commit 012f164414
1 changed files with 16 additions and 4 deletions

View File

@ -730,21 +730,33 @@ open class ResponseParser @JvmOverloads constructor(
*/ */
protected open fun splitIntoPartsAndUnmask(dataString: String, separator: Char): List<String> { protected open fun splitIntoPartsAndUnmask(dataString: String, separator: Char): List<String> {
val binaryRanges = messageUtils.findBinaryDataRanges(dataString) val binaryRanges = messageUtils.findBinaryDataRanges(dataString)
val containsLargeBinaryRanges = binaryRanges.firstOrNull { it.last - it.first > 100 } != null
val parts = mutableListOf<String>() val parts = mutableListOf<String>()
var part = StringBuilder() var part = StringBuilder()
var index = 0
for (i in dataString.indices) { while (index < dataString.length) {
val char = dataString[i] val char = dataString[index]
if (isSeparator(char, dataString, separator, i, binaryRanges)) { if (containsLargeBinaryRanges && messageUtils.isInRange(index, binaryRanges)) {
binaryRanges.forEach { range ->
if (range.contains(index)) {
part.append(dataString.substring(range))
index = range.endInclusive
}
}
}
else if (isSeparator(char, dataString, separator, index, binaryRanges)) {
parts.add(part.toString()) parts.add(part.toString())
part = StringBuilder() part = StringBuilder()
} }
else if (isNotMaskingCharacter(char, dataString, separator, i, binaryRanges)) { else if (isNotMaskingCharacter(char, dataString, separator, index, binaryRanges)) {
part.append(char) part.append(char)
} }
index++
} }
if (part.isNotEmpty()) { if (part.isNotEmpty()) {