Class DataUrlDecoder


  • public class DataUrlDecoder
    extends java.lang.Object
    Helper to work with data URLs.
    See Also:
    RFC2397
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected DataUrlDecoder​(byte[] data, java.lang.String mediaType, java.nio.charset.Charset charset)
      C'tor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static DataUrlDecoder decode​(java.net.URL url)
      Decodes a data URL providing simple access to the information contained by the URL.
      static DataUrlDecoder decodeDataURL​(java.lang.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 java.nio.charset.Charset extractCharset​(java.lang.String beforeData)  
      private static java.lang.String extractMediaType​(java.lang.String beforeData)  
      byte[] getBytes()
      Gets the bytes contained in the data URL.
      java.lang.String getCharset()
      Gets the charset information specified in the data URL.
      java.lang.String getDataAsString()
      Gets the text content of the data URL.
      java.lang.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
    • Field Detail

      • DEFAULT_CHARSET

        private static final java.nio.charset.Charset DEFAULT_CHARSET
      • DEFAULT_MEDIA_TYPE

        private static final java.lang.String DEFAULT_MEDIA_TYPE
        See Also:
        Constant Field Values
      • mediaType_

        private final java.lang.String mediaType_
      • charset_

        private final java.nio.charset.Charset charset_
      • content_

        private final byte[] content_
    • Constructor Detail

      • DataUrlDecoder

        protected DataUrlDecoder​(byte[] data,
                                 java.lang.String mediaType,
                                 java.nio.charset.Charset charset)
        C'tor.
        Parameters:
        data - the data
        mediaType - the media type
        charset - the charset
    • Method Detail

      • decode

        public static DataUrlDecoder decode​(java.net.URL url)
                                     throws java.io.UnsupportedEncodingException
        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:
        java.io.UnsupportedEncodingException - if the encoding specified by the data URL is invalid or not
      • decodeDataURL

        public static DataUrlDecoder decodeDataURL​(java.lang.String url)
                                            throws java.io.UnsupportedEncodingException
        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:
        java.io.UnsupportedEncodingException - if the encoding specified by the data URL is invalid or not available on the JVM
      • extractCharset

        private static java.nio.charset.Charset extractCharset​(java.lang.String beforeData)
      • extractMediaType

        private static java.lang.String extractMediaType​(java.lang.String beforeData)
      • getMediaType

        public java.lang.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 java.lang.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 java.lang.String getDataAsString()
                                         throws java.io.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:
        java.io.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