Skip to content

Commit

Permalink
feat: with binary body do not print the body contents out
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Holshausen committed Jun 17, 2020
1 parent 6257818 commit 68b0d6c
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import au.com.dius.pact.core.model.ContentType.Companion.JSONREGEXP
import au.com.dius.pact.core.model.ContentType.Companion.XMLREGEXP
import au.com.dius.pact.core.model.ContentType.Companion.XMLREGEXP2
import mu.KLogging
import org.apache.commons.codec.binary.Hex
import org.apache.tika.config.TikaConfig
import org.apache.tika.io.TikaInputStream
import org.apache.tika.metadata.Metadata
Expand Down Expand Up @@ -93,7 +94,11 @@ data class OptionalBody(

override fun toString(): String {
return when (state) {
State.PRESENT -> "PRESENT(${value!!.toString(contentType.asCharset())})"
State.PRESENT -> if (contentType.isBinaryType()) {
"PRESENT(${value!!.size} bytes starting with ${Hex.encodeHexString(slice(16))}...)"
} else {
"PRESENT(${value!!.toString(contentType.asCharset())})"
}
State.EMPTY -> "EMPTY"
State.NULL -> "NULL"
State.MISSING -> "MISSING"
Expand Down Expand Up @@ -145,6 +150,17 @@ data class OptionalBody(
}
}

fun slice(size: Int): ByteArray {
return when (state) {
State.PRESENT -> if (value!!.size > size) {
value.copyOf(size)
} else {
value
}
else -> ByteArray(0)
}
}

companion object : KLogging() {

@JvmStatic fun missing(): OptionalBody {
Expand Down

0 comments on commit 68b0d6c

Please sign in to comment.