_pd = pd;
// Validate
- int textLength = ((StringBuffer)_buf).length();
+ int textLength = ((CharSequence)_buf).length();
if(end-start != textLength) {
throw new IllegalStateException("Told we're for characters " + start + " -> " + end + ", but actually covers " + textLength + " characters!");
}
}
/**
- * Create the StringBuffer from the text and unicode flag
+ * Create the StringBuilder from the text and unicode flag
*/
- private static StringBuffer buildInitSB(byte[] text, PieceDescriptor pd) {
+ private static StringBuilder buildInitSB(byte[] text, PieceDescriptor pd) {
String str;
try {
if(pd.isUnicode()) {
} catch(UnsupportedEncodingException e) {
throw new RuntimeException("Your Java is broken! It doesn't know about basic, required character encodings!");
}
- return new StringBuffer(str);
+ return new StringBuilder(str);
}
/**
return _pd;
}
+ @Deprecated
public StringBuffer getStringBuffer()
{
- return (StringBuffer)_buf;
+ return new StringBuffer(getStringBuilder());
+ }
+
+ public StringBuilder getStringBuilder()
+ {
+ return (StringBuilder)_buf;
}
public byte[] getRawBytes()
{
try {
- return ((StringBuffer)_buf).toString().getBytes(_usesUnicode ?
+ return ((CharSequence)_buf).toString().getBytes(_usesUnicode ?
"UTF-16LE" : "Cp1252");
} catch (UnsupportedEncodingException ignore) {
throw new RuntimeException("Your Java is broken! It doesn't know about basic, required character encodings!");
*/
public String substring(int start, int end)
{
- StringBuffer buf = (StringBuffer)_buf;
+ StringBuilder buf = (StringBuilder)_buf;
// Validate
if(start < 0) {
int bufStart = overlapStart - myStart;
int bufEnd = overlapEnd - myStart;
- ((StringBuffer)_buf).delete(bufStart, bufEnd);
+ ((StringBuilder)_buf).delete(bufStart, bufEnd);
}
// We need to invoke this even if text from this piece is not being
if (limitsAreEqual(o))
{
TextPiece tp = (TextPiece)o;
- return getStringBuffer().toString().equals(tp.getStringBuffer().toString()) &&
+ return getStringBuilder().toString().equals(tp.getStringBuilder().toString()) &&
tp._usesUnicode == _usesUnicode && _pd.equals(tp._pd);
}
return false;
// All ascii, so stored in one big lump
assertEquals(1, tbl.getTextPieces().size());
- TextPiece tp = (TextPiece)tbl.getTextPieces().get(0);
+ TextPiece tp = tbl.getTextPieces().get(0);
assertEquals(0, tp.getStart());
assertEquals(339, tp.getEnd());
assertEquals(339, tp.characterLength());
assertEquals(339, tp.bytesLength());
- assertTrue(tp.getStringBuffer().toString().startsWith("This is a sample word document"));
+ assertTrue(tp.getStringBuilder().toString().startsWith("This is a sample word document"));
// Save and re-load
tbl = docB.getTextTable();
assertEquals(1, tbl.getTextPieces().size());
- tp = (TextPiece)tbl.getTextPieces().get(0);
+ tp = tbl.getTextPieces().get(0);
assertEquals(0, tp.getStart());
assertEquals(339, tp.getEnd());
assertEquals(339, tp.characterLength());
assertEquals(339, tp.bytesLength());
- assertTrue(tp.getStringBuffer().toString().startsWith("This is a sample word document"));
+ assertTrue(tp.getStringBuilder().toString().startsWith("This is a sample word document"));
}
/**