Skip to content
This repository was archived by the owner on Dec 18, 2022. It is now read-only.

Commit f975fb3

Browse files
committed
refactor WriteObserver to be clearer with Exceptions that may be thrown
1 parent 5e69c61 commit f975fb3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

topl-android/src/main/java/io/matthewnelson/topl_android/util/WriteObserver.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class WriteObserver(file: File) : FileObserver(file.absolutePath, CLOSE_WRITE) {
3939

4040
private val countDownLatch = CountDownLatch(1)
4141

42+
@Throws(RuntimeException::class)
4243
fun poll(timeout: Long, unit: TimeUnit): Boolean =
4344
try {
4445
countDownLatch.await(timeout, unit)
@@ -51,8 +52,12 @@ class WriteObserver(file: File) : FileObserver(file.absolutePath, CLOSE_WRITE) {
5152
countDownLatch.countDown()
5253
}
5354

54-
init {
55+
@Throws(IllegalArgumentException::class, SecurityException::class)
56+
private fun checkExists(file: File) =
5557
require(file.exists()) { "FileObserver doesn't work properly on files that don't already exist." }
58+
59+
init {
60+
checkExists(file)
5661
startWatching()
5762
}
5863
}

0 commit comments

Comments
 (0)