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 de.bytefish.pgbulkinsert.exceptions.BinaryWriteFailedException;
006
007import java.io.DataOutputStream;
008
009public abstract class BaseValueHandler<T> implements IValueHandler<T> {
010
011    @Override
012    public void handle(DataOutputStream buffer, final T value) {
013        try {
014            if (value == null) {
015                buffer.writeInt(-1);
016                return;
017            }
018            internalHandle(buffer, value);
019        } catch (Exception e) {
020            throw new BinaryWriteFailedException(e);
021        }
022    }
023
024    protected abstract void internalHandle(DataOutputStream buffer, final T value) throws Exception;
025}