Java Code Examples for io.airlift.slice.DynamicSliceOutput#size()

The following examples show how to use io.airlift.slice.DynamicSliceOutput#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JtsGeometrySerde.java    From presto with Apache License 2.0 6 votes vote down vote up
private static void writeGeometryCollection(Geometry collection, DynamicSliceOutput output)
{
    output.appendByte(GeometrySerializationType.GEOMETRY_COLLECTION.code());
    for (int geometryIndex = 0; geometryIndex < collection.getNumGeometries(); geometryIndex++) {
        Geometry geometry = collection.getGeometryN(geometryIndex);
        int startPosition = output.size();

        // leave 4 bytes for the shape length
        output.appendInt(0);
        writeGeometry(geometry, output);

        int endPosition = output.size();
        int length = endPosition - startPosition - Integer.BYTES;

        output.getUnderlyingSlice().setInt(startPosition, length);
    }
}
 
Example 2
Source File: GeometrySerde.java    From presto with Apache License 2.0 6 votes vote down vote up
private static void writeGeometryCollection(DynamicSliceOutput output, OGCGeometryCollection collection)
{
    output.appendByte(GeometrySerializationType.GEOMETRY_COLLECTION.code());
    for (int geometryIndex = 0; geometryIndex < collection.numGeometries(); geometryIndex++) {
        OGCGeometry geometry = collection.geometryN(geometryIndex);
        int startPosition = output.size();

        // leave 4 bytes for the shape length
        output.appendInt(0);
        writeGeometry(output, geometry);

        int endPosition = output.size();
        int length = endPosition - startPosition - Integer.BYTES;

        output.getUnderlyingSlice().setInt(startPosition, length);
    }
}
 
Example 3
Source File: TestBlockRetainedSizeBreakdown.java    From presto with Apache License 2.0 5 votes vote down vote up
private static Block createVariableWidthBlock(int entries)
{
    int[] offsets = new int[entries + 1];
    DynamicSliceOutput dynamicSliceOutput = new DynamicSliceOutput(entries);
    for (int i = 0; i < entries; i++) {
        dynamicSliceOutput.writeByte(i);
        offsets[i + 1] = dynamicSliceOutput.size();
    }
    return new VariableWidthBlock(entries, dynamicSliceOutput.slice(), offsets, Optional.empty());
}