Permalink
Browse files

Attempt to fix #220 by making UTF-8 output explicit in more places

  • Loading branch information...
ndw committed Aug 17, 2016
1 parent 3c145f5 commit 21e364788ab9b048b8488cea52d7d79581fa5ff1
@@ -1,12 +1,7 @@
package com.xmlcalabash.extensions;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -581,7 +576,12 @@ public void storeText(FileToZip file, XdmNode doc, OutputStream out) throws IOEx
}
public void storeJSON(FileToZip file, XdmNode doc, OutputStream out) {
PrintWriter writer = new PrintWriter(out);
PrintWriter writer = null;
try {
writer = new PrintWriter(new OutputStreamWriter(out, "UTF-8"));
} catch (UnsupportedEncodingException e) {
// This can't happen
}
try {
String json = XMLtoJSON.convert(doc);
writer.print(json);
@@ -176,6 +176,9 @@ public void run(String addnLog) {
public Serializer makeSerializer() {
Serializer serializer = runtime.getProcessor().newSerializer();
// This is XML; default to UTF-8
serializer.setOutputProperty(Serializer.Property.ENCODING, "UTF-8");
if (options == null) {
return serializer;
}
@@ -19,11 +19,7 @@
package com.xmlcalabash.library;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.*;
import java.net.URI;
import java.util.zip.GZIPOutputStream;
@@ -303,8 +299,7 @@ public void store(OutputStream outstr) throws IOException {
}
}
private URI storeJSON(final XdmNode doc, String href, String base,
String media) throws SaxonApiException {
private URI storeJSON(final XdmNode doc, String href, String base, String media) throws SaxonApiException {
if (media == null) {
media = "application/json";
}
@@ -322,7 +317,7 @@ private URI storeJSON(final XdmNode doc, String href, String base,
outstr = gzout;
}
PrintWriter writer = new PrintWriter(outstr);
PrintWriter writer = new PrintWriter(new OutputStreamWriter(outstr, "UTF-8"));
String json = XMLtoJSON.convert(doc);
writer.print(json);
} finally {
@@ -341,7 +336,7 @@ public void store(OutputStream outstr) throws IOException {
outstr = gzout;
}
PrintWriter writer = new PrintWriter(outstr);
PrintWriter writer = new PrintWriter(new OutputStreamWriter(outstr, "UTF-8"));
String json = XMLtoJSON.convert(doc);
writer.print(json);
// No need to close writer here - the underlying
@@ -32,14 +32,7 @@
import net.sf.saxon.s9api.Serializer;
import net.sf.saxon.s9api.XdmNode;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.*;
import java.net.URI;
import java.net.URLConnection;
@@ -122,7 +115,7 @@ private static void storeBinary(XdmNode doc, OutputStream stream) {
private static void storeJSON(XdmNode doc, OutputStream stream) {
try {
try {
PrintWriter writer = new PrintWriter(stream);
PrintWriter writer = new PrintWriter(new OutputStreamWriter(stream, "UTF-8"));
String json = XMLtoJSON.convert(doc);
writer.print(json);
} finally {

0 comments on commit 21e3647

Please sign in to comment.