Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encoding problem when generating extent reports #298

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -20,10 +22,12 @@ private WriterInstance() {
private BufferedWriterWriter() {
}

public synchronized void write(final File f, String text) {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(f))) {
public synchronized void write(final File f, String text, String encoding) {
try (BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(f), encoding))) {
writer.write(text);
} catch (Exception e) {
} catch (IOException e) {
logger.log(Level.SEVERE, f.getPath(), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ protected void loadTemplateModel() {
}
}

protected void processTemplate(Template template, File outputFile) throws TemplateException, IOException {
protected void processTemplate(Template template, File outputFile, String encoding) throws TemplateException, IOException {
FreemarkerTemplate freemarkerTemplate = new FreemarkerTemplate(getFreemarkerConfig());
freemarkerConfig.setDefaultEncoding(encoding);
freemarkerTemplate.writeTemplate(template, templateModel, outputFile);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void flush(ReportEntity value) {
createFreemarkerConfig(TEMPLATE_LOCATION, ENCODING);
final String filePath = getFileNameAsExt(FILE_NAME, new String[]{".html", ".htm"});
final Template template = getFreemarkerConfig().getTemplate(SPA_TEMPLATE_NAME);
processTemplate(template, new File(filePath));
processTemplate(template, new File(filePath), conf.getEncoding());
return;
} catch (IOException | TemplateException e) {
disposable.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String getSource(Template template, Map<String, Object> templateMap) thro
public void writeTemplate(Template template, Map<String, Object> templateMap, File outputFile)
throws TemplateException, IOException {
String source = getSource(template, templateMap);
BufferedWriterWriter.getInstance().write(outputFile, source);
BufferedWriterWriter.getInstance().write(outputFile, source, freemarkerConfig.getDefaultEncoding());
}

private String processTemplate(Template template, Map<String, Object> templateMap)
Expand Down