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

com.emv.qrcode.decoder.cpm.DecoderCpm Maven / Gradle / Ivy

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

import java.lang.reflect.Constructor;
import java.util.AbstractMap.SimpleEntry;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.function.BiConsumer;

import com.emv.qrcode.core.configuration.DecodersCpmMap;

// @formatter:off
public abstract class DecoderCpm {

  protected final Iterator iterator;

  protected DecoderCpm(final byte[] source) {
    this.iterator = new DecodeCpmIterator(source);
  }

  protected abstract T decode();

  protected static  Entry, BiConsumer> consumerTagLengthValue(final Class clazz, final BiConsumer consumer) {
    return new SimpleEntry<>(clazz, consumer);
  }

  public static  T decode(final byte[] source, final Class clazz) {
    try {
      final Class> parserClass = DecodersCpmMap.getDecoder(clazz);
      final Constructor> ctor = parserClass.getConstructor(byte[].class);
      final DecoderCpm parser = ctor.newInstance(source);
      return clazz.cast(parser.decode());
    } catch (final Exception ex) {
      throw new RuntimeException(ex);
    }
  }

}
// @formatter:on




© 2015 - 2024 Weber Informatics LLC | Privacy Policy