public int position() { return buf.position(); } public ByteOrder order() { return buf.order(); }
public void position(int pos) { buf.position(pos); } public void order(ByteOrder v) { buf.order(v); }
public final void mark() { buffer.mark(); mark = position(); } public final int position() {
/** * Reads a 31-bit positive integer from the buffer, which was written using 1 or 4 bytes. * * @return the integer read */ public int getInt1_4Bytes() { byte flagByte = get(); position(position() - 1); if ((flagByte & 0x80) != 0) { //length 4 bytes return getInt() & 0x7FFFFFFF; } else { //length 1 byte return get(); } }
public String toString() { return "GrowableByteBuffer" + "[pos="+ position() + " lim=" + limit() + " cap=" + capacity() + " grow=" + growFactor + "]"; } public static GrowableByteBuffer wrap(byte[] array) {
public void serialize(OutputStream out) throws SerializationException { DocumentSerializer writer = DocumentSerializerFactory.create6(new GrowableByteBuffer(64 * 1024, 2.0f)); writer.write(this); GrowableByteBuffer data = writer.getBuf(); byte[] array; if (data.hasArray()) { //just get the array array = data.array(); } else { //copy the bytebuffer into the array array = new byte[data.position()]; int endPos = data.position(); data.position(0); data.get(array); data.position(endPos); } try { out.write(array, 0, data.position()); } catch (IOException ioe) { throw new SerializationException(ioe); } }
/** * Reads a 30-bit positive integer from the buffer, which was written using 1, 2, or 4 bytes. * * @return the integer read */ public int getInt1_2_4Bytes() { byte flagByte = get(); position(position() - 1); if ((flagByte & 0x80) != 0) { if ((flagByte & 0x40) != 0) { //length 4 bytes return getInt() & 0x3FFFFFFF; } else { //length 2 bytes return getShort() & 0x3FFF; } } else { //length 1 byte return get(); } }
/** * Reads a 62-bit positive integer from the buffer, which was written using 2, 4, or 8 bytes. * * @return the integer read */ public long getInt2_4_8Bytes() { byte flagByte = get(); position(position() - 1); if ((flagByte & 0x80) != 0) { if ((flagByte & 0x40) != 0) { //length 8 bytes return getLong() & 0x3FFFFFFFFFFFFFFFL; } else { //length 4 bytes return getInt() & 0x3FFFFFFF; } } else { //length 2 bytes return getShort(); } }
/** * Write out the value of weighted set field * * @param field - field description (name and data type) * @param ws - field value */ public <T extends FieldValue> void write(FieldBase field, WeightedSet<T> ws) { WeightedSetDataType type = ws.getDataType(); putInt(null, type.getNestedType().getId()); putInt(null, ws.size()); Iterator<T> it = ws.fieldValueIterator(); while (it.hasNext()) { FieldValue key = it.next(); java.lang.Integer value = ws.get(key); int sizePos = buf.position(); putInt(null, 0); int startPos = buf.position(); key.serialize(this); putInt(null, value); int finalPos = buf.position(); int size = finalPos - startPos; buf.position(sizePos); putInt(null, size); buf.position(finalPos); } }
/** * Write out the value of weighted set field * * @param field - field description (name and data type) * @param ws - field value */ public <T extends FieldValue> void write(FieldBase field, WeightedSet<T> ws) { WeightedSetDataType type = ws.getDataType(); putInt(null, type.getNestedType().getId()); putInt(null, ws.size()); Iterator<T> it = ws.fieldValueIterator(); while (it.hasNext()) { FieldValue key = it.next(); java.lang.Integer value = ws.get(key); int sizePos = buf.position(); putInt(null, 0); int startPos = buf.position(); key.serialize(this); putInt(null, value); int finalPos = buf.position(); int size = finalPos - startPos; buf.position(sizePos); putInt(null, size); buf.position(finalPos); } }
public int getSerializedSize() throws SerializationException { DocumentSerializer data = DocumentSerializerFactory.create6(new GrowableByteBuffer(64 * 1024, 2.0f)); data.write(this); return data.getBuf().position(); }
private SpanNode readSpanNode() { byte type = buf.get(); buf.position(buf.position() - 1); SpanNode retval; if ((type & Span.ID) == Span.ID) { retval = new Span(); if (spanNodes != null) { spanNodes.add(retval); } read((Span) retval); } else if ((type & SpanList.ID) == SpanList.ID) { retval = new SpanList(); if (spanNodes != null) { spanNodes.add(retval); } read((SpanList) retval); } else if ((type & AlternateSpanList.ID) == AlternateSpanList.ID) { retval = new AlternateSpanList(); if (spanNodes != null) { spanNodes.add(retval); } read((AlternateSpanList) retval); } else { throw new DeserializationException("Cannot read SpanNode of type " + type); } return retval; }
private SpanNode readSpanNode() { byte type = buf.get(); buf.position(buf.position() - 1); SpanNode retval; if ((type & Span.ID) == Span.ID) { retval = new Span(); if (spanNodes != null) { spanNodes.add(retval); } read((Span) retval); } else if ((type & SpanList.ID) == SpanList.ID) { retval = new SpanList(); if (spanNodes != null) { spanNodes.add(retval); } read((SpanList) retval); } else if ((type & AlternateSpanList.ID) == AlternateSpanList.ID) { retval = new AlternateSpanList(); if (spanNodes != null) { spanNodes.add(retval); } read((AlternateSpanList) retval); } else { throw new DeserializationException("Cannot read SpanNode of type " + type); } return retval; }
/** * Returns the serialized size of the given {@link Document}. Please note that this method performs actual * serialization of the document, but simply return the size of the final {@link GrowableByteBuffer}. If you need * the buffer itself, do NOT use this method. * * @param doc The Document whose size to calculate. * @return The size in bytes. */ public static long getSerializedSize(Document doc) { DocumentSerializer serializer = new VespaDocumentSerializer6(new GrowableByteBuffer()); serializer.write(doc); return serializer.getBuf().position(); }
/** * Returns the serialized size of the given {@link Document}. Please note that this method performs actual * serialization of the document, but simply return the size of the final {@link GrowableByteBuffer}. If you need * the buffer itself, do NOT use this method. * * @param doc The Document whose size to calculate. * @return The size in bytes. */ public static long getSerializedSize(Document doc) { DocumentSerializer serializer = new VespaDocumentSerializerHead(new GrowableByteBuffer()); serializer.write(doc); return serializer.getBuf().position(); }
return new byte[0]; byte[] ret = new byte[out.getBuf().position()]; out.getBuf().rewind(); out.getBuf().get(ret);
public byte[] serialize() { BufferSerializer out = new BufferSerializer(new GrowableByteBuffer()); out.putInt(null, distributionBits); out.putLong(null, bucketCursor); out.putLong(null, finishedBucketCount); out.putLong(null, totalBucketCount); out.putInt(null, buckets.size()); // Append individual bucket progress for (Map.Entry<BucketKeyWrapper, ProgressToken.BucketEntry> entry : buckets.entrySet()) { out.putLong(null, keyToBucketId(entry.getKey().getKey())); out.putLong(null, entry.getValue().getProgress().getRawId()); } byte[] ret = new byte[out.getBuf().position()]; out.getBuf().rewind(); out.getBuf().get(ret); return ret; }