code: private static void fileToTarArchiveOutputStream(FileStatus fileStatus, FSDataInputStream fsDataInputStream,
        Path destFile, TarArchiveOutputStream tarArchiveOutputStream) throws IOException {
      TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(formatPathToFile(destFile));
      tarArchiveEntry.setSize(fileStatus.getLen());
      tarArchiveEntry.setModTime(System.currentTimeMillis());
      tarArchiveOutputStream.putArchiveEntry(tarArchiveEntry);
  
      try {
        IOUtils.copy(fsDataInputStream, tarArchiveOutputStream);
      } finally {
        tarArchiveOutputStream.closeArchiveEntry();
      }
    }
docs: Helper method for {@link #tar(FileSystem, FileSystem, Path, Path)} that adds a file entry to a given
  {@link TarArchiveOutputStream} and copies the contents of the file to the new entry.