Skip to content

Instantly share code, notes, and snippets.

@vrnsky
Created January 18, 2021 04:44
Show Gist options
  • Save vrnsky/925fcf96b598cdcf77d592138ed1940f to your computer and use it in GitHub Desktop.
Save vrnsky/925fcf96b598cdcf77d592138ed1940f to your computer and use it in GitHub Desktop.
private static void logContent(byte[] content, String contentType, String contentEncoding, String prefix) {
MediaType mediaType = MediaType.valueOf(contentType);
boolean visible = VISIBLE_TYPES.stream().anyMatch(visibleType -> visibleType.includes(mediaType));
if (visible) {
try {
String contentString = new String(content, contentEncoding);
Stream.of(contentString.split("\r\n|\r\n")).forEach(line -> logger.info("{} {}", prefix, line));
} catch (UnsupportedEncodingException e) {
logger.info("{}, [{} bytes content]", prefix, content.length);
}
} else {
logger.info("{}, [{} bytes content]", prefix, content.length);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment