Package org.simpleframework.common.parse
Class ParseBuffer
java.lang.Object
org.simpleframework.common.parse.ParseBuffer
This is primarily used to replace the
StringBuffer
class, as a way for the Parser
to store the char's
for a specific region within the parse data that constitutes a
desired value. The methods are not synchronized so it enables
the char
's to be taken quicker than the
StringBuffer
class.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructor forParseBuffer
.ParseBuffer
(int size) This creates aParseBuffer
with a specific default size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
append
(char c) This will add achar
to the end of the buffer.void
append
(char[] c, int off, int len) This will add achar
to the end of the buffer.void
This will add aString
to the end of the buffer.void
This will add aString
to the end of the buffer.void
append
(ParseBuffer text) This will add aParseBuffer
to the end of this.void
append
(ParseBuffer text, int off, int len) This will add aParseBuffer
to the end of this.void
clear()
This will empty theParseBuffer
so that thetoString
parameter will returnnull
.protected void
ensureCapacity
(int min) This ensure that there is enough space in the buffer to allow for morechar
's to be added.int
length()
This will return the number of bytes that have been appended to theParseBuffer
.void
This will reset the buffer in such a way that the buffer is cleared of all contents and then has the given string appended.void
reset
(ParseBuffer text) This will reset the buffer in such a way that the buffer is cleared of all contents and then has the given string appended.toString()
This will return the characters that have been appended to theParseBuffer
as aString
object.
-
Field Details
-
cache
This is used to quickentoString
. -
buf
protected char[] bufThechar
's this buffer accumulated. -
count
protected int countThis is the number ofchar
's stored.
-
-
Constructor Details
-
ParseBuffer
public ParseBuffer()Constructor forParseBuffer
. The defaultParseBuffer
stores 16char
's before aresize
is needed to accommodate extra characters. -
ParseBuffer
public ParseBuffer(int size) This creates aParseBuffer
with a specific default size. The buffer will be created the with the length specified. TheParseBuffer
can grow to accommodate a collection ofchar
's larger the the size specified.- Parameters:
size
- initial size of thisParseBuffer
-
-
Method Details
-
append
public void append(char c) This will add achar
to the end of the buffer. The buffer will not overflow with repeated uses of theappend
, it uses anensureCapacity
method which will allow the buffer to dynamically grow in size to accommodate morechar
's.- Parameters:
c
- thechar
to be appended
-
append
This will add aString
to the end of the buffer. The buffer will not overflow with repeated uses of theappend
, it uses anensureCapacity
method which will allow the buffer to dynamically grow in size to accommodate largeString
objects.- Parameters:
text
- theString
to be appended to this
-
reset
This will reset the buffer in such a way that the buffer is cleared of all contents and then has the given string appended. This is used when a value is to be set into the buffer value. See theappend(String)
method for reference.- Parameters:
text
- this is the text that is to be appended to this
-
append
This will add aParseBuffer
to the end of this. The buffer will not overflow with repeated uses of theappend
, it uses anensureCapacity
method which will allow the buffer to dynamically grow in size to accommodate largeParseBuffer
objects.- Parameters:
text
- theParseBuffer
to be appended
-
reset
This will reset the buffer in such a way that the buffer is cleared of all contents and then has the given string appended. This is used when a value is to be set into the buffer value. See theappend(ParseBuffer)
method for reference.- Parameters:
text
- this is the text that is to be appended to this
-
append
public void append(char[] c, int off, int len) This will add achar
to the end of the buffer. The buffer will not overflow with repeated uses of theappend
, it uses anensureCapacity
method which will allow the buffer to dynamically grow in size to accommodate largechar
arrays.- Parameters:
c
- thechar
array to be appended to thisoff
- the read offset for the arraylen
- the number ofchar
's to add
-
append
This will add aString
to the end of the buffer. The buffer will not overflow with repeated uses of theappend
, it uses anensureCapacity
method which will allow the buffer to dynamically grow in size to accommodate largeString
objects.- Parameters:
str
- theString
to be appended to thisoff
- the read offset for theString
len
- the number ofchar
's to add
-
append
This will add aParseBuffer
to the end of this. The buffer will not overflow with repeated uses of theappend
, it uses anensureCapacity
method which will allow the buffer to dynamically grow in size to accommodate largeParseBuffer
objects.- Parameters:
text
- theParseBuffer
to be appendedoff
- the read offset for theParseBuffer
len
- the number ofchar
's to add
-
ensureCapacity
protected void ensureCapacity(int min) This ensure that there is enough space in the buffer to allow for morechar
's to be added. If the buffer is already larger than min then the buffer will not be expanded at all.- Parameters:
min
- the minimum size needed
-
clear
public void clear()This will empty theParseBuffer
so that thetoString
parameter will returnnull
. This is used so that the sameParseBuffer
can be recycled for different tokens. -
length
public int length()This will return the number of bytes that have been appended to theParseBuffer
. This will return zero after the clear method has been invoked.- Returns:
- the number of
char
's within the buffer
-
toString
This will return the characters that have been appended to theParseBuffer
as aString
object. If theString
object has been created before then a cachedString
object will be returned. This method will returnnull
after clear is invoked.
-