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

com.credibledoc.iso8583packer.binary.BinaryToHexStringer Maven / Gradle / Ivy

There is a newer version: 1.0.51
Show newest version
package com.credibledoc.iso8583packer.binary;

import com.credibledoc.iso8583packer.exception.PackerRuntimeException;
import com.credibledoc.iso8583packer.hex.HexService;
import com.credibledoc.iso8583packer.stringer.Stringer;

/**
 * Converts byte array to hex String.
 * 
 * @author Kyrylo Semenko
 */
public class BinaryToHexStringer implements Stringer {

    /**
     * Single instance.
     */
    private static BinaryToHexStringer instance;

    /**
     * Only one instance is allowed, see the {@link #getInstance()} method.
     */
    private BinaryToHexStringer() {
        // empty
    }

    /**
     * @return The {@link #instance} singleton.
     */
    public static BinaryToHexStringer getInstance() {
        if (instance == null) {
            instance = new BinaryToHexStringer();
        }
        return instance;
    }

    @Override
    public String convert(Object object) {
        if (object == null) {
            return null;
        }
        if (!(object instanceof byte[])) {
            throw new PackerRuntimeException("Expected byte array but found " + object.getClass().getSimpleName());
        }
        return HexService.bytesToHex((byte[]) object);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy