- java.lang.Object
- 
- com.pervasive.datarush.io.BinaryBuilder
 
- 
 public class BinaryBuilder extends Object A buffer for building variable-length binary valued data. An internal buffer is used to accumulate the binary value, resizing as necessary. Additionally, a number of encodings for multi-byte values such as (but not limited to) longs and doubles is supported. ABinaryBuilderis similar in function toStringBuilder, although it does not allow mutation of previously written data.
- 
- 
Constructor SummaryConstructors Constructor Description BinaryBuilder(int initialSize)Creates a new buffer sized as specified.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(byte value)Appends a byte to the buffer.voidappend(byte[] values)Appends a sequence of bytes to the buffer.voidappend(byte[] values, int offset, int length)Appends a subsequence of bytes to the buffer.voidappend(char data)Appends a character value to the buffer.voidappend(double value)Appends a a double value to the buffer.voidappend(float value)Appends a float value to the buffer.voidappend(int value)Appends an int value to the buffer.voidappend(long value)Appends a long value to the buffer.voidappend(CharSequence values)Appends a sequence of character values to the buffer.voidappendBase128(int value)Appends an int value to the buffer, using variable length base-128 encoding.voidappendBase128(long value)Appends a long value to the buffer, using variable length base-128 encoding.voidappendSingleByte(CharSequence values)Appends a sequence of character values to the buffer using only a single byte per character.voidappendUnsignedBase128(int value)Appends an int value to the buffer, using variable length base-128 encoding with bias towards non-negative values.voidappendUnsignedBase128(long value)Appends a long value to the buffer, using variable length base-128 encoding with bias towards non-negative values.static intbase128Size(int value)Computes the length of the base-128 encoding of an int value.static intbase128Size(long value)Computes the length of the base-128 encoding of an long value.voidcopy(byte[] dest, int offset)Extracts the current contents of the builder to the specified array at the given offset.static voidencodeInt32(int value, byte[] data, int offset)Writes a 32-bit integer value into the specified position in the given array.static voidencodeUnsignedBase128(long value, byte[] data, int offset)Writes a 64-bit integer value using base-128 encoding into the specified position in the given array.voidreset()Resets the buffer to empty.voidset(int position, int data)Sets 4 bytes beginning at the specified position to the given value.intsize()Gets the current size of the binary sequence represented by the builder.byte[]toBinary()Gets the current contents of the builder.ByteBuffertoByteBuffer()Gets aByteBufferthat wraps the internal bytes storage of this builder object.StringtoString()static intunsignedBase128Size(int value)Computes the length of the non-negative biased base-128 encoding of an int value.static intunsignedBase128Size(long value)Computes the length of the non-negative biased base-128 encoding of an long value.voidwriteToStream(OutputStream out)Writes the current contents of the builder to the specifiedOutputStream.
 
- 
- 
- 
Method Detail- 
sizepublic int size() Gets the current size of the binary sequence represented by the builder.- Returns:
- the current size of the binary data
 
 - 
setpublic void set(int position, int data)Sets 4 bytes beginning at the specified position to the given value.- Parameters:
- position- the byte offset at which to write the update
- data- the 4 byte value to write
 
 - 
appendpublic void append(byte value) Appends a byte to the buffer.- Parameters:
- value- the byte to append
 
 - 
appendpublic void append(byte[] values) Appends a sequence of bytes to the buffer.This is equivalent to calling append(values, 0, values.length).- Parameters:
- values- the bytes to append
 
 - 
appendpublic void append(byte[] values, int offset, int length)Appends a subsequence of bytes to the buffer.- Parameters:
- values- the sequence containing the bytes to append
- offset- the starting position of the subsequence
- length- the length of the subsequence
 
 - 
appendpublic void append(char data) Appends a character value to the buffer. Values are represented using 2 bytes.- Parameters:
- data- the character to append
 
 - 
appendpublic void append(CharSequence values) Appends a sequence of character values to the buffer.Functionally equivalent to calling append(char)on every element in the sequence, though slightly more efficient.- Parameters:
- values- the character values to append
 
 - 
appendSingleBytepublic void appendSingleByte(CharSequence values) Appends a sequence of character values to the buffer using only a single byte per character. The least significant byte is encoded. Therefore this encoding can be lossy if any characters cannot be represented in a single byte.- Parameters:
- values- the character values to append
 
 - 
appendpublic void append(int value) Appends an int value to the buffer. Values are represented using 4 bytes.- Parameters:
- value- the value to append
 
 - 
appendUnsignedBase128public void appendUnsignedBase128(int value) Appends an int value to the buffer, using variable length base-128 encoding with bias towards non-negative values. If values are known to be non-negative, this guarantees an equal or smaller sized encoding thanappendBase128(int)produces. Negative values will always encode to the maximum length.Base-128 can produce more compact encodings, with the size being proportional to the size of the value. Encodings will vary between 1 and 5 bytes, depending on the value encoded. - Parameters:
- value- the unsigned value to append in base-128
 
 - 
appendBase128public void appendBase128(int value) Appends an int value to the buffer, using variable length base-128 encoding. Encoding is unbiased with respect to sign, so that values with smaller absolute values will have shorter encodings.Base-128 can produce more compact encodings, with the size being proportional to the size of the value. Encodings will vary between 1 and 5 bytes, depending on the value encoded. - Parameters:
- value- the signed value to append in base-128
 
 - 
appendpublic void append(long value) Appends a long value to the buffer. Values are represented using 8 bytes.- Parameters:
- value- the value to append
 
 - 
appendUnsignedBase128public void appendUnsignedBase128(long value) Appends a long value to the buffer, using variable length base-128 encoding with bias towards non-negative values. If values are known to be non-negative, this guarantees an equal or smaller sized encoding thanappendBase128(long)produces. Negative values will always encode to the maximum length.Base-128 can produce more compact encodings, with the size being proportional to the size of the value. Encodings will vary between 1 and 10 bytes, depending on the value encoded. - Parameters:
- value- the unsigned value to append in base-128
 
 - 
appendBase128public void appendBase128(long value) Appends a long value to the buffer, using variable length base-128 encoding. Encoding is unbiased with respect to sign, so that values with smaller absolute values will have shorter encodings.Base-128 can produce more compact encodings, with the size being proportional to the size of the value. Encodings will vary between 1 and 10 bytes, depending on the value encoded. - Parameters:
- value- the signed value to append in base-128
 
 - 
appendpublic void append(float value) Appends a float value to the buffer. Values are represented using 4 bytes, as mapped byFloat.floatToRawIntBits(float).- Parameters:
- value- the value to append
 
 - 
appendpublic void append(double value) Appends a a double value to the buffer. Values are represented using 8 bytes, as mapped byDouble.doubleToRawLongBits(double).- Parameters:
- value- the value to append
 
 - 
toBinarypublic byte[] toBinary() Gets the current contents of the builder.- Returns:
- a copy of the current buffer
 
 - 
toByteBufferpublic ByteBuffer toByteBuffer() Gets aByteBufferthat wraps the internal bytes storage of this builder object. The byte buffer will wrap from the start of the internal byte storage to its current size.- Returns:
- ByteBuffer wrapping the internal storage of this builder
 
 - 
copypublic void copy(byte[] dest, int offset)Extracts the current contents of the builder to the specified array at the given offset.- Parameters:
- dest- the target array into which to copy
- offset- the offset into the target array at which to start
 
 - 
writeToStreampublic void writeToStream(OutputStream out) throws IOException Writes the current contents of the builder to the specifiedOutputStream. This is more efficient than callingout.write(toBinary()), as it avoids making an extra copy of the data.- Parameters:
- out- the target to which to write the buffer contents
- Throws:
- IOException- if an error occurs during the write
 
 - 
resetpublic void reset() Resets the buffer to empty.
 - 
base128Sizepublic static final int base128Size(int value) Computes the length of the base-128 encoding of an int value.- Parameters:
- value- the value for which to determine the encoding size
- Returns:
- the length, in bytes, of the encoding
- See Also:
- appendBase128(int)
 
 - 
unsignedBase128Sizepublic static final int unsignedBase128Size(int value) Computes the length of the non-negative biased base-128 encoding of an int value.- Parameters:
- value- the value for which to determine the encoding size
- Returns:
- the length, in bytes, of the encoding
- See Also:
- appendUnsignedBase128(int)
 
 - 
base128Sizepublic static final int base128Size(long value) Computes the length of the base-128 encoding of an long value.- Parameters:
- value- the value for which to determine the encoding size
- Returns:
- the length, in bytes, of the encoding
- See Also:
- appendBase128(long)
 
 - 
unsignedBase128Sizepublic static final int unsignedBase128Size(long value) Computes the length of the non-negative biased base-128 encoding of an long value.- Parameters:
- value- the value for which to determine the encoding size
- Returns:
- the length, in bytes, of the encoding
- See Also:
- appendUnsignedBase128(int)
 
 - 
encodeInt32public static final void encodeInt32(int value, byte[] data, int offset)Writes a 32-bit integer value into the specified position in the given array.- Parameters:
- value- the value to write
- data- the buffer to update
- offset- the byte offset at which to write
 
 - 
encodeUnsignedBase128public static final void encodeUnsignedBase128(long value, byte[] data, int offset)Writes a 64-bit integer value using base-128 encoding into the specified position in the given array.- Parameters:
- value- the value to write in base-128
- data- the buffer to update
- offset- the byte offset at which to write
 
 
- 
 
-