/**
   * {@inheritDoc}
   *
   * @throws Zip64RequiredException if the archive's size exceeds 4 GByte or there are more than
   *     65535 entries inside the archive and {@link #setUseZip64} is {@link Zip64Mode#Never}.
   */
  @Override
  public void finish() throws IOException {
    if (finished) {
      throw new IOException("This archive has already been finished");
    }

    if (entry != null) {
      throw new IOException("This archive contains unclosed entries.");
    }

    cdOffset = written;
    for (ZipArchiveEntry ze : entries) {
      writeCentralFileHeader(ze);
    }
    cdLength = written - cdOffset;
    writeZip64CentralDirectory();
    writeCentralDirectoryEnd();
    offsets.clear();
    entries.clear();
    def.end();
    finished = true;
  }