-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Move to commons module - Deprecate dropToString() api
- Loading branch information
Showing
8 changed files
with
267 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 0 additions & 90 deletions
90
...strap-core/src/test/java/com/navercorp/pinpoint/bootstrap/plugin/jdbc/ArrayUtilsTest.java
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
commons/src/main/java/com/navercorp/pinpoint/common/util/ArrayUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2016 NAVER Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.navercorp.pinpoint.common.util; | ||
|
||
/** | ||
* @author Woonduk Kang(emeroad) | ||
*/ | ||
public final class ArrayUtils { | ||
|
||
private static final int DEFAULT_ABBREVIATE_MAX_WIDTH = 32; | ||
|
||
private ArrayUtils() { | ||
} | ||
|
||
public static String abbreviate(byte[] bytes) { | ||
return abbreviate(bytes, DEFAULT_ABBREVIATE_MAX_WIDTH); | ||
} | ||
|
||
public static String abbreviate(byte[] bytes, int maxWidth) { | ||
if (bytes == null) { | ||
return "null"; | ||
} | ||
if (maxWidth < 0) { | ||
throw new IllegalArgumentException("negative maxWidth:" + maxWidth); | ||
} | ||
// TODO handle negative limit | ||
|
||
// Last valid index is length - 1 | ||
int bytesMaxLength = bytes.length - 1; | ||
final int maxLimit = maxWidth - 1; | ||
if (bytesMaxLength > maxLimit) { | ||
bytesMaxLength = maxLimit; | ||
} | ||
if (bytesMaxLength == -1) { | ||
if (bytes.length == 0) { | ||
return "[]"; | ||
} else { | ||
return "[...(" + bytes.length + ")]"; | ||
} | ||
} | ||
|
||
|
||
final StringBuilder sb = new StringBuilder(); | ||
sb.append('['); | ||
for (int i = 0; ; i++) { | ||
sb.append(bytes[i]); | ||
if (i == bytesMaxLength) { | ||
if ((bytes.length - 1) <= maxLimit) { | ||
return sb.append(']').toString(); | ||
} else { | ||
sb.append(", ...("); | ||
sb.append(bytes.length - (i+1)); | ||
sb.append(")]"); | ||
return sb.toString(); | ||
} | ||
} | ||
sb.append(", "); | ||
} | ||
} | ||
} |
Oops, something went wrong.