Class DmfTarRunner

java.lang.Object
nl.knaw.dans.layerstore.AbstractRunner
nl.knaw.dans.layerstore.DmfTarRunner

public class DmfTarRunner extends AbstractRunner
A runner for the dmftar command line tool, which creates and reads DMF TAR archives on a remote host via SSH.

Security: all parameters provided to the constructor are validated to prevent command injection attacks. The tarDirectory(Path, String) method checks that the directory to be archived does not contain any subdirectories prefixed with 'dmftar-cache.', as these may conflict with temporary cache directories created by dmftar itself.

  • Constructor Details

    • DmfTarRunner

      public DmfTarRunner(Path dmfTarExecutable, String user, String host, Path remoteBaseDir)
      Creates a new DmfTarRunner.
      Parameters:
      dmfTarExecutable - path to the dmftar executable
      user - username for the remote host
      host - host name or IP address of the remote host
      remoteBaseDir - base directory on the remote host where archives are stored
  • Method Details

    • tarDirectory

      public void tarDirectory(Path directory, String archiveName)
      Create a DMF TAR archive from the contents of the given directory. The directory itself is not included in the archive. The directory must not contain any subdirectories prefixed with 'dmftar-cache.', as these may conflict with temporary cache directories created by dmftar itself. The resulting DMT TAR archive will be created in the remote base directory with the given name.
      Parameters:
      directory - the directory to archive
      archiveName - the name of the archive to create on the remote host
    • readFile

      public InputStream readFile(String archiveName, String fileName) throws IOException
      Reads a file from a DMF TAR archive on the remote host.
      Parameters:
      archiveName - the name of the archive to read from
      fileName - the name of the file to read from the archive
      Returns:
      an InputStream for reading the file
      Throws:
      IOException
    • listFiles

      public Iterator<String> listFiles(String archiveName)
      Lists the files in a DMF TAR archive on the remote host.
      Parameters:
      archiveName - the name of the archive to list files from
      Returns:
      an Iterator over the file names in the archive
    • fileExists

      public boolean fileExists(String archiveName, String fileName) throws IOException
      Checks if a file exists in a DMF TAR archive on the remote host.
      Parameters:
      archiveName - the name of the archive to check
      fileName - the name of the file to check for
      Returns:
      true if the file exists in the archive, false otherwise
      Throws:
      IOException - if an I/O error occurs