protected boolean truncateAndWriteToFile(String filePath, String text) {
    EnumSet<StandardOpenOption> options = EnumSet.of(StandardOpenOption.CREATE, StandardOpenOption.WRITE);
    SeekableByteChannel seekableByteChannel = getFd(filePath, options);
    try {
      seekableByteChannel.truncate(0);
      seekableByteChannel.write(ByteBuffer.wrap(text.getBytes()));
      return true;
    } catch (Throwable e) {
      logger.error("Failed to write token {} to file {} due to {}", text, filePath, e.toString());
    }
    return false;
  }
Truncates a file and then writes to it.
Creates the file if absent.
@param filePath Path of the file in the system
@param text Text to append
@return True if append was successful, false otherwise
ambry-replication/src/main/java/com/github/ambry/replication/BackupCheckerFileManager.java