From f3d53ad2a2e8070f1dae009deb6aea1ec2e993e7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 27 Jan 2014 06:27:08 +0100 Subject: [PATCH] Add method that allows to reset the line suppression. --- .../xdcc/util/io/DuplicateLineSuppressingWriter.java | 4 ++++ .../xdcc/util/io/DuplicateLineSuppressingWriterTest.java | 9 +++++++++ 2 files changed, 13 insertions(+) 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")); + } + } -- 2.7.4