diff --git a/diylc/diylc-core/src/org/diylc/serialization/ProjectFileManager.java b/diylc/diylc-core/src/org/diylc/serialization/ProjectFileManager.java index d76e75ea..941b3a7c 100644 --- a/diylc/diylc-core/src/org/diylc/serialization/ProjectFileManager.java +++ b/diylc/diylc-core/src/org/diylc/serialization/ProjectFileManager.java @@ -31,6 +31,8 @@ import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; import java.lang.reflect.Modifier; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -261,24 +263,27 @@ public class ProjectFileManager { } catch (Exception e) { warnings.add("Could not read file version number, the file may be corrupted."); } - FileInputStream fis = new FileInputStream(fileName); + + String xml = new String(Files.readAllBytes(Paths.get(fileName))); missingFields.clear(); - try { - Reader reader = new InputStreamReader(fis, "UTF-8"); - project = (Project) xStream.fromXML(reader); + try { + xml = cleanupV3XML(xml); + project = (Project) xStream.fromXML(xml); } catch (Exception e) { LOG.warn("Could not open with the new xStream, trying the old one", e); - fis.close(); - fis = new FileInputStream(fileName); - project = (Project) xStreamOld.fromXML(fis); + project = (Project) xStreamOld.fromXML(xml); } if (!missingFields.isEmpty()) { LOG.warn("The opened file is missing the following properties: " + String.join(", ", missingFields)); warnings.add("The project references unknown component properties, most likely because it was created with a newer version of DIYLC."); } - fis.close(); return project; } + + private String cleanupV3XML(String xml) { + xml = xml.replaceAll("", ""); + return xml; + } private VersionNumber readV3Version(String fileName) throws Exception { File fXmlFile = new File(fileName);