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

com.emv.qrcode.model.cpm.CommonDataTransparentTemplate Maven / Gradle / Ivy

There is a newer version: 0.1.2
Show newest version
package com.emv.qrcode.model.cpm;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Objects;

import org.apache.commons.lang3.ArrayUtils;

import com.emv.qrcode.core.model.BERTLV;
import com.emv.qrcode.model.cpm.constants.ConsumerPresentedModeFieldCodes;

import lombok.Getter;
import lombok.Setter;

@Getter
public class CommonDataTransparentTemplate implements BERTLV> {

  private static final long serialVersionUID = 5072500891200624780L;

  @Setter
  private BERTLV value;

  @Override
  public Integer getTag() {
    return ConsumerPresentedModeFieldCodes.ID_COMMON_DATA_TRANSPARENT_TEMPLATE;
  }

  @Override
  public byte[] getBytes() throws IOException {

    if (Objects.isNull(value)) {
      return EMPTY_BYTES;
    }

    final byte[] bytes = value.getBytes();

    if (ArrayUtils.isEmpty(bytes)) {
      return EMPTY_BYTES;
    }

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
      out.write(getTag());
      out.write(bytes.length);
      out.write(bytes);
      return out.toByteArray();
    }

  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy