public final class CharsetUtils
extends java.lang.Object
In the absence of information provided by an external transport protocol (e.g. HTTP or MIME), it is a fatal error for an entity including an encoding declaration to be presented to the XML processor in an encoding other than that named in the declaration, or for an entity which begins with neither a Byte Order Mark nor an encoding declaration to use an encoding other than UTF-8. Note that since ASCII is a subset of UTF-8, ordinary ASCII entities do not strictly need an encoding declaration.
Unless an encoding is determined by a higher-level protocol, it is also a fatal error if an XML entity contains no encoding declaration and its content is not legal UTF-8 or UTF-16.
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
fromContentType(javax.servlet.ServletRequest request)
Returns the charset specified in the Content-Type header.
|
static java.lang.String |
fromContentType(java.lang.String contentType)
Returns the charset specified in the Content-Type header.
|
static java.lang.String |
fromXMLProlog(byte[] xml)
Scans the encoding specified in the XML prolog.
|
static java.io.InputStream |
skipByteOrderMark(java.io.InputStream is)
This method will remove (or read away) any byte order marks from the
stream.
|
public static java.lang.String fromContentType(javax.servlet.ServletRequest request)
request
- The servlet request.public static java.lang.String fromContentType(java.lang.String contentType)
contentType
- The header value.public static java.lang.String fromXMLProlog(byte[] xml)
xml
- The bytes of the xml prolog (or the entire document).public static java.io.InputStream skipByteOrderMark(java.io.InputStream is) throws java.io.IOException
is
- The inputstream to read fromInputStream
that you should use to read the data from.java.io.IOException
- If some error occurs while reading from the stream.Copyright © Technia AB. All Rights Reserved.