// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/constants/NfcType.java
// public class NfcType {
// 
//     /**
//      * Type for the Bluetooth Application Record
//      */
//     public static final byte[] BLUETOOTH_AAR = "application/vnd.bluetooth.ep.oob".getBytes();
// }
// 
// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/interfaces/NfcReadUtility.java
// public interface NfcReadUtility {
// 
//     /**
//      * Read data from received {@link android.content.Intent}
//      *
//      * @param nfcDataIntent
//      *         the intent containing the data to read
//      *
//      * @return the data in an array of {@link android.content.Intent}'s or an empty {@link android.util.SparseArray} array
//      */
//     android.util.SparseArray<String> readFromTagWithSparseArray(Intent nfcDataIntent);
// 
//     /**
//      * Read data from received {@link android.content.Intent}
//      * @param nfcDataIntent the intent containing the data to read
//      * @return the data is either a filled or empty {@link java.util.Map} depending on whether parsing was successful
//      */
//     Map<Byte,String> readFromTagWithMap(Intent nfcDataIntent);
// 
// 
//     /**
//      * Retrieve the content type from the message
//      * @param message type {@link be.appfoundry.nfclibrary.constants.NfcPayloadHeader}
//      * @return {@link be.appfoundry.nfclibrary.constants.NfcPayloadHeader}
//      */
//     java.util.Iterator<Byte> retrieveMessageTypes(NdefMessage message);
// 
//     /**
//      * Retrieve the actual message content
//      * @param message to parse
//      * @return the formatted message
//      */
//     String retrieveMessage(NdefMessage message);
// }


import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import be.appfoundry.nfclibrary.constants.NfcType;
import be.appfoundry.nfclibrary.utilities.interfaces.NfcReadUtility;
import android.content.Intent;
import android.net.Uri;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.os.Parcelable;
import android.util.SparseArray;
import org.jetbrains.annotations.NotNull;
    @Override
    public Iterator<Byte> retrieveMessageTypes(NdefMessage record) {
        Collection<Byte> list = new ArrayList<Byte>();
        for (NdefRecord ndefRecord : record.getRecords()) {
            list.add(retrieveTypeByte(ndefRecord.getPayload()));
        }
        return list.iterator();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String retrieveMessage(NdefMessage message) {
        return message.getRecords()[0] != null ? parseAccordingToHeader(message.getRecords()[0].getPayload()) : null;
    }

    private byte retrieveTypeByte(byte[] payload) {
        if (payload.length > 0) {
            return payload[0];
        }

        return -1;
    }

    private String parseAccordingToHeader(@NotNull byte[] payload) {
        return (payload.length > 0) ? new String(payload, 0, payload.length, Charset.forName("US-ASCII")).trim() : "";
    }

    private String parseAccordingToType(NdefRecord obj) {
// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/constants/NfcType.java
// public class NfcType {
// 
//     /**
//      * Type for the Bluetooth Application Record
//      */
//     public static final byte[] BLUETOOTH_AAR = "application/vnd.bluetooth.ep.oob".getBytes();
// }
// 
// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/interfaces/NfcReadUtility.java
// public interface NfcReadUtility {
// 
//     /**
//      * Read data from received {@link android.content.Intent}
//      *
//      * @param nfcDataIntent
//      *         the intent containing the data to read
//      *
//      * @return the data in an array of {@link android.content.Intent}'s or an empty {@link android.util.SparseArray} array
//      */
//     android.util.SparseArray<String> readFromTagWithSparseArray(Intent nfcDataIntent);
// 
//     /**
//      * Read data from received {@link android.content.Intent}
//      * @param nfcDataIntent the intent containing the data to read
//      * @return the data is either a filled or empty {@link java.util.Map} depending on whether parsing was successful
//      */
//     Map<Byte,String> readFromTagWithMap(Intent nfcDataIntent);
// 
// 
//     /**
//      * Retrieve the content type from the message
//      * @param message type {@link be.appfoundry.nfclibrary.constants.NfcPayloadHeader}
//      * @return {@link be.appfoundry.nfclibrary.constants.NfcPayloadHeader}
//      */
//     java.util.Iterator<Byte> retrieveMessageTypes(NdefMessage message);
// 
//     /**
//      * Retrieve the actual message content
//      * @param message to parse
//      * @return the formatted message
//      */
//     String retrieveMessage(NdefMessage message);
// }


// Path: nfclib/src/main/java/be/appfoundry/nfclibrary/utilities/sync/NfcReadUtilityImpl.java
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import be.appfoundry.nfclibrary.constants.NfcType;
import be.appfoundry.nfclibrary.utilities.interfaces.NfcReadUtility;
import android.content.Intent;
import android.net.Uri;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.os.Parcelable;
import android.util.SparseArray;
import org.jetbrains.annotations.NotNull;

    @Override
    public Iterator<Byte> retrieveMessageTypes(NdefMessage record) {
        Collection<Byte> list = new ArrayList<Byte>();
        for (NdefRecord ndefRecord : record.getRecords()) {
            list.add(retrieveTypeByte(ndefRecord.getPayload()));
        }
        return list.iterator();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String retrieveMessage(NdefMessage message) {
        return message.getRecords()[0] != null ? parseAccordingToHeader(message.getRecords()[0].getPayload()) : null;
    }

    private byte retrieveTypeByte(byte[] payload) {
        if (payload.length > 0) {
            return payload[0];
        }

        return -1;
    }

    private String parseAccordingToHeader(@NotNull byte[] payload) {
        return (payload.length > 0) ? new String(payload, 0, payload.length, Charset.forName("US-ASCII")).trim() : "";
    }

    private String parseAccordingToType(NdefRecord obj) {
        if (Arrays.equals(obj.getType(), NfcType.BLUETOOTH_AAR)) {