private static int lastNonZeroByteOffset(@NotNull ByteBuffer buffer,
                                           int startingOffset,
                                           int maxBytesToCheck) {
    int lastNonZeroOffset = -1;
    for (int i = 0; i < maxBytesToCheck; i++) {
      byte b = buffer.get(startingOffset + i);
      if (b != 0) {
        lastNonZeroOffset = startingOffset + i;
      }
    }
    return lastNonZeroOffset;
  }
private static int lastNonZeroByteOffset(@NotNull ByteBuffer buffer,
                                           int startingOffset,
                                           int maxBytesToCheck)