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
This commit is contained in:
David Huynh 2010-10-17 23:43:02 +00:00
parent a9a3944cbf
commit c8dcc10ab8
4 changed files with 20 additions and 14 deletions

View File

@ -31,7 +31,7 @@ import com.google.refine.util.Pool;
*/ */
public class History implements Jsonizable { public class History implements Jsonizable {
static public Change readOneChange(InputStream in, Pool pool) throws Exception { 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 { try {
return readOneChange(reader, pool); return readOneChange(reader, pool);
} finally { } finally {
@ -51,7 +51,7 @@ public class History implements Jsonizable {
} }
static public void writeOneChange(OutputStream out, Change change, Pool pool) throws IOException { 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 { try {
History.writeOneChange(writer, change, pool); History.writeOneChange(writer, change, pool);
} finally { } finally {

View File

@ -2,8 +2,6 @@ package com.google.refine.io;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
@ -115,15 +113,11 @@ public class ProjectUtilities {
Pool pool = new Pool(); Pool pool = new Pool();
ZipEntry poolEntry = zipFile.getEntry("pool.txt"); ZipEntry poolEntry = zipFile.getEntry("pool.txt");
if (poolEntry != null) { if (poolEntry != null) {
pool.load(new InputStreamReader( pool.load(zipFile.getInputStream(poolEntry));
zipFile.getInputStream(poolEntry)));
} // else, it's a legacy project file } // else, it's a legacy project file
return Project.loadFromReader( return Project.loadFromInputStream(
new LineNumberReader( zipFile.getInputStream(zipFile.getEntry("data.txt")),
new InputStreamReader(
zipFile.getInputStream(
zipFile.getEntry("data.txt")))),
id, id,
pool pool
); );

View File

@ -1,6 +1,8 @@
package com.google.refine.model; package com.google.refine.model;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
@ -96,7 +98,7 @@ public class Project {
} }
} }
Writer writer = new OutputStreamWriter(out); Writer writer = new OutputStreamWriter(out, "UTF-8");
try { try {
Properties options = new Properties(); Properties options = new Properties();
options.setProperty("mode", "save"); 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, LineNumberReader reader,
long id, long id,
Pool pool Pool pool

View File

@ -1,6 +1,8 @@
package com.google.refine.util; package com.google.refine.util;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
@ -53,7 +55,7 @@ public class Pool implements Jsonizable {
} }
public void save(OutputStream out) throws IOException { public void save(OutputStream out) throws IOException {
Writer writer = new OutputStreamWriter(out); Writer writer = new OutputStreamWriter(out, "UTF-8");
try { try {
save(writer); save(writer);
} finally { } 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 { public void load(Reader reader) throws Exception {
LineNumberReader reader2 = new LineNumberReader(reader); LineNumberReader reader2 = new LineNumberReader(reader);