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

The following examples show how to use io.airlift.slice.DynamicSliceOutput#appendInt() . 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: StringClassifierAdapter.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public byte[] getSerializedData()
{
    byte[] classifierBytes = serialize(classifier).getBytes();
    DynamicSliceOutput output = new DynamicSliceOutput(classifierBytes.length + 64 * labelEnumeration.size());
    output.appendInt(classifierBytes.length);
    output.appendBytes(classifierBytes);
    output.appendInt(labelEnumeration.size());
    // Write the enumeration keys
    for (Map.Entry<Integer, String> entry : labelEnumeration.entrySet()) {
        output.appendInt(entry.getKey());
        byte[] bytes = entry.getValue().getBytes(UTF_8);
        output.appendInt(bytes.length);
        output.appendBytes(bytes);
    }

    return output.slice().getBytes();
}
 
Example 2
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 3
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);
    }
}