Skip to content

Commit 114f43e

Browse files
committed
Sort members
1 parent aad135f commit 114f43e

File tree

2 files changed

+89
-89
lines changed

2 files changed

+89
-89
lines changed

src/main/java/org/apache/commons/io/input/Tailer.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@
138138
* VFS</a>.
139139
*/
140140
public class Tailer implements Runnable, AutoCloseable {
141-
private static final boolean DEFAULT_IGNORE_TOUCH = false;
142-
143141
// @formatter:off
144142
/**
145143
* Builds a new {@link Tailer}.
@@ -247,6 +245,23 @@ public Builder setExecutorService(final ExecutorService executorService) {
247245
return this;
248246
}
249247

248+
/**
249+
* Sets ignoreTouch behaviour
250+
*
251+
* @param ignoreTouch This can be useful when your watched file gets touched (meaning it gets more recent timestamps
252+
* without changing the file) for some reason or when you are working on file systems where timestamp
253+
* is updated before content.
254+
* The default behaviour (ignoreTouch=false) would then reissue the whole current file, while
255+
* ignoreTouch=true does nothing in that case.
256+
*
257+
* @return {@code this} instance.
258+
* @since 2.20.0
259+
*/
260+
public Builder setIgnoreTouch(final boolean ignoreTouch) {
261+
this.ignoreTouch = ignoreTouch;
262+
return this;
263+
}
264+
250265
/**
251266
* Sets the origin.
252267
*
@@ -312,23 +327,6 @@ public Builder setTailFromEnd(final boolean end) {
312327
this.tailFromEnd = end;
313328
return this;
314329
}
315-
316-
/**
317-
* Sets ignoreTouch behaviour
318-
*
319-
* @param ignoreTouch This can be useful when your watched file gets touched (meaning it gets more recent timestamps
320-
* without changing the file) for some reason or when you are working on file systems where timestamp
321-
* is updated before content.
322-
* The default behaviour (ignoreTouch=false) would then reissue the whole current file, while
323-
* ignoreTouch=true does nothing in that case.
324-
*
325-
* @return {@code this} instance.
326-
* @since 2.20.0
327-
*/
328-
public Builder setIgnoreTouch(final boolean ignoreTouch) {
329-
this.ignoreTouch = ignoreTouch;
330-
return this;
331-
}
332330
}
333331

334332
/**
@@ -491,6 +489,8 @@ public String toString() {
491489
}
492490
}
493491

492+
private static final boolean DEFAULT_IGNORE_TOUCH = false;
493+
494494
private static final int DEFAULT_DELAY_MILLIS = 1000;
495495

496496
private static final String RAF_READ_ONLY_MODE = "r";

src/test/java/org/apache/commons/io/input/TailerTest.java

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -577,76 +577,6 @@ void testStopWithNoFileUsingExecutor() throws Exception {
577577
assertEquals(0, listener.reachedEndOfFile, "end of file never reached");
578578
}
579579

580-
@Test
581-
void testTailerIgnoreTouch() throws Exception {
582-
// Create & start the Tailer
583-
final long delayMillis = 50;
584-
final File file = new File(temporaryFolder, "tailer1-testIgnoreTouch.txt");
585-
createFile(file, 0);
586-
final TestTailerListener listener = new TestTailerListener();
587-
try (Tailer tailer = Tailer.builder()
588-
.setFile(file)
589-
.setTailerListener(listener)
590-
.setDelayDuration(Duration.ofMillis(delayMillis))
591-
.setStartThread(false)
592-
.setIgnoreTouch(true)
593-
.get()) {
594-
final Thread thread = new Thread(tailer);
595-
thread.start();
596-
597-
// Write some lines to the file
598-
write(file, "Line one");
599-
final long testDelayMillis = delayMillis * 10;
600-
TestUtils.sleep(testDelayMillis);
601-
List<String> lines = listener.getLines();
602-
assertEquals(1, lines.size(), "1 line count");
603-
assertEquals("Line one", lines.get(0), "1 line 1");
604-
listener.clear();
605-
606-
// touch the file
607-
file.setLastModified(System.currentTimeMillis());
608-
TestUtils.sleep(testDelayMillis);
609-
lines = listener.getLines();
610-
assertEquals(0, lines.size(), "nothing should have changed by touching");
611-
}
612-
}
613-
614-
@Test
615-
void testTailerReissueOnTouch() throws Exception {
616-
// Create & start the Tailer
617-
final long delayMillis = 50;
618-
final File file = new File(temporaryFolder, "tailer1-testReissueOnTouch.txt");
619-
createFile(file, 0);
620-
final TestTailerListener listener = new TestTailerListener();
621-
try (Tailer tailer = Tailer.builder()
622-
.setFile(file)
623-
.setTailerListener(listener)
624-
.setDelayDuration(Duration.ofMillis(delayMillis))
625-
.setStartThread(false)
626-
.setIgnoreTouch(false)
627-
.get()) {
628-
final Thread thread = new Thread(tailer);
629-
thread.start();
630-
631-
// Write some lines to the file
632-
write(file, "Line one");
633-
final long testDelayMillis = delayMillis * 10;
634-
TestUtils.sleep(testDelayMillis);
635-
List<String> lines = listener.getLines();
636-
assertEquals(1, lines.size(), "1 line count");
637-
assertEquals("Line one", lines.get(0), "1 line 1");
638-
listener.clear();
639-
640-
// touch the file
641-
file.setLastModified(System.currentTimeMillis());
642-
TestUtils.sleep(testDelayMillis);
643-
lines = listener.getLines();
644-
assertEquals(1, lines.size(), "1 line count");
645-
assertEquals("Line one", lines.get(0), "1 line 1");
646-
listener.clear();
647-
}
648-
}
649-
650580
@Test
651581
void testTailer() throws Exception {
652582

@@ -775,6 +705,76 @@ void testTailerEof() throws Exception {
775705
}
776706
}
777707

708+
@Test
709+
void testTailerIgnoreTouch() throws Exception {
710+
// Create & start the Tailer
711+
final long delayMillis = 50;
712+
final File file = new File(temporaryFolder, "tailer1-testIgnoreTouch.txt");
713+
createFile(file, 0);
714+
final TestTailerListener listener = new TestTailerListener();
715+
try (Tailer tailer = Tailer.builder()
716+
.setFile(file)
717+
.setTailerListener(listener)
718+
.setDelayDuration(Duration.ofMillis(delayMillis))
719+
.setStartThread(false)
720+
.setIgnoreTouch(true)
721+
.get()) {
722+
final Thread thread = new Thread(tailer);
723+
thread.start();
724+
725+
// Write some lines to the file
726+
write(file, "Line one");
727+
final long testDelayMillis = delayMillis * 10;
728+
TestUtils.sleep(testDelayMillis);
729+
List<String> lines = listener.getLines();
730+
assertEquals(1, lines.size(), "1 line count");
731+
assertEquals("Line one", lines.get(0), "1 line 1");
732+
listener.clear();
733+
734+
// touch the file
735+
file.setLastModified(System.currentTimeMillis());
736+
TestUtils.sleep(testDelayMillis);
737+
lines = listener.getLines();
738+
assertEquals(0, lines.size(), "nothing should have changed by touching");
739+
}
740+
}
741+
742+
@Test
743+
void testTailerReissueOnTouch() throws Exception {
744+
// Create & start the Tailer
745+
final long delayMillis = 50;
746+
final File file = new File(temporaryFolder, "tailer1-testReissueOnTouch.txt");
747+
createFile(file, 0);
748+
final TestTailerListener listener = new TestTailerListener();
749+
try (Tailer tailer = Tailer.builder()
750+
.setFile(file)
751+
.setTailerListener(listener)
752+
.setDelayDuration(Duration.ofMillis(delayMillis))
753+
.setStartThread(false)
754+
.setIgnoreTouch(false)
755+
.get()) {
756+
final Thread thread = new Thread(tailer);
757+
thread.start();
758+
759+
// Write some lines to the file
760+
write(file, "Line one");
761+
final long testDelayMillis = delayMillis * 10;
762+
TestUtils.sleep(testDelayMillis);
763+
List<String> lines = listener.getLines();
764+
assertEquals(1, lines.size(), "1 line count");
765+
assertEquals("Line one", lines.get(0), "1 line 1");
766+
listener.clear();
767+
768+
// touch the file
769+
file.setLastModified(System.currentTimeMillis());
770+
TestUtils.sleep(testDelayMillis);
771+
lines = listener.getLines();
772+
assertEquals(1, lines.size(), "1 line count");
773+
assertEquals("Line one", lines.get(0), "1 line 1");
774+
listener.clear();
775+
}
776+
}
777+
778778
private void validateTailer(final TestTailerListener listener, final File file) throws IOException, InterruptedException {
779779
write(file, "foo");
780780
final int timeout = 30;

0 commit comments

Comments
 (0)