Skip to content
Snippets Groups Projects
Commit c97afa18 authored by Sean Busbey's avatar Sean Busbey
Browse files

Merge pull request #288 from steffenfriedrich/randomByteIteratorAz

closes #279 
parents 2973ea5a b5bee232
No related branches found
No related tags found
No related merge requests found
...@@ -16,8 +16,10 @@ ...@@ -16,8 +16,10 @@
*/ */
package com.yahoo.ycsb; package com.yahoo.ycsb;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.util.Iterator; import java.util.Iterator;
import java.util.ArrayList;
/** /**
* YCSB-specific buffer class. ByteIterators are designed to support * YCSB-specific buffer class. ByteIterators are designed to support
* efficient field generation, and to allow backend drivers that can stream * efficient field generation, and to allow backend drivers that can stream
...@@ -73,10 +75,11 @@ public abstract class ByteIterator implements Iterator<Byte> { ...@@ -73,10 +75,11 @@ public abstract class ByteIterator implements Iterator<Byte> {
/** Consumes remaining contents of this object, and returns them as a string. */ /** Consumes remaining contents of this object, and returns them as a string. */
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); Charset cset = Charset.forName("UTF-8");
while(this.hasNext()) { sb.append((char)nextByte()); } CharBuffer cb = cset.decode(ByteBuffer.wrap(this.toArray()));
return sb.toString(); return cb.toString();
} }
/** Consumes remaining contents of this object, and returns them as a byte array. */ /** Consumes remaining contents of this object, and returns them as a byte array. */
public byte[] toArray() { public byte[] toArray() {
long left = bytesLeft(); long left = bytesLeft();
......
...@@ -34,11 +34,11 @@ public class RandomByteIterator extends ByteIterator { ...@@ -34,11 +34,11 @@ public class RandomByteIterator extends ByteIterator {
int bytes = Utils.random().nextInt(); int bytes = Utils.random().nextInt();
try { try {
buffer[base+0] = (byte)(((bytes) & 31) + ' '); buffer[base+0] = (byte)(((bytes) & 31) + ' ');
buffer[base+1] = (byte)(((bytes >> 5) & 31) + ' '); buffer[base+1] = (byte)(((bytes >> 5) & 63) + ' ');
buffer[base+2] = (byte)(((bytes >> 10) & 31) + ' '); buffer[base+2] = (byte)(((bytes >> 10) & 95) + ' ');
buffer[base+3] = (byte)(((bytes >> 15) & 31) + ' '); buffer[base+3] = (byte)(((bytes >> 15) & 31) + ' ');
buffer[base+4] = (byte)(((bytes >> 20) & 31) + ' '); buffer[base+4] = (byte)(((bytes >> 20) & 63) + ' ');
buffer[base+5] = (byte)(((bytes >> 25) & 31) + ' '); buffer[base+5] = (byte)(((bytes >> 25) & 95) + ' ');
} catch (ArrayIndexOutOfBoundsException e) { /* ignore it */ } } catch (ArrayIndexOutOfBoundsException e) { /* ignore it */ }
} }
......
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