Use Guava charset enum

This commit is contained in:
Ignasi Barrera 2019-08-19 17:06:44 +02:00
parent d4b9f03059
commit 14ba1abcfb

View File

@ -25,7 +25,6 @@ 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;
@ -35,15 +34,16 @@ import org.jclouds.javax.annotation.Nullable;
import org.jclouds.logging.Logger;
import org.jclouds.rest.InvocationContext;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.util.Closeables2;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.base.Throwables;
import org.jclouds.util.Closeables2;
/**
* This object will parse the body of an HttpResponse and return the result of type <T> back to the
@ -94,7 +94,7 @@ public class ParseSax<T> implements Function<HttpResponse, T>, InvocationContext
String from = null;
try {
byte[] fromBytes = closeClientButKeepContentStream(response);
from = new String(fromBytes, StandardCharsets.UTF_8);
from = new String(fromBytes, Charsets.UTF_8);
validateXml(from);
// Use InputStream to skip over byte order mark.
return doParse(new InputSource(new ByteArrayInputStream(fromBytes)));
@ -135,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(StandardCharsets.UTF_8.name());
from.setEncoding(Charsets.UTF_8.name());
parser.setContentHandler(getHandler());
// This method should accept documents with a BOM (Byte-order mark)
parser.parse(from);