I have a class CustomBuffer
that implements Appendable
, CharSequence
and extends Buffer
. It uses a charBuffer
to access elements. Since it takes some time in computation I am planning to replace it with a StringBuilder
. Unfortunately my current class uses methods like position
, flip
from Buffer
class, which is not available in StringBuilder
class. In order to use those I have two options,
StringBuilder
extendBuffer
(I am not sure whether its a right option as I have not used Buffers much)- Otherwise use the methods I mentioned my modifying the resources from
StringBuilder
.
I am providing sample code.
Current scenario:
public void write(Object object, CustomBuffer cba)
throws Exception {
CustomBuffer cb = new CustomBuffer();
String str = getString(cb.position(), (String)object.size());
cb.flip();
cba.append(str);
cba.append(cb.toString());
}
If I have to replace with StringBuilder
how can I reproduce the same effect. Definitely I cannot provide the index to get position according to the structure of the code, it would be great if I get some help, thanks!