edu.usc.bg.base
Class ByteIterator

java.lang.Object
  extended by edu.usc.bg.base.ByteIterator
All Implemented Interfaces:
java.util.Iterator<java.lang.Byte>
Direct Known Subclasses:
ByteArrayByteIterator, InputStreamByteIterator, ObjectByteIterator, RandomByteIterator, StringByteIterator

public abstract class ByteIterator
extends java.lang.Object
implements java.util.Iterator<java.lang.Byte>

ByteIterators are designed to support efficient field generation, and to allow backend drivers that can stream fields (instead of materializing them in RAM) to do so.

String objects were used to represent field values. This led to two performance issues.

First, it leads to unnecessary conversions between UTF-16 and UTF-8, both during field generation, and when passing data to byte-based backend drivers.

Second, Java strings are represented internally using UTF-16, and are built by appending to a growable array type (StringBuilder or StringBuffer), then calling a toString() method. This leads to a 4x memory overhead as field values are being built, which prevented BG from driving large object stores.

The StringByteIterator class contains a number of convenience methods for backend drivers that convert between Map<String,String> and Map<String,ByteBuffer>.

Author:
sears

Constructor Summary
ByteIterator()
           
 
Method Summary
abstract  long bytesLeft()
           
abstract  boolean hasNext()
           
 java.lang.Byte next()
           
 int nextBuf(byte[] buf, int buf_off)
           
abstract  byte nextByte()
           
 void remove()
           
 byte[] toArray()
          Consumes remaining contents of this object, and returns them as a byte array.
 java.lang.String toString()
          Consumes remaining contents of this object, and returns them as a string.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ByteIterator

public ByteIterator()
Method Detail

hasNext

public abstract boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator<java.lang.Byte>

next

public java.lang.Byte next()
Specified by:
next in interface java.util.Iterator<java.lang.Byte>

nextByte

public abstract byte nextByte()

nextBuf

public int nextBuf(byte[] buf,
                   int buf_off)
Returns:
byte offset immediately after the last valid byte

bytesLeft

public abstract long bytesLeft()

remove

public void remove()
Specified by:
remove in interface java.util.Iterator<java.lang.Byte>

toString

public java.lang.String toString()
Consumes remaining contents of this object, and returns them as a string.

Overrides:
toString in class java.lang.Object

toArray

public byte[] toArray()
Consumes remaining contents of this object, and returns them as a byte array.