You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ga...@apache.org on 2019/08/19 11:59:56 UTC
[jclouds] branch master updated: JCLOUDS-1510: ParseSax use charset
constant for all String creations
This is an automated email from the ASF dual-hosted git repository.
gaul pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jclouds.git
The following commit(s) were added to refs/heads/master by this push:
new dfeafcc JCLOUDS-1510: ParseSax use charset constant for all String creations
dfeafcc is described below
commit dfeafcc6fb914a6e5aa5293fcdf188e39a87842a
Author: Roded Bahat <ro...@model9.io>
AuthorDate: Mon Aug 12 18:46:56 2019 +0300
JCLOUDS-1510: ParseSax use charset constant for all String creations
This commit prevents the convertStreamToStringAndParse method from
failing XML validation on environments in which the default charset is
not compatible with UTF-8.
---
core/src/main/java/org/jclouds/http/functions/ParseSax.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/core/src/main/java/org/jclouds/http/functions/ParseSax.java b/core/src/main/java/org/jclouds/http/functions/ParseSax.java
index 1564db5..a277922 100644
--- a/core/src/main/java/org/jclouds/http/functions/ParseSax.java
+++ b/core/src/main/java/org/jclouds/http/functions/ParseSax.java
@@ -25,6 +25,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
import javax.annotation.Resource;
@@ -93,7 +94,7 @@ public class ParseSax<T> implements Function<HttpResponse, T>, InvocationContext
String from = null;
try {
byte[] fromBytes = closeClientButKeepContentStream(response);
- from = new String(fromBytes);
+ from = new String(fromBytes, StandardCharsets.UTF_8);
validateXml(from);
// Use InputStream to skip over byte order mark.
return doParse(new InputSource(new ByteArrayInputStream(fromBytes)));
@@ -134,7 +135,7 @@ public class ParseSax<T> implements Function<HttpResponse, T>, InvocationContext
protected T doParse(InputSource from) throws IOException, SAXException {
checkNotNull(from, "xml inputsource");
- from.setEncoding("UTF-8");
+ from.setEncoding(StandardCharsets.UTF_8.name());
parser.setContentHandler(getHandler());
// This method should accept documents with a BOM (Byte-order mark)
parser.parse(from);