Package nl.knaw.dans.layerstore
Class DmfTarRunner
java.lang.Object
nl.knaw.dans.layerstore.AbstractRunner
nl.knaw.dans.layerstore.DmfTarRunner
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 Summary
ConstructorsConstructorDescriptionDmfTarRunner
(Path dmfTarExecutable, String user, String host, Path remoteBaseDir) Creates a new DmfTarRunner. -
Method Summary
Modifier and TypeMethodDescriptionboolean
fileExists
(String archiveName, String fileName) Checks if a file exists in a DMF TAR archive on the remote host.Lists the files in a DMF TAR archive on the remote host.Reads a file from a DMF TAR archive on the remote host.void
tarDirectory
(Path directory, String archiveName) Create a DMF TAR archive from the contents of the given directory.Methods inherited from class nl.knaw.dans.layerstore.AbstractRunner
checkExecutableForSecurity, checkRemoteBaseDirForSecurity, checkUserOrHostNameForSecurity
-
Constructor Details
-
DmfTarRunner
Creates a new DmfTarRunner.- Parameters:
dmfTarExecutable
- path to the dmftar executableuser
- username for the remote hosthost
- host name or IP address of the remote hostremoteBaseDir
- base directory on the remote host where archives are stored
-
-
Method Details
-
tarDirectory
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 archivearchiveName
- the name of the archive to create on the remote host
-
readFile
Reads a file from a DMF TAR archive on the remote host.- Parameters:
archiveName
- the name of the archive to read fromfileName
- the name of the file to read from the archive- Returns:
- an InputStream for reading the file
- Throws:
IOException
-
listFiles
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
Checks if a file exists in a DMF TAR archive on the remote host.- Parameters:
archiveName
- the name of the archive to checkfileName
- 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
-