jw
03/09/2023, 4:41 PMdave08
03/13/2023, 1:41 PMimport okio.*
class FilterCharacterSource(private val delegate: Source, private val charToRemove: Char) : ForwardingSource(delegate) {
override fun read(sink: Buffer, byteCount: Long): Long {
// Read from the delegate source into a temporary buffer
val tempBuffer = Buffer()
val bytesRead = delegate.read(tempBuffer, byteCount)
// Remove the character to be filtered from the temporary buffer
for (i in 0 until bytesRead) {
val c = tempBuffer.readUtf8CodePoint().toChar()
if (c != charToRemove) {
sink.writeUtf8CodePoint(c.toInt())
}
}
return bytesRead
}
}