* ContentExtractorTestBase.java

createRecorder(String,String) - new method for creating test Recorder and specifying charset
    createRecorder(String) - deprecate (use default charset as before)
This commit is contained in:
Noah Levitt
2012-11-15 11:14:25 -08:00
parent 1d994493e2
commit 1e2d86dc63
@@ -21,7 +21,9 @@ package org.archive.modules.extractor;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import org.archive.modules.CrawlURI;
import org.archive.modules.ProcessorTestBase;
@@ -123,13 +125,16 @@ public abstract class ContentExtractorTestBase extends ProcessorTestBase {
assertTrue(uri.getAnnotations().isEmpty());
}
@Deprecated
public static Recorder createRecorder(String content) throws IOException {
return createRecorder(content, Charset.defaultCharset().name());
}
public static Recorder createRecorder(String content)
throws Exception {
public static Recorder createRecorder(String content, String charset)
throws IOException {
File temp = File.createTempFile("test", ".tmp");
Recorder recorder = new Recorder(temp, 1024, 1024);
byte[] b = content.getBytes(); // FIXME: Allow other encodings?
byte[] b = content.getBytes(charset);
ByteArrayInputStream bais = new ByteArrayInputStream(b);
InputStream is = recorder.inputWrap(bais);
for (int x = is.read(); x >= 0; x = is.read());