diff --git a/core/src/main/groovy/com/muwire/core/files/PersisterService.groovy b/core/src/main/groovy/com/muwire/core/files/PersisterService.groovy index 884465c0..9592fbfc 100644 --- a/core/src/main/groovy/com/muwire/core/files/PersisterService.groovy +++ b/core/src/main/groovy/com/muwire/core/files/PersisterService.groovy @@ -103,10 +103,12 @@ class PersisterService extends Service { private void persistFiles() { location.delete() def sharedFiles = fileSource.getSharedFiles() - sharedFiles.each { k, v -> - def json = toJson(k,v) - json = JsonOutput.toJson(json) - location.append "$json\n" + location.withPrintWriter { writer -> + sharedFiles.each { k, v -> + def json = toJson(k,v) + json = JsonOutput.toJson(json) + writer.println json + } } } diff --git a/core/src/main/groovy/com/muwire/core/hostcache/HostCache.groovy b/core/src/main/groovy/com/muwire/core/hostcache/HostCache.groovy index a906bd5d..0c9f0881 100644 --- a/core/src/main/groovy/com/muwire/core/hostcache/HostCache.groovy +++ b/core/src/main/groovy/com/muwire/core/hostcache/HostCache.groovy @@ -107,13 +107,15 @@ class HostCache extends Service { private void save() { storage.delete() - hosts.each { dest, host -> - if (allowHost(host)) { - def map = [:] - map.destination = dest.toBase64() - map.failures = host.failures - def json = JsonOutput.toJson(map) - storage.append("${json}\n") + storage.withPrintWriter { writer -> + hosts.each { dest, host -> + if (allowHost(host)) { + def map = [:] + map.destination = dest.toBase64() + map.failures = host.failures + def json = JsonOutput.toJson(map) + writer.println json + } } } } diff --git a/core/src/main/groovy/com/muwire/core/trust/TrustService.groovy b/core/src/main/groovy/com/muwire/core/trust/TrustService.groovy index 8bd5d8e9..6a4dd5a5 100644 --- a/core/src/main/groovy/com/muwire/core/trust/TrustService.groovy +++ b/core/src/main/groovy/com/muwire/core/trust/TrustService.groovy @@ -49,12 +49,16 @@ class TrustService extends Service { private void persist() { persistGood.delete() - good.each { - persistGood.append("${it.toBase64()}\n") + persistGood.withPrintWriter { writer -> + good.each { + writer.println it.toBase64() + } } persistBad.delete() - bad.each { - persistBad.append("${it.toBase64()}\n") + persistBad.withPrintWriter { writer -> + bad.each { + writer.println it.toBase64() + } } }