Class DatasetDownloadUtils

java.lang.Object
gaiasky.util.datadesc.DatasetDownloadUtils

public class DatasetDownloadUtils extends Object
Utilities to fetch and uncompress datasets.
  • Field Details

    • mirrorKeyword

      public static final String mirrorKeyword
      See Also:
    • EXTRACTION_LOCK

      public static final ReentrantLock EXTRACTION_LOCK
      Reentrant lock to synchronize the latter part of the dataset download process: checksum, extraction, and dataset enable+UI update.
  • Constructor Details

    • DatasetDownloadUtils

      public DatasetDownloadUtils()
  • Method Details

    • fileSize

      public static long fileSize(String inputFilePath)
      Returns the file size.
      Parameters:
      inputFilePath - A file.
      Returns:
      The size in bytes.
    • fileSizeGZUncompressed

      public static long fileSizeGZUncompressed(String inputFilePath) throws IOException
      Returns the GZ uncompressed size.
      Parameters:
      inputFilePath - A gzipped file.
      Returns:
      The uncompressed size in bytes.
      Throws:
      IOException - If the file failed to read.
    • cleanupTempFiles

      public static void cleanupTempFiles()
      We should never need to call this, as the main GaiaSky.dispose() method already cleans up the temp directory. This way, we allow download resumes within the same session.
    • cleanupTempFile

      public static void cleanupTempFile(String file)
      Remove a single file in the temp directory.
      Parameters:
      file - The file to remove.
    • cleanupTempFiles

      public static void cleanupTempFiles(boolean dataDownloads, boolean dataDescriptor)
    • deleteFile

      public static void deleteFile(Path p)
    • decompress

      public static void decompress(String in, File out, Dataset dataset) throws Exception
      Throws:
      Exception
    • snapshotDescriptors

      public static Set<Path> snapshotDescriptors(Path dataLocation)
      Snapshots the paths of all dataset.json descriptors currently present in the given data location (at depth 2, i.e. <data location>/<dataset dir>/dataset.json). Used to detect descriptors added by an extraction, regardless of the directory names inside the archive.
      Parameters:
      dataLocation - The data location directory.
      Returns:
      The set of existing descriptor paths.
    • findNewDescriptors

      public static List<Path> findNewDescriptors(Set<Path> before, Path dataLocation)
      Finds dataset.json descriptors in the given data location that are not contained in the given snapshot. Meant to be called right after an extraction, with the snapshot taken right before.
      Parameters:
      before - The snapshot taken before the extraction.
      dataLocation - The data location directory.
      Returns:
      The list of new descriptor paths, possibly empty.
    • datasetFromDescriptor

      public static Dataset datasetFromDescriptor(Path descriptorFile)
      Builds a Dataset from a dataset.json descriptor file.
      Parameters:
      descriptorFile - The path to the descriptor file.
      Returns:
      The dataset, or null if it could not be built.
    • copyInstallFields

      public static void copyInstallFields(Dataset target, Dataset source)
      Copies the installation-related fields of the source dataset into the target dataset, leaving identity fields (key, file URL) untouched. Used to update a URL-derived stub dataset in place once the real descriptor has been resolved after extraction.
      Parameters:
      target - The dataset to update.
      source - The dataset to copy the fields from.
    • localDatasets

      public static List<Dataset> localDatasets(Path dataLocation)
      Scans the given data location for dataset.json descriptors and builds the datasets they describe.
      Parameters:
      dataLocation - The data location directory.
      Returns:
      The list of datasets described by local descriptors, possibly empty.
    • findLocalDataset

      public static Dataset findLocalDataset(Path dataLocation, String key, String name)
      Finds a locally installed dataset matching the given key or name, by scanning the dataset.json descriptors in the data location.
      Parameters:
      dataLocation - The data location directory.
      key - The dataset key. May be null.
      name - The dataset name. May be null.
      Returns:
      The matching dataset, or null if none is found.
    • isEnabled

      public static boolean isEnabled(Dataset dataset)
    • isPathIn

      public static boolean isPathIn(String path, List<String> setting)