com.gargoylesoftware.htmlunit.protocol.data
Class DataUrlDecoder

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.protocol.data.DataUrlDecoder

public class DataUrlDecoder
extends Object

Helper to work with data URLs.

Version:
$Revision: 5301 $
Author:
Marc Guillemot
See Also:
RFC2397

Constructor Summary
protected DataUrlDecoder(byte[] data, String mediaType, String charset)
          C'tor.
 
Method Summary
static DataUrlDecoder decode(URL url)
          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.
 byte[] getBytes()
          Gets the bytes contained in the data URL.
 String getCharset()
          Gets the charset information specified in the data URL.
 String getDataAsString()
          Gets the text content of the data URL.
 String getMediaType()
          Gets the media type information contained in the data URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataUrlDecoder

protected DataUrlDecoder(byte[] data,
                         String mediaType,
                         String charset)
C'tor.

Parameters:
data - the data
mediaType - the media type
charset - the charset
Method Detail

decode

public static DataUrlDecoder decode(URL url)
                             throws UnsupportedEncodingException,
                                    org.apache.commons.codec.DecoderException
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 available on the JVM
org.apache.commons.codec.DecoderException - if decoding didn't success

decodeDataURL

public static DataUrlDecoder decodeDataURL(String url)
                                    throws UnsupportedEncodingException,
                                           org.apache.commons.codec.DecoderException
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
org.apache.commons.codec.DecoderException - if decoding didn't success

getMediaType

public String 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

public String 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

public String getDataAsString()
                       throws UnsupportedEncodingException
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


Copyright © 2002-2011 Gargoyle Software Inc.. All Rights Reserved.