Skip to content

Commit

Permalink
#14 Force encoding for exported JSON and CSV to be UTF-8
Browse files Browse the repository at this point in the history
System default encoding was used, forced to use UTF-8.
  • Loading branch information
Dominik Mosen committed Jun 10, 2013
1 parent c8e8661 commit 70a0a49
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
6 changes: 4 additions & 2 deletions wiki-analysis/src/utils/WikipediaAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,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.ArrayList;

import schemas.categoryschema.Category;
Expand Down Expand Up @@ -43,7 +44,8 @@ public static void saveGraphAsJSON(Graph graph, File file)
dfs.addVisitor(visitor);
dfs.execute();

BufferedWriter jsonWriter = new BufferedWriter(new FileWriter(file));
BufferedWriter jsonWriter = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(file), "UTF-8"));
jsonWriter.write(visitor.getJSON().toJSONString());
jsonWriter.close();
}
Expand Down
20 changes: 11 additions & 9 deletions wiki-analysis/src/visualisation/view/table/TableDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import java.awt.event.ActionListener;
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 javax.swing.JButton;
import javax.swing.JDialog;
Expand Down Expand Up @@ -141,14 +142,14 @@ public TableDialog(CategoryGraph graph) {
}
buttonPane.add(okButton, "6, 2, left, top");
}

fc.setFileFilter(new FileFilter() {

@Override
public String getDescription() {
return "CSV files";
}

@Override
public boolean accept(File f) {
if (f.isDirectory()) {
Expand All @@ -157,7 +158,7 @@ public boolean accept(File f) {
return f.getName().toLowerCase().endsWith(CSV_SUFFIX);
}
});

addComponentListeners();
}

Expand Down Expand Up @@ -225,7 +226,8 @@ public void actionPerformed(ActionEvent e) {
}

private void writeCSVFile(File file) throws IOException {
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(file), "UTF-8"));

for (int col = 0; col < table.getColumnCount(); col++) {
bw.write(table.getColumnName(col));
Expand Down Expand Up @@ -274,9 +276,9 @@ private void saveCSVFile() {

int override = JOptionPane.YES_OPTION;
if (file.exists()) {
override = JOptionPane.showConfirmDialog(this, "\"" + file.getPath()
+ "\" already exists. Ovewrite?", "File exists",
JOptionPane.YES_NO_OPTION);
override = JOptionPane.showConfirmDialog(this,
"\"" + file.getPath() + "\" already exists. Overwrite?",
"File exists", JOptionPane.YES_NO_OPTION);
}

if (override == JOptionPane.YES_OPTION) {
Expand Down

0 comments on commit 70a0a49

Please sign in to comment.