/** * encodes the heartRateTrace to binary format (byte-array) * * @param trace the given trace (as list) to get the byteArray from * @return a byteArray representing the heartRateTrace */ public static byte[] encodeHeartRateTrace(List<HeartRateData> trace) { if (trace == null || trace.size() == 0) { return new byte[0]; } DataOutputStream os = null; try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); os = new DataOutputStream(bos); os.writeInt(trace.size()); for (HeartRateData data : trace) { os.writeLong(data.getRuntime()); os.writeByte(data.getHeartRate()); } return bos.toByteArray(); } catch (Exception e) { Log.e(TAG, "Can't encode heart rate trace: ", e); return new byte[0]; } }