import java.nio.ByteBuffer
import java.nio.charset.CharacterCodingException
import static java.nio.charset.StandardCharsets.UTF_8
final decoder = UTF_8.newDecoder()
final buffer = ByteBuffer.wrap(s)
try {
decoder.decode(buffer)
b = true
} catch (CharacterCodingException e) {
b = false
}
Decoders are not thread-safe.
This is @CompileStatic compatible.
This is @CompileStatic compatible.