Class ParseBuffer
java.lang.Object
org.simpleframework.util.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.- Author:
- Niall Gallagher
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructor forParseBuffer.ParseBuffer(int size) This creates aParseBufferwith a specific default size. -
Method Summary
Modifier and TypeMethodDescriptionvoidappend(char c) This will add acharto the end of the buffer.voidappend(char[] c, int off, int len) This will add acharto the end of the buffer.voidThis will add aStringto the end of the buffer.voidThis will add aStringto the end of the buffer.voidappend(ParseBuffer text) This will add aParseBufferto the end of this.voidappend(ParseBuffer text, int off, int len) This will add aParseBufferto the end of this.voidclear()This will empty theParseBufferso that thetoStringparameter will returnnull.protected voidensureCapacity(int min) This ensure that there is enough space in the buffer to allow for morechar's to be added.intlength()This will return the number of bytes that have been appended to theParseBuffer.voidThis will reset the buffer in such a way that the buffer is cleared of all contents and then has the given string appended.voidreset(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 theParseBufferas aStringobject.
-
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 defaultParseBufferstores 16char's before aresizeis needed to accommodate extra characters. -
ParseBuffer
public ParseBuffer(int size) This creates aParseBufferwith a specific default size. The buffer will be created the with the length specified. TheParseBuffercan 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 acharto the end of the buffer. The buffer will not overflow with repeated uses of theappend, it uses anensureCapacitymethod which will allow the buffer to dynamically grow in size to accommodate morechar's.- Parameters:
c- thecharto be appended
-
append
This will add aStringto the end of the buffer. The buffer will not overflow with repeated uses of theappend, it uses anensureCapacitymethod which will allow the buffer to dynamically grow in size to accommodate largeStringobjects.- Parameters:
text- theStringto 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 aParseBufferto the end of this. The buffer will not overflow with repeated uses of theappend, it uses anensureCapacitymethod which will allow the buffer to dynamically grow in size to accommodate largeParseBufferobjects.- Parameters:
text- theParseBufferto 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 acharto the end of the buffer. The buffer will not overflow with repeated uses of theappend, it uses anensureCapacitymethod which will allow the buffer to dynamically grow in size to accommodate largechararrays.- Parameters:
c- thechararray to be appended to thisoff- the read offset for the arraylen- the number ofchar's to add
-
append
This will add aStringto the end of the buffer. The buffer will not overflow with repeated uses of theappend, it uses anensureCapacitymethod which will allow the buffer to dynamically grow in size to accommodate largeStringobjects.- Parameters:
str- theStringto be appended to thisoff- the read offset for theStringlen- the number ofchar's to add
-
append
This will add aParseBufferto the end of this. The buffer will not overflow with repeated uses of theappend, it uses anensureCapacitymethod which will allow the buffer to dynamically grow in size to accommodate largeParseBufferobjects.- Parameters:
text- theParseBufferto be appendedoff- the read offset for theParseBufferlen- 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 theParseBufferso that thetoStringparameter will returnnull. This is used so that the sameParseBuffercan 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 theParseBufferas aStringobject. If theStringobject has been created before then a cachedStringobject will be returned. This method will returnnullafter clear is invoked.
-