All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.bytefish.pgbulkinsert.pgsql.handlers.JsonbValueHandler Maven / Gradle / Ivy

There is a newer version: 7.0.1
Show newest version
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

package de.bytefish.pgbulkinsert.pgsql.handlers;

import java.io.DataOutputStream;

public class JsonbValueHandler extends BaseValueHandler {

    private final int jsonbProtocolVersion;

    public JsonbValueHandler() {
        this(1);
    }

    public JsonbValueHandler(int jsonbProtocolVersion) {
        this.jsonbProtocolVersion = jsonbProtocolVersion;
    }

    @Override
    protected void internalHandle(DataOutputStream buffer, final String value) throws Exception {

        byte[] utf8Bytes = value.getBytes("UTF-8");

        // Write the Length of the Data to Copy:
        buffer.writeInt(utf8Bytes.length + 1);
        // Write the Jsonb Protocol Version:
        buffer.writeByte(jsonbProtocolVersion);
        // Copy the Data:
        buffer.write(utf8Bytes);
    }

    @Override
    public int getLength(String value) {
        throw new UnsupportedOperationException();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy