LUCENE-4199: fix more default charset uses

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4199@1358555 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-07-07 12:25:16 +00:00
parent 6e9890c9ed
commit d69c73c027
5 changed files with 19 additions and 14 deletions

View File

@ -37,7 +37,7 @@ public class TestBinaryDocument extends LuceneTestCase {
{
FieldType ft = new FieldType();
ft.setStored(true);
IndexableField binaryFldStored = new StoredField("binaryStored", binaryValStored.getBytes());
IndexableField binaryFldStored = new StoredField("binaryStored", binaryValStored.getBytes("UTF-8"));
IndexableField stringFldStored = new Field("stringStored", binaryValStored, ft);
Document doc = new Document();
@ -62,7 +62,7 @@ public class TestBinaryDocument extends LuceneTestCase {
/** fetch the binary stored field and compare it's content with the original one */
BytesRef bytes = docFromReader.getBinaryValue("binaryStored");
assertNotNull(bytes);
String binaryFldStoredTest = new String(bytes.bytes, bytes.offset, bytes.length);
String binaryFldStoredTest = new String(bytes.bytes, bytes.offset, bytes.length, "UTF-8");
assertTrue(binaryFldStoredTest.equals(binaryValStored));
/** fetch the string field and compare it's content with the original one */
@ -75,7 +75,7 @@ public class TestBinaryDocument extends LuceneTestCase {
}
public void testCompressionTools() throws Exception {
IndexableField binaryFldCompressed = new StoredField("binaryCompressed", CompressionTools.compress(binaryValCompressed.getBytes()));
IndexableField binaryFldCompressed = new StoredField("binaryCompressed", CompressionTools.compress(binaryValCompressed.getBytes("UTF-8")));
IndexableField stringFldCompressed = new StoredField("stringCompressed", CompressionTools.compressString(binaryValCompressed));
Document doc = new Document();
@ -94,7 +94,7 @@ public class TestBinaryDocument extends LuceneTestCase {
assertTrue(docFromReader != null);
/** fetch the binary compressed field and compare it's content with the original one */
String binaryFldCompressedTest = new String(CompressionTools.decompress(docFromReader.getBinaryValue("binaryCompressed")));
String binaryFldCompressedTest = new String(CompressionTools.decompress(docFromReader.getBinaryValue("binaryCompressed")), "UTF-8");
assertTrue(binaryFldCompressedTest.equals(binaryValCompressed));
assertTrue(CompressionTools.decompressString(docFromReader.getBinaryValue("stringCompressed")).equals(binaryValCompressed));

View File

@ -17,11 +17,14 @@ package org.apache.lucene.index;
* limitations under the License.
*/
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
@ -78,14 +81,14 @@ public class TestDoc extends LuceneTestCase {
}
private File createOutput(String name, String text) throws IOException {
FileWriter fw = null;
Writer fw = null;
PrintWriter pw = null;
try {
File f = new File(workDir, name);
if (f.exists()) f.delete();
fw = new FileWriter(f);
fw = new OutputStreamWriter(new FileOutputStream(f), "UTF-8");
pw = new PrintWriter(fw);
pw.println(text);
return f;
@ -182,9 +185,11 @@ public class TestDoc extends LuceneTestCase {
{
File file = new File(workDir, fileName);
Document doc = new Document();
doc.add(new TextField("contents", new FileReader(file), Field.Store.NO));
InputStreamReader is = new InputStreamReader(new FileInputStream(file), "UTF-8");
doc.add(new TextField("contents", is, Field.Store.NO));
writer.addDocument(doc);
writer.commit();
is.close();
return writer.newestSegment();
}

View File

@ -203,7 +203,7 @@ public class TestNumericRangeFilterBuilder extends LuceneTestCase {
private static Document getDocumentFromString(String str)
throws SAXException, IOException, ParserConfigurationException {
InputStream is = new ByteArrayInputStream(str.getBytes());
InputStream is = new ByteArrayInputStream(str.getBytes("UTF-8"));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();

View File

@ -38,12 +38,12 @@ public class PlainTextDictionary implements Dictionary {
private BufferedReader in;
public PlainTextDictionary(File file) throws FileNotFoundException {
in = new BufferedReader(new FileReader(file));
public PlainTextDictionary(File file) throws IOException {
in = new BufferedReader(IOUtils.getDecodingReader(file, IOUtils.CHARSET_UTF_8));
}
public PlainTextDictionary(InputStream dictFile) {
in = new BufferedReader(new InputStreamReader(dictFile));
in = new BufferedReader(IOUtils.getDecodingReader(dictFile, IOUtils.CHARSET_UTF_8));
}
/**

View File

@ -42,7 +42,7 @@ public class FileDictionary implements Dictionary {
private boolean done = false;
public FileDictionary(InputStream dictFile) {
in = new BufferedReader(new InputStreamReader(dictFile));
in = new BufferedReader(IOUtils.getDecodingReader(dictFile, IOUtils.CHARSET_UTF_8));
}
/**