public class TaskIdPathStore<T extends util.object.Identifiable> extends java.lang.Object implements TaskFileStore<T>
TaskFileStore
based on TaskIdPath
.Constructor and Description |
---|
TaskIdPathStore(java.nio.file.Path storeDir,
java.util.function.Function<java.lang.String,T> newTaskId)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
add(T taskId,
util.lambda.ConsumerE<java.io.OutputStream> contentWriter)
Writes a file associated to the specified task.
|
void |
add(T taskId,
java.nio.file.Path contentSource)
Writes a file associated to the specified task by taking the contents
from a source file.
|
java.util.stream.Stream<T> |
listTaskIds() |
java.nio.file.Path |
pathFor(T taskId)
Builds the path to the file associated to the given task ID.
|
void |
remove(T taskId)
Deletes the file associated to the specified task ID.
|
void |
replace(T taskId,
StreamFilter filter)
Uses a
filter function to replace the content of the file
associated to the specified task. |
java.nio.file.Path |
storeDir() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
add, replace
public TaskIdPathStore(java.nio.file.Path storeDir, java.util.function.Function<java.lang.String,T> newTaskId)
storeDir
- the directory where files are stored.newTaskId
- creates a task id from its string representation.java.lang.NullPointerException
- if any argument is null
.public java.nio.file.Path pathFor(T taskId)
TaskFileStore
pathFor
in interface TaskFileStore<T extends util.object.Identifiable>
taskId
- the task ID.public java.util.stream.Stream<T> listTaskIds()
listTaskIds
in interface TaskFileStore<T extends util.object.Identifiable>
The following checked exceptions are rethrown as unchecked (i.e.
the exception is masked as a runtime exception and thrown as is without
wrapping it in a RuntimeException
):
IOException
if an I/O occurs.
public void remove(T taskId)
TaskFileStore
remove
in interface TaskFileStore<T extends util.object.Identifiable>
taskId
- the task ID.public void add(T taskId, util.lambda.ConsumerE<java.io.OutputStream> contentWriter)
TaskFileStore
add
in interface TaskFileStore<T extends util.object.Identifiable>
taskId
- identifies the task.contentWriter
- writes the file contents into an output stream.public void add(T taskId, java.nio.file.Path contentSource)
TaskFileStore
add
in interface TaskFileStore<T extends util.object.Identifiable>
taskId
- identifies the task.contentSource
- the file contents to use.public void replace(T taskId, StreamFilter filter)
TaskFileStore
filter
function to replace the content of the file
associated to the specified task.replace
in interface TaskFileStore<T extends util.object.Identifiable>
taskId
- identifies the task.filter
- gets passed the current content of the file and produces
the new file content.TaskFileStore.replace(Identifiable, FunctionE)
public java.nio.file.Path storeDir()