From c8dcc10ab8e7420d3744178c66b77109761f7211 Mon Sep 17 00:00:00 2001 From: David Huynh Date: Sun, 17 Oct 2010 23:43:02 +0000 Subject: [PATCH] Be sure to use UTF-8 when saving data.txt, pool.txt, and change files. Fix issue 163: Refine doesn't retain the characters for flat or sharp. git-svn-id: http://google-refine.googlecode.com/svn/trunk@1588 7d457c2a-affb-35e4-300a-418c747d4874 --- main/src/com/google/refine/history/History.java | 4 ++-- main/src/com/google/refine/io/ProjectUtilities.java | 12 +++--------- main/src/com/google/refine/model/Project.java | 10 ++++++++-- main/src/com/google/refine/util/Pool.java | 8 +++++++- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/main/src/com/google/refine/history/History.java b/main/src/com/google/refine/history/History.java index 06e516ce0..89b37b7f4 100644 --- a/main/src/com/google/refine/history/History.java +++ b/main/src/com/google/refine/history/History.java @@ -31,7 +31,7 @@ import com.google.refine.util.Pool; */ public class History implements Jsonizable { static public Change readOneChange(InputStream in, Pool pool) throws Exception { - LineNumberReader reader = new LineNumberReader(new InputStreamReader(in)); + LineNumberReader reader = new LineNumberReader(new InputStreamReader(in, "UTF-8")); try { return readOneChange(reader, pool); } finally { @@ -51,7 +51,7 @@ public class History implements Jsonizable { } static public void writeOneChange(OutputStream out, Change change, Pool pool) throws IOException { - Writer writer = new OutputStreamWriter(out); + Writer writer = new OutputStreamWriter(out, "UTF-8"); try { History.writeOneChange(writer, change, pool); } finally { diff --git a/main/src/com/google/refine/io/ProjectUtilities.java b/main/src/com/google/refine/io/ProjectUtilities.java index 9742d0fc2..c22955855 100644 --- a/main/src/com/google/refine/io/ProjectUtilities.java +++ b/main/src/com/google/refine/io/ProjectUtilities.java @@ -2,8 +2,6 @@ package com.google.refine.io; import java.io.File; import java.io.FileOutputStream; -import java.io.InputStreamReader; -import java.io.LineNumberReader; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; @@ -115,15 +113,11 @@ public class ProjectUtilities { Pool pool = new Pool(); ZipEntry poolEntry = zipFile.getEntry("pool.txt"); if (poolEntry != null) { - pool.load(new InputStreamReader( - zipFile.getInputStream(poolEntry))); + pool.load(zipFile.getInputStream(poolEntry)); } // else, it's a legacy project file - return Project.loadFromReader( - new LineNumberReader( - new InputStreamReader( - zipFile.getInputStream( - zipFile.getEntry("data.txt")))), + return Project.loadFromInputStream( + zipFile.getInputStream(zipFile.getEntry("data.txt")), id, pool ); diff --git a/main/src/com/google/refine/model/Project.java b/main/src/com/google/refine/model/Project.java index b39ea4b7f..97c21c926 100644 --- a/main/src/com/google/refine/model/Project.java +++ b/main/src/com/google/refine/model/Project.java @@ -1,6 +1,8 @@ package com.google.refine.model; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.io.LineNumberReader; import java.io.OutputStream; import java.io.OutputStreamWriter; @@ -96,7 +98,7 @@ public class Project { } } - Writer writer = new OutputStreamWriter(out); + Writer writer = new OutputStreamWriter(out, "UTF-8"); try { Properties options = new Properties(); options.setProperty("mode", "save"); @@ -143,7 +145,11 @@ public class Project { } } - static public Project loadFromReader( + static public Project loadFromInputStream(InputStream is, long id, Pool pool) throws Exception { + return loadFromReader(new LineNumberReader(new InputStreamReader(is, "UTF-8")), id, pool); + } + + static private Project loadFromReader( LineNumberReader reader, long id, Pool pool diff --git a/main/src/com/google/refine/util/Pool.java b/main/src/com/google/refine/util/Pool.java index f5d5d58f2..a50532347 100644 --- a/main/src/com/google/refine/util/Pool.java +++ b/main/src/com/google/refine/util/Pool.java @@ -1,6 +1,8 @@ package com.google.refine.util; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.io.LineNumberReader; import java.io.OutputStream; import java.io.OutputStreamWriter; @@ -53,7 +55,7 @@ public class Pool implements Jsonizable { } public void save(OutputStream out) throws IOException { - Writer writer = new OutputStreamWriter(out); + Writer writer = new OutputStreamWriter(out, "UTF-8"); try { save(writer); } finally { @@ -97,6 +99,10 @@ public class Pool implements Jsonizable { } } + public void load(InputStream is) throws Exception { + load(new InputStreamReader(is, "UTF-8")); + } + public void load(Reader reader) throws Exception { LineNumberReader reader2 = new LineNumberReader(reader);