@@ -0,0 +1,2088 @@
+package org.schoellerfamily.gedbrowser.writer;%0A%0Aimport java.io.BufferedOutputStream;%0Aimport java.io.File;%0Aimport java.io.FileOutputStream;%0Aimport java.io.IOException;%0A%0Aimport org.apache.commons.logging.Log;%0Aimport org.apache.commons.logging.LogFactory;%0Aimport org.schoellerfamily.gedbrowser.datamodel.Root;%0A%0A/**%0A * @author Richard Schoeller%0A */%0Apublic class GedWriter %7B%0A    /** Logger. */%0A    private final transient Log logger = LogFactory.getLog(getClass());%0A%0A    /** */%0A    private final GedWriterLineCreator creator = new GedWriterLineCreator();%0A%0A    /** */%0A    private final Root root;%0A%0A    /**%0A     * @param root the root of the data set to write.%0A     */%0A    public GedWriter(final Root root) %7B%0A        this.root = root;%0A    %7D%0A%0A    /**%0A     * Write the file as directed.%0A     */%0A    public void write() %7B%0A        root.accept(creator);%0A        backup();%0A        final String filename = root.getFilename();%0A        try (FileOutputStream fstream = new FileOutputStream(filename);%0A                BufferedOutputStream bstream = new BufferedOutputStream(%0A                        fstream)) %7B%0A            for (final GedWriterLine line : creator.getLines()) %7B%0A                final String string = line.getLine();%0A                bstream.write(string.getBytes());%0A            %7D%0A        %7D catch (IOException e) %7B%0A            logger.error(%22Problem writing GEDCOM file%22, e);%0A        %7D%0A    %7D%0A%0A    /**%0A     * Save the existing version of the file.%0A     */%0A    private void backup() %7B%0A        final File dest = new File(root.getFilename());%0A        if (dest.exists()) %7B%0A            final File backupFile = generateBackupFilename();%0A            dest.renameTo(backupFile);%0A        %7D%0A    %7D%0A%0A    /**%0A     * @return the filename.n that doesn't exist%0A     */%0A    private File generateBackupFilename() %7B%0A        int i = 1;%0A        while (true) %7B%0A            final String backupFilename = root.getFinder() + %22.%22 + i;%0A            final File backupFile = new File(backupFilename);%0A            if (!backupFile.exists()) %7B%0A                return backupFile;%0A            %7D%0A            i++;%0A        %7D%0A    %7D%0A%7D%0A

add class to write gedcom to a file