LUCENE-4194: more solr default encoding fixes.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1358107 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dawid Weiss 2012-07-06 10:29:29 +00:00
parent 403ef8c934
commit bb1190c05d
3 changed files with 27 additions and 20 deletions

View File

@ -21,6 +21,7 @@ import java.io.BufferedReader;
import java.io.Closeable; import java.io.Closeable;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -331,5 +332,24 @@ public final class IOUtils {
} }
} }
/**
* Copy one file's contents to another file. The target will be overwritten
* if it exists. The source must exist.
*/
public static void copy(File source, File target) throws IOException {
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream(source);
fos = new FileOutputStream(target);
final byte [] buffer = new byte [1024 * 8];
int len;
while ((len = fis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
} finally {
close(fis, fos);
}
}
} }

View File

@ -26,6 +26,7 @@ import java.util.Set;
import org.apache.noggit.JSONParser; import org.apache.noggit.JSONParser;
import org.apache.lucene.analysis.util.ResourceLoader; import org.apache.lucene.analysis.util.ResourceLoader;
import org.apache.lucene.util.IOUtils;
import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode; import org.apache.solr.common.SolrException.ErrorCode;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -181,7 +182,7 @@ public class OpenExchangeRatesOrgProvider implements ExchangeRateProvider {
private JSONParser parser; private JSONParser parser;
public OpenExchangeRates(InputStream ratesStream) throws IOException { public OpenExchangeRates(InputStream ratesStream) throws IOException {
parser = new JSONParser(new InputStreamReader(ratesStream)); parser = new JSONParser(new InputStreamReader(ratesStream, IOUtils.CHARSET_UTF_8));
rates = new HashMap<String, Double>(); rates = new HashMap<String, Double>();
int ev; int ev;

View File

@ -16,6 +16,7 @@
*/ */
package org.apache.solr; package org.apache.solr;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.util.AbstractSolrTestCase; import org.apache.solr.util.AbstractSolrTestCase;
import org.apache.solr.client.solrj.embedded.JettySolrRunner; import org.apache.solr.client.solrj.embedded.JettySolrRunner;
@ -24,7 +25,6 @@ import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.commons.io.IOUtils;
import java.io.*; import java.io.*;
import java.util.Properties; import java.util.Properties;
@ -115,29 +115,15 @@ public class TestSolrCoreProperties extends LuceneTestCase {
confDir.mkdirs(); confDir.mkdirs();
File f = new File(confDir, "solrconfig.xml"); File f = new File(confDir, "solrconfig.xml");
copyFile(SolrTestCaseJ4.getFile(getSolrConfigFile()), f); IOUtils.copy(SolrTestCaseJ4.getFile(getSolrConfigFile()), f);
f = new File(confDir, "schema.xml"); f = new File(confDir, "schema.xml");
copyFile(SolrTestCaseJ4.getFile(getSchemaFile()), f); IOUtils.copy(SolrTestCaseJ4.getFile(getSchemaFile()), f);
Properties p = new Properties(); Properties p = new Properties();
p.setProperty("foo.foo1", "f1"); p.setProperty("foo.foo1", "f1");
p.setProperty("foo.foo2", "f2"); p.setProperty("foo.foo2", "f2");
FileOutputStream fos = new FileOutputStream(confDir + File.separator + "solrcore.properties"); FileOutputStream fos = new FileOutputStream(confDir + File.separator + "solrcore.properties");
p.store(fos, null); p.store(fos, null);
fos.close(); IOUtils.close(fos);
IOUtils.closeQuietly(fos);
}
private void copyFile(File src, File dst) throws IOException {
BufferedReader in = new BufferedReader(new FileReader(src));
Writer out = new FileWriter(dst);
for (String line = in.readLine(); null != line; line = in.readLine()) {
out.write(line);
}
in.close();
out.close();
} }
} }