001// Licensed under the MIT license. See LICENSE file in the project root for full license information. 002 003package de.bytefish.pgbulkinsert.pgsql.handlers; 004 005import java.io.DataOutputStream; 006 007public class JsonbValueHandler extends BaseValueHandler<String> { 008 009 private final int jsonbProtocolVersion; 010 011 public JsonbValueHandler() { 012 this(1); 013 } 014 015 public JsonbValueHandler(int jsonbProtocolVersion) { 016 this.jsonbProtocolVersion = jsonbProtocolVersion; 017 } 018 019 @Override 020 protected void internalHandle(DataOutputStream buffer, final String value) throws Exception { 021 022 byte[] utf8Bytes = value.getBytes("UTF-8"); 023 024 // Write the Length of the Data to Copy: 025 buffer.writeInt(utf8Bytes.length + 1); 026 // Write the Jsonb Protocol Version: 027 buffer.writeByte(jsonbProtocolVersion); 028 // Copy the Data: 029 buffer.write(utf8Bytes); 030 } 031 032 @Override 033 public int getLength(String value) { 034 throw new UnsupportedOperationException(); 035 } 036}