StringBuilderBuffer

public final class StringBuilderBuffer implements IWritableCharSequence, IStringable

StringBuilderBuffer is a buffer that is backed by a string builder. It is significantly more efficient than ManagedSecureCharBuffer at the expense of strings not being cleaned from the JVM and not retaining references to the original sequences (which means inputs won’t be cleaned at the end!) This should not be used for sensitive information, but is sensible for most cases.

Constructors

StringBuilderBuffer

public StringBuilderBuffer(int parInitialCapacity)

Construct a StringBuilderBuffer instance with an initial capacity.

Parameters:
  • parInitialCapacity – The initial capacity to use. If unspecified, the INITIAL_CAPACITY constant will be used instead.

StringBuilderBuffer

public StringBuilderBuffer(int parInitialCapacity, boolean parEraseOnClose)

Construct a StringBuilderBuffer instance with an initial capacity.

Parameters:
  • parInitialCapacity – The initial capacity to use. If unspecified, the INITIAL_CAPACITY constant will be used instead.
  • parEraseOnClose – If true, all buffers will be erased when we finish with it. Otherwise, close will be a NOOP.

Methods

append

public void append(char parChar)

Append a character.

Parameters:
  • parChar – The character to append.

append

public void append(CharSequence parChars)

Append a sequence of characters.

Parameters:
  • parChars – The sequence to append.

charAt

public char charAt(int parIndex)

Get the character at the given index.

Parameters:
  • parIndex – The index to lookup.
Returns:

The character at the given index.

close

public void close()

Reset the data in our buffer.

getCapacity

public int getCapacity()

Get the current capacity.

Returns:The capacity.

isRestrictedToCapacity

public boolean isRestrictedToCapacity()

Is this restricted to the initial capacity? This is used when this is being managed by another class to determine when more memory needs to be allocated.

Returns:True if this is restricted to the initial capacity.

length

public int length()

Get our buffer length.

Returns:Our buffer length.

subSequence

public CharSequence subSequence(int parStart, int parEnd)

Get the subsequence between parStart and parEnd.

Parameters:
  • parStart – The start index (inclusive)
  • parEnd – The end index (exclusive)
Returns:

The sequence between parStart and parEnd.

toString

public String toString()