public class CharacterRecorder extends Object
When maybeRecord(char)
is called, it will add the
supplied character to the recording buffer but only if
recording is in progress. This is useful in our
com.google.security.streamhtmlparser.HtmlParser
as the caller logic to enable/disable recording is decoupled from the logic
of recording.
This is a specialized class - of no use to external code -
which aims to be 100% compatible with the corresponding logic
in the C-version of the HtmlParser, specifically in
statemachine.c
. In particular:
startRecording()
and stopRecording()
methods
may be called repeatedly without interleaving since the C version is
not guaranteed to interleave them.
RECORDING_BUFFER_SIZE
. Once the size is
reached, no further characters are recorded regardless of whether
recording is currently enabled.
Modifier and Type | Field and Description |
---|---|
static int |
RECORDING_BUFFER_SIZE
How many characters can be recorded before stopping to accept new
ones.
|
Constructor and Description |
---|
CharacterRecorder()
Constructs an empty character recorder of fixed size currently
not recording.
|
CharacterRecorder(CharacterRecorder aCharacterRecorder)
Constructs a character recorder of fixed size that is a copy
of the one provided.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Empties the underlying storage but does not change the recording
state [i.e whether we are recording or not incoming characters].
|
String |
getContent()
Returns the characters recorded in a
String form. |
boolean |
isRecording()
Returns whether or not we are currently recording incoming characters.
|
void |
maybeRecord(char input)
Records the
input if recording is currently on and we
have space available in the buffer. |
void |
reset()
Empties the underlying storage and resets the recording indicator
to indicate we are not recording currently.
|
void |
startRecording()
Enables recording for incoming characters.
|
void |
stopRecording()
Disables recording further characters.
|
String |
toString()
Returns the full state of the object in a human readable form.
|
public static final int RECORDING_BUFFER_SIZE
public CharacterRecorder()
RECORDING_BUFFER_SIZE
for the size.public CharacterRecorder(CharacterRecorder aCharacterRecorder)
aCharacterRecorder
- the CharacterRecorder
to copypublic void startRecording()
public void stopRecording()
public void maybeRecord(char input)
input
if recording is currently on and we
have space available in the buffer. If recording is not
currently on, this method will not perform any action.input
- the character to recordpublic void clear()
public void reset()
public String getContent()
String
form. This
method has no side-effects, the characters remain stored as is.String
formpublic boolean isRecording()
true
if we are recording, false
otherwiseCopyright © 2010–2016 Google. All rights reserved.