public void toFileString(final BufferedWriter bw, String comment, Style style) throws IOException { // special starter method made for root // root is a "virtual" document node that does not appear in file // so we start by writing children directly if (comment != null && comment.length() != 0) { // if (allWritable.get(0) != null && allWritable.get(0) instanceof Comment) { // // If there is a file header comment, merge the two, with the new comment // first. // Comment c = ((Comment) allWritable.get(0)); // String s = c.getComment(); // c.setComment(comment); // c.appendComment(s); // } else { new HeaderComment(comment).toFileString(bw, 0, style); // bw.newLine(); bw.newLine(); // } } // Changed from foreach // EU4 saves require the last node (a checksum) to be the last line of the file for (Iterator<WritableObject> it = allWritable.iterator(); it.hasNext(); ) { WritableObject obj = it.next(); obj.toFileString(bw, 0, style); if (it.hasNext()) bw.newLine(); } bw.close(); }
@Override public void toFileString(final BufferedWriter bw, int depth, Style style) throws IOException { if (name.equals("root")) { toFileString(bw, style); return; } final boolean parentSameLine = style.isInline(parent); final boolean sameLine = parentSameLine || style.isInline(this); if (!parentSameLine && headComment != null) { headComment.toFileString(bw, depth, style); } final String localtab = (parentSameLine ? "" : style.getTab(depth)); bw.write(localtab); if (!"".equals(name)) { bw.write(name); style.printEqualsSign(bw, depth); style.printOpeningBrace(bw, depth); } else { style.printOpeningBrace(bw, depth); } if (!sameLine) bw.newLine(); for (WritableObject obj : allWritable) { if (obj instanceof ObjectVariable || obj instanceof Comment) { if (!sameLine) { style.printTab(bw, depth + 1); } } obj.toFileString(bw, depth + 1, style); if (sameLine) bw.write(' '); else bw.newLine(); } if (parentSameLine) { bw.write('}'); } else if (sameLine) { bw.write("} "); if (inlineComment != null) inlineComment.toFileString(bw, depth, style); } else { bw.write(localtab + "}"); if (inlineComment != null) { bw.write(" "); inlineComment.toFileString(bw, depth, style); } if (style.newLineAfterObject()) bw.newLine(); } }