public class FileContentsTransformer extends Object implements FileTransformer
FileTransformer
that transforms a file be feeding its contents through a ContentsTransformer
.FileTransformer.Mode
NOT_IDENTICAL, THROW_NOT_IDENTICAL
Constructor and Description |
---|
FileContentsTransformer(ContentsTransformer contentsTransformer,
boolean keepOriginals) |
Modifier and Type | Method and Description |
---|---|
static void |
checkIdentity(String path,
InputStream inputStream,
ContentsTransformer contentsTransformer,
boolean closeInputStream)
Consumes the inputStream, feeds it through the contentsTransformer, and checks whether
the output is identical with the input.
|
void |
transform(String path,
File in,
File out,
FileTransformer.Mode mode)
Opens the in file for reading, opens the out file for writing, reads the contents, feeds
it through the given
ContentsTransformer , and writes it to the out file. |
public FileContentsTransformer(ContentsTransformer contentsTransformer, boolean keepOriginals)
keepOriginals
- Whether to keep a copy of the original file; only relevant for in-place transformationspublic void transform(String path, File in, File out, FileTransformer.Mode mode) throws IOException
ContentsTransformer
, and writes it to the out file.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
public static void checkIdentity(String path, InputStream inputStream, ContentsTransformer contentsTransformer, boolean closeInputStream) throws IOException
RuntimeException
- FileTransformer.NOT_IDENTICAL
iff the transformer contents differs from the
original contentsIOException
Copyright © 2018 Arno Unkrig. All rights reserved.