public class SubstitutionContentsTransformer extends Object implements de.unkrig.commons.file.contentstransformation.ContentsTransformer
ContentsTransformer
that replaces regex matches. The pattern search is stream-oriented, not line-oriented,
i.e. matches are found even across line boundaries.Modifier and Type | Class and Description |
---|---|
static interface |
SubstitutionContentsTransformer.Condition |
Constructor and Description |
---|
SubstitutionContentsTransformer(Charset inputCharset,
Charset outputCharset,
Pattern pattern,
de.unkrig.commons.lang.protocol.FunctionWhichThrows<MatchResult,String,? extends RuntimeException> replacer,
SubstitutionContentsTransformer.Condition condition)
Replaces all matches of the regex according to the replacementString.
|
SubstitutionContentsTransformer(Charset inputCharset,
Charset outputCharset,
Pattern pattern,
String replacement,
SubstitutionContentsTransformer.Condition condition)
Replaces all matches of the regex according to the replacementMode and the
replacement.
|
Modifier and Type | Method and Description |
---|---|
void |
addReplacementListener(de.unkrig.commons.lang.protocol.Function<String,String> replacementListener)
The given replacementListener will be
FunctionWhichThrows.call(Object) ed for each replacement, and has
the chance to modify the replacement string. |
void |
setInitialBufferCapacity(int initialBufferCapacity) |
String |
toString() |
void |
transform(String path,
InputStream is,
OutputStream os) |
public SubstitutionContentsTransformer(Charset inputCharset, Charset outputCharset, Pattern pattern, String replacement, SubstitutionContentsTransformer.Condition condition) throws de.unkrig.commons.text.parser.ParseException
condition
- Is checked for each match, and determines whether or not the match is replacedde.unkrig.commons.text.parser.ParseException
- Problems parsing the replacementFor the format of the replacementString
public SubstitutionContentsTransformer(Charset inputCharset, Charset outputCharset, Pattern pattern, de.unkrig.commons.lang.protocol.FunctionWhichThrows<MatchResult,String,? extends RuntimeException> replacer, SubstitutionContentsTransformer.Condition condition)
condition
- Is checked for each match, and determines whether or not the match is replacedFor the format of the replacementString
public void addReplacementListener(de.unkrig.commons.lang.protocol.Function<String,String> replacementListener)
FunctionWhichThrows.call(Object)
ed for each replacement, and has
the chance to modify the replacement string.public void setInitialBufferCapacity(int initialBufferCapacity)
initialBufferCapacity
- See PatternUtil.replaceSome(java.io.Reader, Pattern, FunctionWhichThrows,
Appendable, int)
public void transform(String path, InputStream is, OutputStream os) throws IOException
transform
in interface de.unkrig.commons.file.contentstransformation.ContentsTransformer
IOException
Copyright © 2022 Arno Unkrig. All rights reserved.