HBASE-9031 ImmutableBytesWritable.toString() should downcast the bytes before converting to hex string

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1509842 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2013-08-02 20:08:30 +00:00
parent a1cb0fc0e8
commit 3ad1139378
1 changed files with 6 additions and 8 deletions

View File

@ -212,20 +212,18 @@ implements WritableComparable<ImmutableBytesWritable> {
*/ */
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(3*this.bytes.length); StringBuilder sb = new StringBuilder(3*this.length);
for (int idx = offset; idx < offset + length; idx++) { final int endIdx = this.offset + this.length;
// if not the first, put a blank separator in for (int idx = this.offset; idx < endIdx ; idx++) {
if (idx != offset) {
sb.append(' '); sb.append(' ');
} String num = Integer.toHexString(0xff & this.bytes[idx]);
String num = Integer.toHexString(bytes[idx]);
// if it is only one digit, add a leading 0. // if it is only one digit, add a leading 0.
if (num.length() < 2) { if (num.length() < 2) {
sb.append('0'); sb.append('0');
} }
sb.append(num); sb.append(num);
} }
return sb.toString(); return sb.length() > 0 ? sb.substring(1) : "";
} }
/** A Comparator optimized for ImmutableBytesWritable. /** A Comparator optimized for ImmutableBytesWritable.