Naming services: Export address books with Windows line endings on Windows (ticket #1557)

This commit is contained in:
zzz
2015-05-06 01:48:47 +00:00
parent abd8ca34dc
commit 77c9a644ac
2 changed files with 12 additions and 8 deletions

View File

@ -295,23 +295,26 @@ public abstract class NamingService {
if (list != null) if (list != null)
out.write(" (" + list + ')'); out.write(" (" + list + ')');
} }
out.write('\n'); final String nl = System.getProperty("line.separator", "\n");
out.write(nl);
int sz = entries.size(); int sz = entries.size();
if (sz <= 0) { if (sz <= 0) {
out.write("# No entries\n"); out.write("# No entries");
out.write(nl);
return; return;
} }
out.write("# Exported: "); out.write("# Exported: ");
out.write((new Date()).toString()); out.write((new Date()).toString());
out.write('\n'); out.write(nl);
if (sz > 1) { if (sz > 1) {
out.write("# " + sz + " entries\n"); out.write("# " + sz + " entries");
out.write(nl);
} }
for (Map.Entry<String, String> e : entries.entrySet()) { for (Map.Entry<String, String> e : entries.entrySet()) {
out.write(e.getKey()); out.write(e.getKey());
out.write('='); out.write('=');
out.write(e.getValue()); out.write(e.getValue());
out.write('\n'); out.write(nl);
} }
} }

View File

@ -443,10 +443,11 @@ public class SingleFileNamingService extends NamingService {
public void export(Writer out, Properties options) throws IOException { public void export(Writer out, Properties options) throws IOException {
out.write("# Address book: "); out.write("# Address book: ");
out.write(getName()); out.write(getName());
out.write('\n'); final String nl = System.getProperty("line.separator", "\n");
out.write(nl);
out.write("# Exported: "); out.write("# Exported: ");
out.write((new Date()).toString()); out.write((new Date()).toString());
out.write('\n'); out.write(nl);
BufferedReader in = null; BufferedReader in = null;
getReadLock(); getReadLock();
try { try {
@ -454,7 +455,7 @@ public class SingleFileNamingService extends NamingService {
String line = null; String line = null;
while ( (line = in.readLine()) != null) { while ( (line = in.readLine()) != null) {
out.write(line); out.write(line);
out.write('\n'); out.write(nl);
} }
} finally { } finally {
if (in != null) try { in.close(); } catch (IOException ioe) {} if (in != null) try { in.close(); } catch (IOException ioe) {}