com.google.streamhtmlparser.util
Class CharacterRecorder

java.lang.Object
  extended by com.google.streamhtmlparser.util.CharacterRecorder

public class CharacterRecorder
extends Object

Records (stores) characters supplied one at a time conditional on whether recording is currently enabled.

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:


Field Summary
static int RECORDING_BUFFER_SIZE
          How many characters can be recorded before stopping to accept new ones.
 
Constructor Summary
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.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

RECORDING_BUFFER_SIZE

public static final int RECORDING_BUFFER_SIZE
How many characters can be recorded before stopping to accept new ones. Set to one less than in the C-version as we do not need to reserve a character for the terminating null.

See Also:
Constant Field Values
Constructor Detail

CharacterRecorder

public CharacterRecorder()
Constructs an empty character recorder of fixed size currently not recording. See RECORDING_BUFFER_SIZE for the size.


CharacterRecorder

public CharacterRecorder(CharacterRecorder aCharacterRecorder)
Constructs a character recorder of fixed size that is a copy of the one provided. In particular it has the same recording setting and the same contents.

Parameters:
aCharacterRecorder - the CharacterRecorder to copy
Method Detail

startRecording

public void startRecording()
Enables recording for incoming characters. The recording buffer is cleared of content it may have contained.


stopRecording

public void stopRecording()
Disables recording further characters.


maybeRecord

public void maybeRecord(char input)
Records the 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.

Parameters:
input - the character to record

clear

public void clear()
Empties the underlying storage but does not change the recording state [i.e whether we are recording or not incoming characters].


reset

public void reset()
Empties the underlying storage and resets the recording indicator to indicate we are not recording currently.


getContent

public String getContent()
Returns the characters recorded in a String form. This method has no side-effects, the characters remain stored as is.

Returns:
the contents in a String form

isRecording

public boolean isRecording()
Returns whether or not we are currently recording incoming characters.

Returns:
true if we are recording, false otherwise

toString

public String toString()
Returns the full state of the object in a human readable form. The format of the returned String is not specified and is subject to change.

Overrides:
toString in class Object
Returns:
the full state of this object


Copyright © 2010-2012 Google. All Rights Reserved.