Skip to content

Commit

Permalink
Read raw bytes instead of string from file
Browse files Browse the repository at this point in the history
  • Loading branch information
igrek51 committed Mar 26, 2023
1 parent 8ad8632 commit db0fca0
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ abstract class AbstractJsonDao<T>(
throw RuntimeException("No permission to read a file: ${file.absoluteFile}")

try {
val content = file.readText(Charsets.UTF_8)
if (content.isEmpty()) {
val bytes: ByteArray = file.readBytes()
if (bytes.isEmpty()) {
throw RuntimeException("File seems to be empty (due to insufficient permissions or corrupted file): ${file.absoluteFile}")
}
val content: String = bytes.toString(Charsets.UTF_8)
return json.decodeFromString(serializer, content)
} catch (e: FileNotFoundException) {
if (e.message.orEmpty().contains("(Permission denied)", ignoreCase = true)) {
Expand Down

0 comments on commit db0fca0

Please sign in to comment.