diff --git a/core/src/main/java/com/yahoo/ycsb/ByteIterator.java b/core/src/main/java/com/yahoo/ycsb/ByteIterator.java index 9bb3b63e36fcb6a95dbad08da0ea02cbf43f4005..568cdc1d69f4e4ea53b1fc24aea0071de580a9e6 100644 --- a/core/src/main/java/com/yahoo/ycsb/ByteIterator.java +++ b/core/src/main/java/com/yahoo/ycsb/ByteIterator.java @@ -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(); diff --git a/core/src/main/java/com/yahoo/ycsb/RandomByteIterator.java b/core/src/main/java/com/yahoo/ycsb/RandomByteIterator.java index 65db4335035ef22be38f249cc9b6ab7dcb92fe7e..cb0977aa56c8f52f4686d84aaaa23f4f30f160c2 100644 --- a/core/src/main/java/com/yahoo/ycsb/RandomByteIterator.java +++ b/core/src/main/java/com/yahoo/ycsb/RandomByteIterator.java @@ -34,11 +34,11 @@ public class RandomByteIterator extends ByteIterator { int bytes = Utils.random().nextInt(); try { buffer[base+0] = (byte)(((bytes) & 31) + ' '); - buffer[base+1] = (byte)(((bytes >> 5) & 31) + ' '); - buffer[base+2] = (byte)(((bytes >> 10) & 31) + ' '); + buffer[base+1] = (byte)(((bytes >> 5) & 63) + ' '); + buffer[base+2] = (byte)(((bytes >> 10) & 95) + ' '); buffer[base+3] = (byte)(((bytes >> 15) & 31) + ' '); - buffer[base+4] = (byte)(((bytes >> 20) & 31) + ' '); - buffer[base+5] = (byte)(((bytes >> 25) & 31) + ' '); + buffer[base+4] = (byte)(((bytes >> 20) & 63) + ' '); + buffer[base+5] = (byte)(((bytes >> 25) & 95) + ' '); } catch (ArrayIndexOutOfBoundsException e) { /* ignore it */ } }