<commit_before>package org.gbif.crawler.dwca.util;

import org.gbif.dwca.io.Archive;
import org.gbif.dwca.io.ArchiveFactory;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

import com.google.common.io.Files;
import org.apache.commons.io.FileUtils;

public class DwcaTestUtil {

  /**
   * Copies a zip archive from the test resources into a random uuid folder and returns the opened archive.
   */
  public static Archive openArchive(String archiveResourcePath) throws IOException {
    UUID uuid = UUID.randomUUID();

    File zipFile = new File(DwcaTestUtil.class.getResource(archiveResourcePath).getFile());
    File tmpFile = new File(zipFile.getParentFile(), uuid.toString() + ".dwca");
    Files.copy(zipFile, tmpFile);

    File dwcaDir = new File(tmpFile.getParent(), uuid.toString());
    return ArchiveFactory.openArchive(tmpFile, dwcaDir);
  }

  public static void cleanupArchive(Archive archive) {
    File zip = archive.getLocation();
    FileUtils.deleteQuietly(zip);
  }
<commit_msg>allow DwcaTestUtil to load a EML file<commit_after>package org.gbif.crawler.dwca.util;

import org.gbif.dwca.io.Archive;
import org.gbif.dwca.io.ArchiveFactory;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

import com.google.common.io.Files;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;

public class DwcaTestUtil {

  /**
   * Copies a zip archive or a single file from the test resources into a random uuid folder and returns the opened archive.
   */
  public static Archive openArchive(String archiveResourcePath) throws IOException {
    UUID uuid = UUID.randomUUID();

    File srcFile = new File(DwcaTestUtil.class.getResource(archiveResourcePath).getFile());
    File tmpFile = new File(srcFile.getParentFile(), uuid.toString() + ".dwca");
    Files.copy(srcFile, tmpFile);

    File dwcaDir = new File(tmpFile.getParent(), uuid.toString());
    if("zip".equalsIgnoreCase(FilenameUtils.getExtension(srcFile.getName()))) {
      return ArchiveFactory.openArchive(tmpFile, dwcaDir);
    }

    return ArchiveFactory.openArchive(tmpFile);

  }

  public static void cleanupArchive(Archive archive) {
    File zip = archive.getLocation();
    FileUtils.deleteQuietly(zip);
  }

{'fraction_non_alphanumeric': 0.11086669599648043, 'fraction_numerical': 0.0, 'mean_word_length': 4.440191387559809, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6079909', 'n_tokens_mistral': 719, 'n_tokens_neox': 699, 'n_words': 167}