Package org.simpleframework.common.parse
Class ParseBuffer
- java.lang.Object
-
- org.simpleframework.common.parse.ParseBuffer
-
public class ParseBuffer extends java.lang.Object
This is primarily used to replace theStringBuffer
class, as a way for theParser
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 thechar
's to be taken quicker than theStringBuffer
class.- Author:
- Niall Gallagher
-
-
Constructor Summary
Constructors Constructor Description ParseBuffer()
Constructor forParseBuffer
.ParseBuffer(int size)
This creates aParseBuffer
with a specific default size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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
append(java.lang.String text)
This will add aString
to the end of the buffer.void
append(java.lang.String str, int off, int len)
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
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.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.java.lang.String
toString()
This will return the characters that have been appended to theParseBuffer
as aString
object.
-
-
-
Constructor Detail
-
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 Detail
-
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
public void append(java.lang.String text)
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
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 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
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 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
public void append(java.lang.String str, int off, int len)
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
public void append(ParseBuffer text, int off, int len)
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
public java.lang.String 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.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the
char
's appended as aString
-
-