fixed PY-14199 IPython Notebook Editing in Pycharm causes "bad request" error when loading in web browser

specified encoding for ipython notebooks
This commit is contained in:
Ekaterina Tuzova
2014-12-27 18:35:56 +03:00
parent dd5df80384
commit 5ce9f08270
2 changed files with 16 additions and 17 deletions
@@ -103,10 +103,6 @@ public class IpnbFileEditor extends UserDataHolderBase implements FileEditor {
new IpnbHeading6CellAction().registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl shift 6")), myIpnbFilePanel);
}
public JScrollPane getScrollPane() {
return myScrollPane;
}
private JPanel createControlPanel() {
final JPanel controlPanel = new JPanel();
controlPanel.setBackground(IpnbEditorUtil.getBackground());
@@ -15,10 +15,8 @@ import org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel;
import org.jetbrains.plugins.ipnb.format.cells.*;
import org.jetbrains.plugins.ipnb.format.cells.output.*;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -101,20 +99,25 @@ public class IpnbParser {
private static void writeToFile(@NotNull final String path, @NotNull final String json) {
final File file = new File(path);
FileWriter writer = null;
try {
writer = new FileWriter(file);
writer.write(json);
} catch (IOException e) {
LOG.error(e);
}
finally {
final FileOutputStream fileOutputStream = new FileOutputStream(file);
final OutputStreamWriter writer = new OutputStreamWriter(fileOutputStream, Charset.forName("UTF-8").newEncoder());
try {
if (writer != null)
writer.close();
writer.write(json);
} catch (IOException e) {
LOG.error(e);
}
finally {
try {
writer.close();
fileOutputStream.close();
} catch (IOException e) {
LOG.error(e);
}
}
}
catch (FileNotFoundException e) {
LOG.error(e);
}
}