// Path: copybook4java/src/main/java/com/nordea/oss/copybook/exceptions/TypeConverterException.java
// public class TypeConverterException extends RuntimeException {
//     private static final long serialVersionUID = -7577535992947276304L;
//     public TypeConverterException(String message) {
//         super(message);
//     }
// }
// 
// Path: copybook4java/src/main/java/com/nordea/oss/copybook/serializers/CopyBookFieldSigningType.java
// public enum CopyBookFieldSigningType {
//     POSTFIX,
//     PREFIX,
//     LAST_BYTE_BIT8,
//     LAST_BYTE_EBCDIC_BIT5
// }


import com.nordea.oss.copybook.exceptions.TypeConverterException;
import com.nordea.oss.copybook.serializers.CopyBookFieldSigningType;
import java.nio.charset.Charset;
import java.util.Arrays;
/*
 * Copyright (c) 2015. Troels Liebe Bentsen <tlb@nversion.dk>
 * Copyright (c) 2016. Nordea Bank AB
 * Licensed under the MIT license (LICENSE.txt)
 */

package com.nordea.oss.copybook.converters;



public abstract class TypeConverterBase implements TypeConverter {
    protected Charset charset;
    protected CopyBookFieldSigningType signingType;
    protected boolean rightPadding;
    protected byte paddingByte;
    protected byte nullFillerByte;
    protected String defaultValue;
    protected String format;
    protected TypeConverterConfig config;

    @Override
    public void initialize(TypeConverterConfig config) {
        this.config = config;
        this.charset = config.getCharset();
        this.signingType = config.getSigningType();
        this.rightPadding = config.isRightPadding();

        byte[] paddingBytes = ( config.getPaddingChar() + "").getBytes(this.charset);
        if(paddingBytes.length > 1) {
// Path: copybook4java/src/main/java/com/nordea/oss/copybook/exceptions/TypeConverterException.java
// public class TypeConverterException extends RuntimeException {
//     private static final long serialVersionUID = -7577535992947276304L;
//     public TypeConverterException(String message) {
//         super(message);
//     }
// }
// 
// Path: copybook4java/src/main/java/com/nordea/oss/copybook/serializers/CopyBookFieldSigningType.java
// public enum CopyBookFieldSigningType {
//     POSTFIX,
//     PREFIX,
//     LAST_BYTE_BIT8,
//     LAST_BYTE_EBCDIC_BIT5
// }


// Path: copybook4java/src/main/java/com/nordea/oss/copybook/converters/TypeConverterBase.java
import com.nordea.oss.copybook.exceptions.TypeConverterException;
import com.nordea.oss.copybook.serializers.CopyBookFieldSigningType;
import java.nio.charset.Charset;
import java.util.Arrays;

/*
 * Copyright (c) 2015. Troels Liebe Bentsen <tlb@nversion.dk>
 * Copyright (c) 2016. Nordea Bank AB
 * Licensed under the MIT license (LICENSE.txt)
 */

package com.nordea.oss.copybook.converters;



public abstract class TypeConverterBase implements TypeConverter {
    protected Charset charset;
    protected CopyBookFieldSigningType signingType;
    protected boolean rightPadding;
    protected byte paddingByte;
    protected byte nullFillerByte;
    protected String defaultValue;
    protected String format;
    protected TypeConverterConfig config;

    @Override
    public void initialize(TypeConverterConfig config) {
        this.config = config;
        this.charset = config.getCharset();
        this.signingType = config.getSigningType();
        this.rightPadding = config.isRightPadding();

        byte[] paddingBytes = ( config.getPaddingChar() + "").getBytes(this.charset);
        if(paddingBytes.length > 1) {
            throw new TypeConverterException("Selected charset and padding char is more than 1 byte long");