From: David ‘Bombe’ Roden Date: Mon, 27 Jan 2014 05:27:08 +0000 (+0100) Subject: Add method that allows to reset the line suppression. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=f3d53ad2a2e8070f1dae009deb6aea1ec2e993e7;p=xudocci.git Add method that allows to reset the line suppression. --- diff --git a/src/main/java/net/pterodactylus/xdcc/util/io/DuplicateLineSuppressingWriter.java b/src/main/java/net/pterodactylus/xdcc/util/io/DuplicateLineSuppressingWriter.java index 85e90eb..1610678 100644 --- a/src/main/java/net/pterodactylus/xdcc/util/io/DuplicateLineSuppressingWriter.java +++ b/src/main/java/net/pterodactylus/xdcc/util/io/DuplicateLineSuppressingWriter.java @@ -91,6 +91,10 @@ public class DuplicateLineSuppressingWriter extends Writer { writeCollectedLines(); } + public void reset() { + lastLine = null; + } + private void writeCollectedLines() throws IOException { while (currentLineContainsLineBreak()) { String nextLine = cutNextLine(); diff --git a/src/test/java/net/pterodactylus/xdcc/util/io/DuplicateLineSuppressingWriterTest.java b/src/test/java/net/pterodactylus/xdcc/util/io/DuplicateLineSuppressingWriterTest.java index e923d69..de6455d 100644 --- a/src/test/java/net/pterodactylus/xdcc/util/io/DuplicateLineSuppressingWriterTest.java +++ b/src/test/java/net/pterodactylus/xdcc/util/io/DuplicateLineSuppressingWriterTest.java @@ -66,4 +66,13 @@ public class DuplicateLineSuppressingWriterTest { assertThat(stringWriter.toString(), is("First Line.\nSecond Line.\nFirst Line.\n")); } + @Test + public void resettingTheWriterAllowsADuplicateLine() throws IOException { + duplicateLineSuppressingWriter.write("First Line.\n"); + duplicateLineSuppressingWriter.write("Second Line.\n"); + duplicateLineSuppressingWriter.reset(); + duplicateLineSuppressingWriter.write("Second Line.\n"); + assertThat(stringWriter.toString(), is("First Line.\nSecond Line.\nSecond Line.\n")); + } + }