Skip to content
Snippets Groups Projects
Commit b5bee232 authored by Steffen Friedrich's avatar Steffen Friedrich
Browse files

[core] ByteIterators `toString()` method now uses java.nio.CharBuffer to decode the byte array.

parent 7bfe3bcd
No related branches found
No related tags found
No related merge requests found
......@@ -16,8 +16,10 @@
*/
package com.yahoo.ycsb;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.ArrayList;
/**
* YCSB-specific buffer class. ByteIterators are designed to support
* efficient field generation, and to allow backend drivers that can stream
......@@ -73,10 +75,11 @@ public abstract class ByteIterator implements Iterator<Byte> {
/** Consumes remaining contents of this object, and returns them as a string. */
public String toString() {
StringBuilder sb = new StringBuilder();
while(this.hasNext()) { sb.append((char)nextByte()); }
return sb.toString();
Charset cset = Charset.forName("UTF-8");
CharBuffer cb = cset.decode(ByteBuffer.wrap(this.toArray()));
return cb.toString();
}
/** Consumes remaining contents of this object, and returns them as a byte array. */
public byte[] toArray() {
long left = bytesLeft();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment