[tor-commits] [onionoo/master] Fix task-14780 file encoding problem that blows up files with utf characters.
karsten at torproject.org
karsten at torproject.org
Mon Feb 9 17:57:03 UTC 2015
commit 8c21e0e70a3db645d532721f67e0c4c993ab7465
Author: iwakeh <iwakeh at users.ourproject.org>
Date: Sat Feb 7 16:50:00 2015 +0000
Fix task-14780 file encoding problem that blows up files with utf characters.
---
.../org/torproject/onionoo/docs/DocumentStore.java | 25 ++++++++++----------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/src/main/java/org/torproject/onionoo/docs/DocumentStore.java b/src/main/java/org/torproject/onionoo/docs/DocumentStore.java
index 054fe3b..974f4c1 100644
--- a/src/main/java/org/torproject/onionoo/docs/DocumentStore.java
+++ b/src/main/java/org/torproject/onionoo/docs/DocumentStore.java
@@ -3,13 +3,13 @@
package org.torproject.onionoo.docs;
import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.BufferedReader;
-import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.FileReader;
-import java.io.FileWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
@@ -345,10 +345,7 @@ public class DocumentStore {
documentFile.getParentFile().mkdirs();
File documentTempFile = new File(
documentFile.getAbsolutePath() + ".tmp");
- BufferedWriter bw = new BufferedWriter(new FileWriter(
- documentTempFile));
- bw.write(documentString);
- bw.close();
+ writeToFile(documentTempFile, documentString);
documentFile.delete();
documentTempFile.renameTo(documentFile);
this.storedFiles++;
@@ -740,9 +737,7 @@ public class DocumentStore {
String documentString = sb.toString();
try {
summaryFile.getParentFile().mkdirs();
- BufferedWriter bw = new BufferedWriter(new FileWriter(summaryFile));
- bw.write(documentString);
- bw.close();
+ writeToFile(summaryFile, documentString);
this.lastModifiedNodeStatuses = summaryFile.lastModified();
this.updatedNodeStatuses.clear();
this.storedFiles++;
@@ -753,6 +748,14 @@ public class DocumentStore {
}
}
+ private static void writeToFile(File file, String content)
+ throws IOException {
+ BufferedOutputStream bos = new BufferedOutputStream(
+ new FileOutputStream(file));
+ bos.write(content.getBytes("US-ASCII"));
+ bos.close();
+ }
+
private void writeSummaryDocuments() {
StringBuilder sb = new StringBuilder();
Gson gson = new Gson();
@@ -770,9 +773,7 @@ public class DocumentStore {
File summaryFile = new File(this.outDir, "summary");
try {
summaryFile.getParentFile().mkdirs();
- BufferedWriter bw = new BufferedWriter(new FileWriter(summaryFile));
- bw.write(documentString);
- bw.close();
+ writeToFile(summaryFile, documentString);
this.lastModifiedSummaryDocuments = summaryFile.lastModified();
this.updatedSummaryDocuments.clear();
this.storedFiles++;
More information about the tor-commits
mailing list