X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneTextParser.java;h=18dd53f64c4dc8418b7dbfe9dabc5b89cf1ca64c;hb=8ee3de9a7ed7c65b5f695dd60da6e55d94c1125e;hp=f338286d6e42c08f8905260e21d2876480ba312f;hpb=419098bcd6215125408b29e60bd888e60979d37b;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java index f338286..18dd53f 100644 --- a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java +++ b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java @@ -21,7 +21,7 @@ import static java.util.logging.Logger.getLogger; 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; @@ -118,9 +118,9 @@ public class SoneTextParser implements Parser { * {@inheritDoc} */ @Override - public Iterable parse(SoneTextParserContext context, Reader source) throws IOException { + public Iterable parse(SoneTextParserContext context, String source) { 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; @@ -271,10 +271,11 @@ public class SoneTextParser implements Parser { } lastLineEmpty = false; } + } catch (IOException ioe1) { + // a buffered reader around a string reader should never throw. + throw new RuntimeException(ioe1); } finally { - if (bufferedReader != source) { - Closer.close(bufferedReader); - } + Closer.close(bufferedReader); } for (int partIndex = parts.size() - 1; partIndex >= 0; --partIndex) { Part part = parts.getPart(partIndex);