static List<int> trimTrailingZero(List<int> bytes) { int offset = bytes.length; while (offset != 0) { if (bytes[offset - 1] != 0) break; offset--; } return bytes.sublist(0, offset); }