avabrake.0.1.5.source-code.Truncator Maven / Gradle / Ivy
package io.airbrake.javabrake;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
class Truncator {
int maxStringLength = 1024;
int maxMapSize = 128;
int maxListSize = 32;
int maxDepth = 8;
Truncator(int level) {
this.maxStringLength = Math.max(1, this.maxStringLength >> level);
this.maxMapSize = Math.max(1, this.maxMapSize >> level);
this.maxListSize = Math.max(1, this.maxListSize >> level);
this.maxDepth = Math.max(1, this.maxDepth >> level);
}
Object truncate(Object obj, int depth) {
if (obj instanceof String) {
String s = (String) obj;
if (s.length() > this.maxStringLength) {
s = s.substring(0, this.maxStringLength);
}
return s;
}
if (obj instanceof Map) {
depth++;
if (depth > this.maxDepth) {
return "[Truncated Map]";
}
Map map = (Map) obj;
return this.truncateMap(map, depth);
}
if (obj instanceof List) {
depth++;
if (depth > this.maxDepth) {
return "[Truncated List]";
}
List