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 007import de.bytefish.pgbulkinsert.util.StringUtils; 008 009public class StringValueHandler extends BaseValueHandler<String> { 010 011 @Override 012 protected void internalHandle(DataOutputStream buffer, final String value) throws Exception { 013 byte[] utf8Bytes = StringUtils.getUtf8Bytes(value); 014 015 buffer.writeInt(utf8Bytes.length); 016 buffer.write(utf8Bytes); 017 } 018 019 @Override 020 public int getLength(String value) { 021 byte[] utf8Bytes = StringUtils.getUtf8Bytes(value); 022 023 return utf8Bytes.length; 024 } 025}