Document doc = new PlainDocument();
try {
doc.remove(0, doc.getLength());
doc.insertString(0, testString, null);
StringBuilder result;
try (DocumentReader reader = new DocumentReader(doc)) {
result = new StringBuilder(testString.length());
for (int i = 0; i < 10; i++) {
int r = generator.nextInt(doc.getLength());
int l = generator.nextInt(doc.getLength() - r);
if (i % 2 == 0) {
doc.remove(r, l);
} else {
String s =
Strings.generateRandomString(generator.nextInt(100),
generator);
doc.insertString(r, s, null);
}
}
{
int l = (int) (testString.length() * generator.nextDouble() / 2f);
char[] cbuf = new char[l];
int read = reader.read(cbuf, 0, cbuf.length);
if (read > 0) {
result.append(cbuf, 0, read);
}
}
for (int i = 0; i < 10; i++) {
int r = generator.nextInt(doc.getLength());
int l = generator.nextInt(doc.getLength() - r);
if (i % 2 == 0) {
doc.remove(r, l);
} else {
String s =
Strings.generateRandomString(generator.nextInt(100),
generator);
doc.insertString(r, s, null);
}
}
while (true) {
char[] cbuf = new char[1024];
int read = reader.read(cbuf, 0, cbuf.length);
if (read < 0) {
break;
}
result.append(cbuf, 0, read);
}