}
public static byte[] toByteArray(Collection<Record> records) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream(1024);
DataOutputStream output = new DataOutputStream(buffer);
NdefMessageEncoder ndefMessageEncoder = NdefContext.getNdefMessageEncoder();
try {
byte[] bytes = ndefMessageEncoder.encode(records);
output.writeByte(VERSION);
output.writeInt(1);
output.writeByte(ACTION_IMMEDIATE);
output.writeInt(bytes.length);
output.write(bytes);