Package org.simpleframework.common.parse
Class ParseBuffer
- java.lang.Object
-
- org.simpleframework.common.parse.ParseBuffer
-
public class ParseBuffer extends java.lang.ObjectThis is primarily used to replace theStringBufferclass, as a way for theParserto 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 thechar's to be taken quicker than theStringBufferclass.
-
-
Constructor Summary
Constructors Constructor Description ParseBuffer()Constructor forParseBuffer.ParseBuffer(int size)This creates aParseBufferwith a specific default size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(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.voidappend(java.lang.String text)This will add aStringto the end of the buffer.voidappend(java.lang.String str, int off, int len)This 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.voidreset(java.lang.String 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.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.java.lang.StringtoString()This will return the characters that have been appended to theParseBufferas aStringobject.
-
-
-
Constructor Detail
-
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 Detail
-
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
public void append(java.lang.String text)
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
public void reset(java.lang.String 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. 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
public void append(ParseBuffer text)
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
public 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. 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
public void append(java.lang.String str, int off, int len)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
public void append(ParseBuffer text, int off, int len)
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
public java.lang.String 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.- Overrides:
toStringin classjava.lang.Object- Returns:
- the
char's appended as aString
-
-