final Gson gson = new GsonBuilder().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create();
final String json = gson.toJson(course);
final File courseJson = new File(project.getBasePath(), "course.json");
- FileWriter writer = null;
+ OutputStreamWriter outputStreamWriter = null;
try {
- writer = new FileWriter(courseJson);
- writer.write(json);
- }
- catch (IOException e) {
- Messages.showErrorDialog(e.getMessage(), "Failed to Generate Json");
- LOG.info(e);
+ outputStreamWriter = new OutputStreamWriter(new FileOutputStream(courseJson), "UTF-8");
+ outputStreamWriter.write(json);
}
catch (Exception e) {
Messages.showErrorDialog(e.getMessage(), "Failed to Generate Json");
}
finally {
try {
- if (writer != null) {
- writer.close();
+ if (outputStreamWriter != null) {
+ outputStreamWriter.close();
}
}
catch (IOException e1) {
if (file.exists()) {
BufferedReader bufferedReader = null;
try {
- bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
+ bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
String line;
while ((line = bufferedReader.readLine()) != null) {
hintText.append(line).append("\n");
VirtualFile hintsDir = myProject.getBaseDir().findChild("hints");
if (hintsDir != null) {
File hintFile = new File(hintsDir.getPath(), hintName);
- PrintWriter printWriter = null;
+ OutputStreamWriter outputStreamWriter = null;
try {
- printWriter = new PrintWriter(hintFile);
- printWriter.print(hintText);
+ outputStreamWriter = new OutputStreamWriter(new FileOutputStream(hintFile), "UTF-8");
+ outputStreamWriter.write(hintText);
}
catch (FileNotFoundException e) {
//TODO:show error in UI
return;
}
+ catch (UnsupportedEncodingException e) {
+ LOG.error(e);
+ }
+ catch (IOException e) {
+ LOG.error(e);
+ }
finally {
- if (printWriter != null) {
- printWriter.close();
+ if (outputStreamWriter != null) {
+ try {
+ outputStreamWriter.close();
+ }
+ catch (IOException e) {
+ //close silently
+ }
}
}
}
myProject = project;
Reader reader = null;
try {
- reader = new InputStreamReader(new FileInputStream(mySelectedCourseFile));
+ reader = new InputStreamReader(new FileInputStream(mySelectedCourseFile), "UTF-8");
Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
final Course course = gson.fromJson(reader, Course.class);
course.init(false);
catch (FileNotFoundException e) {
LOG.error(e);
}
+ catch (UnsupportedEncodingException e) {
+ LOG.error(e);
+ }
finally {
StudyUtils.closeSilently(reader);
}
BufferedReader reader = null;
try {
if (courseFile.getName().equals(COURSE_META_FILE)) {
- reader = new BufferedReader(new InputStreamReader(new FileInputStream(courseFile)));
+ reader = new BufferedReader(new InputStreamReader(new FileInputStream(courseFile), "UTF-8"));
JsonReader r = new JsonReader(reader);
JsonParser parser = new JsonParser();
JsonElement el = parser.parse(r);
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
@Nullable
- public static String getFileText(String parentDir, String fileName, boolean wrapHTML) {
+ public static String getFileText(String parentDir, String fileName, boolean wrapHTML, String encoding) {
File inputFile = parentDir != null ? new File(parentDir, fileName) : new File(fileName);
if (!inputFile.exists()) return null;
StringBuilder taskText = new StringBuilder();
BufferedReader reader = null;
try {
- reader = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile)));
+ reader = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile), encoding));
String line;
while ((line = reader.readLine()) != null) {
taskText.append(line).append("\n");
List<UserTest> userTests = currentTask.getUserTests();
int i = 1;
for (UserTest userTest : userTests) {
- String inputFileText = StudyUtils.getFileText(null, userTest.getInput(), false);
- String outputFileText = StudyUtils.getFileText(null, userTest.getOutput(), false);
+ String inputFileText = StudyUtils.getFileText(null, userTest.getInput(), false, "UTF-8");
+ String outputFileText = StudyUtils.getFileText(null, userTest.getOutput(), false, "UTF-8");
StudyTestContentPanel myContentPanel = new StudyTestContentPanel(userTest);
myContentPanel.addInputContent(inputFileText);
myContentPanel.addOutputContent(outputFileText);
if (resourceRoot != null && resourceRoot.exists()) {
File hintsDir = new File(resourceRoot, Course.HINTS_DIR);
if (hintsDir.exists()) {
- hintText = StudyUtils.getFileText(hintsDir.getAbsolutePath(), hintFileName, true);
+ hintText = StudyUtils.getFileText(hintsDir.getAbsolutePath(), hintFileName, true, "UTF-8");
}
}
}
public String getResourceText(@NotNull final Project project, @NotNull final String fileName, boolean wrapHTML) {
VirtualFile taskDir = getTaskDir(project);
if (taskDir != null) {
- return StudyUtils.getFileText(taskDir.getCanonicalPath(), fileName, wrapHTML);
+ return StudyUtils.getFileText(taskDir.getCanonicalPath(), fileName, wrapHTML, "UTF-8");
}
return null;
}