Package org.apache.solr.internal.csv
Class CharBuffer
- java.lang.Object
-
- org.apache.solr.internal.csv.CharBuffer
-
public class CharBuffer extends Object
A simple StringBuffer replacement that aims to reduce copying as much as possible. The buffer grows as necessary. This class is not thread safe.
-
-
Constructor Summary
Constructors Constructor Description CharBuffer()Creates a new CharBuffer with an initial capacity of 32 characters.CharBuffer(int length)Creates a new CharBuffer with an initial capacity oflengthcharacters.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidappend(char data)Appends a single character to the end of this CharBuffer.voidappend(char[] data)Appendsdatato the end of this CharBuffer.voidappend(String s)Appendssto the end of this CharBuffer.voidappend(StringBuffer sb)Deprecated.voidappend(StringBuilder sb)Appendssbto the end of this CharBuffer.voidappend(CharBuffer cb)Appends the contents ofcbto the end of this CharBuffer.intcapacity()Returns the current capacity of the buffer.charcharAt(int pos)Returns the character at the specified position.voidclear()Empties the buffer.char[]getCharacters()Returns the contents of the buffer as a char[].intlength()Returns the number of characters in the buffer.voidprovideCapacity(int capacity)Copies the data into a new array of at leastcapacitysize.voidshrink()Shrinks the capacity of the buffer to the current length if necessary.StringtoString()Converts the contents of the buffer into a StringBuffer.voidtrimTrailingWhitespace()Removes trailing whitespace.
-
-
-
Method Detail
-
clear
public void clear()
Empties the buffer. The capacity still remains the same, so no memory is freed.
-
length
public int length()
Returns the number of characters in the buffer.- Returns:
- the number of characters
-
capacity
public int capacity()
Returns the current capacity of the buffer.- Returns:
- the maximum number of characters that can be stored in this buffer without resizing it.
-
append
public void append(CharBuffer cb)
Appends the contents ofcbto the end of this CharBuffer.- Parameters:
cb- the CharBuffer to append or null
-
append
public void append(String s)
Appendssto the end of this CharBuffer. This method involves copying the new data once!- Parameters:
s- the String to append or null
-
append
@Deprecated public void append(StringBuffer sb)
Deprecated.Appendssbto the end of this CharBuffer. This method involves copying the new data once!- Parameters:
sb- the StringBuffer to append or null
-
append
public void append(StringBuilder sb)
Appendssbto the end of this CharBuffer. This method involves copying the new data once!- Parameters:
sb- the StringBuffer to append or null
-
append
public void append(char[] data)
Appendsdatato the end of this CharBuffer. This method involves copying the new data once!- Parameters:
data- the char[] to append or null
-
append
public void append(char data)
Appends a single character to the end of this CharBuffer. This method involves copying the new data once!- Parameters:
data- the char to append
-
shrink
public void shrink()
Shrinks the capacity of the buffer to the current length if necessary. This method involves copying the data once!
-
trimTrailingWhitespace
public void trimTrailingWhitespace()
Removes trailing whitespace.
-
getCharacters
public char[] getCharacters()
Returns the contents of the buffer as a char[]. The returned array may be the internal array of the buffer, so the caller must take care when modifying it. This method allows to avoid copying if the caller knows the exact capacity before.
-
charAt
public char charAt(int pos)
Returns the character at the specified position.
-
toString
public String toString()
Converts the contents of the buffer into a StringBuffer. This method involves copying the new data once!
-
provideCapacity
public void provideCapacity(int capacity)
Copies the data into a new array of at leastcapacitysize.
-
-