java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
i2p.susi.util.RegexOutputStream
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
OutputStream that performs case-insensitive regex replacement during streaming.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final LogLogger.private final StringBuilderParse in progress.private booleanWhether a match was found.(package private) intMatch position within the pattern.private final StringPattern string to match, lowercased.private final StringOn-no-match fallback string.private final StringReplacement string.Fields inherited from class FilterOutputStream
outConstructor Summary
ConstructorsConstructorDescriptionRegexOutputStream(OutputStream out, String pattern, String replace, String onNoMatch) Construct with a literal pattern that may contain a single '*' wildcard.Method Summary
Modifier and TypeMethodDescriptionprivate voidclearit()Start over.voidclose()Flush pending output and close.private voidflushit()Flush buf to out, start over.(package private) static StringKeeps a pattern, replacement or buffer readable in the log.private voidpushit(char c) Put in the pending parse buf.private voidThrow out inbuf, output replacement, start over.voidwrite(int val) Write a single byte, with streaming pattern matching.Methods inherited from class FilterOutputStream
flush, write, writeMethods inherited from class OutputStream
nullOutputStream
Field Details
match
Pattern string to match, lowercased.repl
Replacement string.buf
Parse in progress.noMatch
On-no-match fallback string._log
Logger.found
private boolean foundWhether a match was found.idx
int idxMatch position within the pattern.
Constructor Details
RegexOutputStream
Construct with a literal pattern that may contain a single '*' wildcard.- Parameters:
out- MUST be buffered because this writes one byte at a timepattern- the only special char recognized is '*' and cannot be at the beginning or endreplace- the replacement string, ASCII-only, no UTF-8onNoMatch- force output of this at the end if no replacement made, or null
Method Details
write
Write a single byte, with streaming pattern matching.- Overrides:
writein classFilterOutputStream- Throws:
IOException
pushit
private void pushit(char c) Put in the pending parse buf.- Parameters:
c- the character to append to the parse buffer
flushit
Flush buf to out, start over.- Throws:
IOException- if writing to the underlying writer fails
replaceit
Throw out inbuf, output replacement, start over.- Throws:
IOException- if writing the replacement to the underlying writer fails
logText
Keeps a pattern, replacement or buffer readable in the log. These values are HTML fragments of several hundred characters, and one of them per replacement would bury the message the reader is scanning for.- Parameters:
s- the value to shorten, never null- Returns:
- the value, or its head with an ellipsis when it is long
clearit
private void clearit()Start over.close
Flush pending output and close.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterOutputStream- Throws:
IOException