SoneTextParserContext context = new SoneTextParserContext(request, (Sone) sone);
StringWriter parsedTextWriter = new StringWriter();
try {
- Iterable<Part> parts = soneTextParser.parse(context, new StringReader(text));
+ Iterable<Part> parts = soneTextParser.parse(context, text);
if (length > -1) {
int allPartsLength = 0;
List<Part> shortenedParts = new ArrayList<Part>();
SoneTextParser parser = new SoneTextParser(core, core);
SoneTextParserContext parserContext = new SoneTextParserContext(null, postPart.getPost().getSone());
try {
- Iterable<Part> parts = parser.parse(parserContext, new StringReader(postPart.getPost().getText()));
+ Iterable<Part> parts = parser.parse(parserContext, postPart.getPost().getText());
StringBuilder excerpt = new StringBuilder();
for (Part part : parts) {
excerpt.append(part.getText());
import java.io.BufferedReader;
import java.io.IOException;
-import java.io.Reader;
+import java.io.StringReader;
import java.net.MalformedURLException;
import java.util.logging.Level;
import java.util.logging.Logger;
* {@inheritDoc}
*/
@Override
- public Iterable<Part> parse(SoneTextParserContext context, Reader source) throws IOException {
+ public Iterable<Part> parse(SoneTextParserContext context, String source) throws IOException {
PartContainer parts = new PartContainer();
- BufferedReader bufferedReader = (source instanceof BufferedReader) ? (BufferedReader) source : new BufferedReader(source);
+ BufferedReader bufferedReader = new BufferedReader(new StringReader(source));
try {
String line;
boolean lastLineEmpty = true;
lastLineEmpty = false;
}
} finally {
- if (bufferedReader != source) {
- Closer.close(bufferedReader);
- }
+ Closer.close(bufferedReader);
}
for (int partIndex = parts.size() - 1; partIndex >= 0; --partIndex) {
Part part = parts.getPart(partIndex);
Iterable<Part> parts;
/* check basic operation. */
- parts = soneTextParser.parse(null, new StringReader("Test."));
+ parts = soneTextParser.parse(null, "Test.");
assertNotNull("Parts", parts);
assertEquals("Part Text", "Test.", convertText(parts, PlainTextPart.class));
/* check empty lines at start and end. */
- parts = soneTextParser.parse(null, new StringReader("\nTest.\n\n"));
+ parts = soneTextParser.parse(null, "\nTest.\n\n");
assertNotNull("Parts", parts);
assertEquals("Part Text", "Test.", convertText(parts, PlainTextPart.class));
/* check duplicate empty lines in the text. */
- parts = soneTextParser.parse(null, new StringReader("\nTest.\n\n\nTest."));
+ parts = soneTextParser.parse(null, "\nTest.\n\n\nTest.");
assertNotNull("Parts", parts);
assertEquals("Part Text", "Test.\n\nTest.", convertText(parts, PlainTextPart.class));
}
Iterable<Part> parts;
/* check basic links. */
- parts = soneTextParser.parse(null, new StringReader("KSK@gpl.txt"));
+ parts = soneTextParser.parse(null, "KSK@gpl.txt");
assertNotNull("Parts", parts);
assertEquals("Part Text", "[KSK@gpl.txt|gpl.txt|gpl.txt]", convertText(parts, FreenetLinkPart.class));
/* check embedded links. */
- parts = soneTextParser.parse(null, new StringReader("Link is KSK@gpl.txt\u200b."));
+ parts = soneTextParser.parse(null, "Link is KSK@gpl.txt\u200b.");
assertNotNull("Parts", parts);
assertEquals("Part Text", "Link is [KSK@gpl.txt|gpl.txt|gpl.txt]\u200b.", convertText(parts, PlainTextPart.class, FreenetLinkPart.class));
/* check embedded links and line breaks. */
- parts = soneTextParser.parse(null, new StringReader("Link is KSK@gpl.txt\nKSK@test.dat\n"));
+ parts = soneTextParser.parse(null, "Link is KSK@gpl.txt\nKSK@test.dat\n");
assertNotNull("Parts", parts);
assertEquals("Part Text", "Link is [KSK@gpl.txt|gpl.txt|gpl.txt]\n[KSK@test.dat|test.dat|test.dat]", convertText(parts, PlainTextPart.class, FreenetLinkPart.class));
}
Iterable<Part> parts;
/* check basic links. */
- parts = soneTextParser.parse(null, new StringReader("Some text.\n\nLink to sone://DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU and stuff."));
+ parts = soneTextParser.parse(null, "Some text.\n\nLink to sone://DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU and stuff.");
assertNotNull("Parts", parts);
assertEquals("Part Text", "Some text.\n\nLink to [Sone|DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU] and stuff.", convertText(parts, PlainTextPart.class, SonePart.class));
}
Iterable<Part> parts;
/* check empty http links. */
- parts = soneTextParser.parse(null, new StringReader("Some text. Empty link: http:// – nice!"));
+ parts = soneTextParser.parse(null, "Some text. Empty link: http:// – nice!");
assertNotNull("Parts", parts);
assertEquals("Part Text", "Some text. Empty link: http:// – nice!", convertText(parts, PlainTextPart.class));
}