public class Foreign
extends java.lang.Object
This class provides methods to interact with foreign command line tools.
This is used for importing and exporting files using an intermediate, temporary MIDI file.
Constructor and Description |
---|
Foreign() |
Modifier and Type | Method and Description |
---|---|
static java.nio.file.Path |
createTempDirectory()
Creates a temporary directory.
|
static java.io.File |
createTempFile(java.lang.String extension,
java.nio.file.Path parentDir)
Creates a temporary file.
|
static java.io.File |
createTempMidiFile()
Creates a temporary file to be used for MIDI import or export.
|
static void |
deleteTempDir(java.nio.file.Path dir)
Removes the given temp directory.
|
static void |
deleteTempFile(java.io.File file)
Deletes the given temporary file.
|
static void |
execute(java.util.List<java.lang.String> cmd,
java.lang.String programName,
boolean acceptAllExitCodes)
Executes a command.
|
static void |
execute(java.lang.String[] cmd,
java.lang.String programName,
boolean acceptAllExitCodes)
Executes a command.
|
static java.io.File[] |
getFiles(java.nio.file.Path dirPath)
Returns all files inside the given temp directory.
|
public static java.nio.file.Path createTempDirectory() throws ForeignException
Creates a temporary directory.
ForeignException
- if something goes wrongpublic static java.io.File[] getFiles(java.nio.file.Path dirPath) throws ForeignException
Returns all files inside the given temp directory.
dirPath
- temp directory to be readForeignException
- if something goes wrongpublic static void deleteTempDir(java.nio.file.Path dir)
Removes the given temp directory.
dir
- the directory to removepublic static java.io.File createTempMidiFile() throws ForeignException
Creates a temporary file to be used for MIDI import or export.
ForeignException
- if something goes wrongpublic static java.io.File createTempFile(java.lang.String extension, java.nio.file.Path parentDir) throws ForeignException
Creates a temporary file.
extension
- file extension (without the dot) - may be nullparentDir
- parent directory or null, if the directory doesn’t matterForeignException
- if something goes wrongpublic static void deleteTempFile(java.io.File file)
Deletes the given temporary file. Suppresses any exception, if the deletion fails.
file
- the file to be deletedpublic static void execute(java.lang.String[] cmd, java.lang.String programName, boolean acceptAllExitCodes) throws ForeignException
Executes a command.
Transforms the given cmd array to a list and calls execute(List, String, boolean)
.
cmd
- Command and OptionsprogramName
- Name of the foreign Program to be displayed in error messagesacceptAllExitCodes
- true to silently ignore exit codes other than 0. false to throw an exception in this case.ForeignException
- if an error occurs.public static void execute(java.util.List<java.lang.String> cmd, java.lang.String programName, boolean acceptAllExitCodes) throws ForeignException
Executes a command.
cmd
- Command and OptionsprogramName
- Name of the foreign Program to be displayed in error messagesacceptAllExitCodes
- true to silently ignore exit codes other than 0. false to throw an exception in this case.ForeignException
- if an error occurs. Sets the path-checked marker inside of the exception, if the command was found.