java.lang.Object
org.htmlunit.protocol.data.DataUrlDecoder
Helper to work with data URLs.
- Author:
- Marc Guillemot, Ronald Brill, Carsten Steul
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDataUrlDecoder(byte[] data, String mediaType, Charset charset) C'tor. -
Method Summary
Modifier and TypeMethodDescriptionstatic DataUrlDecoderDecodes a data URL providing simple access to the information contained by the URL.static DataUrlDecoderdecodeDataURL(String url) Decodes a data URL providing simple access to the information contained by the URL.byte[]getBytes()Gets the bytes contained in the data URL.Gets the charset information specified in the data URL.Gets the content type of the data URL, serialized like the browsers do it (e.g.getContentType(boolean standardSerialization) Gets the content type of the data URL, serialized like the browsers do it.Gets the text content of the data URL.Gets the media type information contained in the data URL.
-
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
DataUrlDecoderholding 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
DataUrlDecoderholding decoded information - Throws:
UnsupportedEncodingException- if the encoding specified by the data URL is invalid or not available on the JVM
-
getMediaType
Gets the media type information contained in the data URL.- Returns:
- "text/plain" if the URL didn't contain any media type information
-
getContentType
Gets the content type of the data URL, serialized like the browsers do it (e.g. 'text/plain;charset=utf-8' for 'data:text/plain;charset=utf-8,...').- Returns:
- the content type; "text/plain;charset=US-ASCII" if the URL didn't contain a valid MIME type
-
getContentType
Gets the content type of the data URL, serialized like the browsers do it.- Parameters:
standardSerialization- whether to serialize like the MIME Sniffing Standard (like Firefox; duplicate parameters are ignored) or like Chrome (seegetContentType())- Returns:
- the content type; "text/plain;charset=US-ASCII" if the URL didn't contain a valid MIME type
-
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
-