Package org.htmlunit.protocol.data
Class DataUrlDecoder
java.lang.Object
org.htmlunit.protocol.data.DataUrlDecoder
Helper to work with data URLs.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
DataUrlDecoder
(byte[] data, String mediaType, Charset charset) C'tor. -
Method Summary
Modifier and TypeMethodDescriptionstatic DataUrlDecoder
Decodes a data URL providing simple access to the information contained by the URL.static DataUrlDecoder
decodeDataURL
(String url) Decodes a data URL providing simple access to the information contained by the URL.private static byte[]
decodeUrl
(byte[] bytes) private static int
digit16
(byte b) private static Charset
extractCharset
(String beforeData) private static String
extractMediaType
(String beforeData) byte[]
getBytes()
Gets the bytes contained in the data URL.Gets the charset information specified in the data URL.Gets the text content of the data URL.Gets the media type information contained in the data URL.
-
Field Details
-
DEFAULT_CHARSET
-
DEFAULT_MEDIA_TYPE
- See Also:
-
mediaType_
-
charset_
-
content_
private final byte[] content_
-
-
Constructor Details
-
DataUrlDecoder
C'tor.- Parameters:
data
- the datamediaType
- the media typecharset
- the charset
-
-
Method Details
-
decode
Decodes a data URL providing simple access to the information contained by the URL.- Parameters:
url
- the URL to decode- Returns:
- the
DataUrlDecoder
holding decoded information - Throws:
UnsupportedEncodingException
- if the encoding specified by the data URL is invalid or not
-
decodeDataURL
Decodes a data URL providing simple access to the information contained by the URL.- Parameters:
url
- the string representation of the URL to decode- Returns:
- the
DataUrlDecoder
holding decoded information - Throws:
UnsupportedEncodingException
- if the encoding specified by the data URL is invalid or not available on the JVM
-
extractCharset
-
extractMediaType
-
getMediaType
Gets the media type information contained in the data URL.- Returns:
- "text/plain" if the URL didn't contain any media type information
-
getCharset
Gets the charset information specified in the data URL.- Returns:
- "US-ASCII" if the URL didn't contain any charset information
-
getBytes
public byte[] getBytes()Gets the bytes contained in the data URL.- Returns:
- the content
-
getDataAsString
Gets the text content of the data URL. This makes sense only for data URL that represents some text.- Returns:
- the text content
- Throws:
UnsupportedEncodingException
- if decoding failed using the specified charset
-
decodeUrl
private static byte[] decodeUrl(byte[] bytes) throws org.apache.commons.codec.DecoderException - Throws:
org.apache.commons.codec.DecoderException
-
digit16
private static int digit16(byte b) throws org.apache.commons.codec.DecoderException - Throws:
org.apache.commons.codec.DecoderException
-