Ignore:
Timestamp:
2019-04-07T07:14:21+02:00 (6 years ago)
Author:
gerdp
Message:

fix #17568: newline missing in exported *.poly file when only a single ring is written
Further changes

  • use PrinterWriter
  • add Unit test for export of simple polygon
File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/poly/src/poly/PolyExporter.java

    r34860 r34966  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.io.BufferedWriter;
    76import java.io.File;
    87import java.io.IOException;
     8import java.io.PrintWriter;
    99import java.nio.charset.StandardCharsets;
    1010import java.nio.file.Files;
     
    4343                throw new IOException(tr("Data contains unclosed ways."));
    4444            }
    45             try (BufferedWriter writer = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8)) {
     45            try (PrintWriter writer = new PrintWriter(Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8))) {
    4646                DataSet ds = ((OsmDataLayer) layer).getDataSet();
    4747                HashSet<Way> written = new HashSet<>();
     
    5656                    if (rel.isMultipolygon()) {
    5757                        if (!firstFile) {
    58                             writer.newLine();
     58                            writer.println();
    5959                        }
    6060                        writeRelation(writer, fileName, rel, written);
     
    6464               
    6565                if (firstFile) {
    66                     writer.write(fileName);
     66                    writer.println(fileName);
    6767                }
    6868                int counter = 1;
     
    7272                    }
    7373                }
    74                 writer.write("END");
    75                 writer.newLine();
     74                writer.println("END");
    7675            }
    7776        }
    7877    }
    7978
    80     private static void writeRelation(BufferedWriter writer, String fileName, Relation rel, Set<Way> written) throws IOException {
     79    private static void writeRelation(PrintWriter writer, String fileName, Relation rel, Set<Way> written) {
    8180        String polygonName = fileName;
    8281        if (rel.getName() != null)
    8382            polygonName = rel.getName();
    84         writer.write(polygonName);
    85         writer.newLine();
     83        writer.println(polygonName);
    8684        int counter = 1;
    8785        for (RelationMember rm: rel.getMembers()) {
     
    9694    }
    9795
    98     private static int writeWay(BufferedWriter writer, Way w, int counter) throws IOException {
     96    private static int writeWay(PrintWriter writer, Way w, int counter) {
    9997        String name = w.getName();
    10098        if (name == null) {
    10199            name = String.valueOf(counter++);
    102100        }
    103         writer.write(name);
    104         writer.newLine();
     101        writer.println(name);
    105102
    106103        for (Node n : w.getNodes()) {
    107             writer.write(String.format(Locale.ENGLISH, "   %f   %f", n.getCoor().lon(), n.getCoor().lat()));
    108             writer.newLine();
     104            writer.println(String.format(Locale.ENGLISH, "   %f   %f", n.getCoor().lon(), n.getCoor().lat()));
    109105        }
    110         writer.write("END");
    111         writer.newLine();
     106        writer.println("END");
    112107        return counter;
    113108    }
Note: See TracChangeset for help on using the changeset viewer.