public class SelectiveFileTransformer extends Object implements FileTransformer
FileTransformer
that feeds the file to the trueDelegate iff the path matches a given
Predicate
, and otherwise to the falseDelegate.FileTransformer.Mode
NOT_IDENTICAL, THROW_NOT_IDENTICAL
Constructor and Description |
---|
SelectiveFileTransformer(Predicate<? super String> pathPredicate,
FileTransformer trueDelegate,
FileTransformer falseDelegate) |
Modifier and Type | Method and Description |
---|---|
String |
toString() |
void |
transform(String path,
File in,
File out,
FileTransformer.Mode mode)
Creates the file out, based on the file in.
|
public SelectiveFileTransformer(Predicate<? super String> pathPredicate, FileTransformer trueDelegate, FileTransformer falseDelegate)
public void transform(String path, File in, File out, FileTransformer.Mode mode) throws IOException
FileTransformer
in.equals(out)
('in-place
transformation'), then the original file remains unchanged, is modified, or replaced with a new file.
The precise contract is as follows:
mode == Mode.CHECK
, then this method merely checks whether the content of the file
would change, and, if so, complete normally, otherwise it would throw FileTransformer.NOT_IDENTICAL
.
!
in.equals(
out)
("out-of-place
transformation"), out is created, based on in.
(Parameter mode is ignored.)
(If this method throws an exception, then it must not leave a file out behind.)
mode ==
Mode.CHECK_AND_TRANSFORM
, then the method attempts to avoid unnecessary i/o and processing by first checking
whether the file requires any modifications before applying them. (If this method throws an exception, then
it must revert the file to its original state as far as is reasonably possible.)
/li>
transform
in interface FileTransformer
path
- A text designating the input file; typically, but not necessarily identical with in.getPath()
in
- The input file to readout
- The output file to create; irrelevant iff mode ==
FileTransformer.Mode.CHECK
IOException
FileTransformer.NOT_IDENTICAL
,
FileTransformer.Mode.TRANSFORM
,
FileTransformer.Mode.CHECK
,
FileTransformer.Mode.CHECK_AND_TRANSFORM
Copyright © 2018 Arno Unkrig. All rights reserved.