mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-19 09:47:27 +10:00
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@626 84d0f5b1-2673-498c-a247-62c4ff18d310
54 lines
1.4 KiB
Java
54 lines
1.4 KiB
Java
package com.profiler.util;
|
|
|
|
|
|
public class ArrayUtils {
|
|
|
|
public static String dropToString(byte[] bytes) {
|
|
return dropToString(bytes, 10);
|
|
}
|
|
|
|
public static String dropToString(byte[] bytes, int limit) {
|
|
if (bytes == null) {
|
|
return "null";
|
|
}
|
|
// TODO limit음수일 경우 예외처리 필요.
|
|
// size 4인 배열의 경 3에서 멈춰야 하므로 -1
|
|
int iMax = bytes.length - 1;
|
|
int iLimit = limit - 1;
|
|
if (iMax > iLimit) {
|
|
iMax = iLimit;
|
|
}
|
|
if (iMax == -1) {
|
|
if (bytes.length == 0) {
|
|
return "[]";
|
|
} else {
|
|
return "[...(" + bytes.length + ")]";
|
|
}
|
|
}
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append('[');
|
|
for (int i = 0; ; i++) {
|
|
sb.append(bytes[i]);
|
|
if (i == iMax) {
|
|
if (iMax < iLimit) {
|
|
return sb.append(']').toString();
|
|
} else {
|
|
if (i > 0) {
|
|
|
|
}
|
|
sb.append(", ");
|
|
sb.append("...(");
|
|
sb.append(bytes.length);
|
|
sb.append(")]");
|
|
return sb.toString();
|
|
}
|
|
}
|
|
sb.append(", ");
|
|
}
|
|
}
|
|
|
|
|
|
}
|