Interface JobWorkspace
-
- All Implemented Interfaces:
public interface JobWorkspaceLocal Scratch Workspace
Represents a handle on a local workspace and provides methods for operating on files and directories in that workspace.
- Since:
1.0.0
Elizabeth Paige Harper https://github.com/foxcapades
-
-
Method Summary
Modifier and Type Method Description abstract Pathtouch(String path)Creates an empty file in this workspace at the given path. abstract Unitdelete(String path)Deletes the file at the given path if such a file exists. abstract Pathmkdir(String path)Creates an empty directory at the given path. abstract Pathwrite(String path, InputStream data)Writes the contents of the given stream to the file at the given path. abstract Pathwrite(String path, Consumer<OutputStream> consumer)Opens an output stream to the given path and passes it to the consumer, which can write arbitrary data to the file, then closes the stream. abstract Pathwrite(String path, Reader data)Writes the contents of the given reader to the file at the given path. abstract Pathwrite(String path, String data)Writes the given string to the file at the given path. abstract Pathwrite(String path, JsonNode data)Writes the given JsonNode to the file at the given path. abstract Pathcopy(String fromPath, String toPath)Copies the file at the given fromPath to the given toPath. abstract InputStreamopenStream(String path)Opens an InputStream over the contents of the file at the given path. abstract ReaderopenReader(String path)Opens a Reader over the contents of the file at the given path. abstract StringreadAsString(String path)Reads the contents of the file at the given path into a String and returns it. abstract JsonNodereadAsJson(String path)Reads the contents of the file at the given path as a JSON value and returns it. abstract PathgetPath()Absolute path to this workspace on the local filesystem. -
-
Method Detail
-
touch
abstract Path touch(String path)
Creates an empty file in this workspace at the given path.
- Parameters:
path- Relative path at which the empty file will be created.- Returns:
Path to the created file.
-
delete
abstract Unit delete(String path)
Deletes the file at the given path if such a file exists.
If the target file does not exist, this method does nothing.
- Parameters:
path- Relative path to the file that should be deleted.
-
mkdir
abstract Path mkdir(String path)
Creates an empty directory at the given path.
- Parameters:
path- Relative path at which the directory will be created.- Returns:
Path to the created directory.
-
write
abstract Path write(String path, InputStream data)
Writes the contents of the given stream to the file at the given path.
If the given path points to a file that already exists, it will be truncated before writing.
If the given path points to a file that does not yet exist, it will be created.
- Parameters:
path- Relative path at which the file should be written.data- Input stream over the data that will be written to the target file.- Returns:
Path to the written file.
-
write
abstract Path write(String path, Consumer<OutputStream> consumer)
Opens an output stream to the given path and passes it to the consumer, which can write arbitrary data to the file, then closes the stream.
If the given path points to a file that already exists, it will be truncated before writing.
If the given path points to a file that does not yet exist, it will be created.
- Parameters:
path- Relative path at which the file should be written.consumer- Consumer of the created output stream which will write data to the target file via the stream.- Returns:
Path to the written file.
-
write
abstract Path write(String path, Reader data)
Writes the contents of the given reader to the file at the given path.
If the given path points to a file that already exists, it will be truncated before writing.
If the given path points to a file that does not yet exist, it will be created.
- Parameters:
path- Relative path at which the file should be written.data- Reader over the data that will be written to the target file.- Returns:
Path to the written file.
-
write
abstract Path write(String path, String data)
Writes the given string to the file at the given path.
If the given path points to a file that already exists, it will be truncated before writing.
If the given path points to a file that does not yet exist, it will be created.
- Parameters:
path- Relative path at which the file should be written.data- String that will be written to the target file.- Returns:
Path to the written file.
-
write
abstract Path write(String path, JsonNode data)
Writes the given JsonNode to the file at the given path.
If the given path points to a file that already exists, it will be truncated before writing.
If the given path points to a file that does not yet exist, it will be created.
- Parameters:
path- Relative path at which the file should be written.data- Json data that will be written to the target file.- Returns:
Path to the written file.
-
copy
abstract Path copy(String fromPath, String toPath)
- Parameters:
fromPath- Relative path to the file that will be copied.toPath- Relative path to where the file should be copied.- Returns:
Path to the new file copy.
-
openStream
abstract InputStream openStream(String path)
Opens an InputStream over the contents of the file at the given path.
- Parameters:
path- Relative path to the file that will be opened.- Returns:
An InputStream over the contents of the target file.
-
openReader
abstract Reader openReader(String path)
- Parameters:
path- Relative path to the file that will be opened.- Returns:
A Reader over the contents of the target file.
-
readAsString
abstract String readAsString(String path)
- Parameters:
path- Relative path to the file that will be read.- Returns:
The String contents of the target file.
-
readAsJson
abstract JsonNode readAsJson(String path)
Reads the contents of the file at the given path as a JSON value and returns it.
- Parameters:
path- Relative path to the file that will be read.- Returns:
The parsed JsonNode contents of the target file.
-
-
-
-