Package com.helger.css.utils
Class CSSDataURL
java.lang.Object
com.helger.css.utils.CSSDataURL
This class represents a single CSS data URL (RFC 2397).
- Author:
- Philip Helger
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.CSSDataURL(com.helger.commons.mime.IMimeType aMimeType, boolean bBase64Encoded, byte[] aContent) ConstructorCSSDataURL(com.helger.commons.mime.IMimeType aMimeType, boolean bBase64Encoded, byte[] aContent, Charset aCharset, String sContent) Full constructor -
Method Summary
Modifier and TypeMethodDescriptionbooleangetAsString(boolean bOptimizedVersion) static CharsetgetCharsetFromMimeTypeOrDefault(com.helger.commons.mime.IMimeType aMimeType) Determine the charset from the passed MIME type.Get the data content of this Data URL as String.getContentAsString(Charset aCharset) Get the data content of this Data URL as String in the specified charset.byte[]Get a copy of all content bytes.intcom.helger.commons.mime.IMimeTypeinthashCode()booleantoString()voidWrite all the binary content to the passed output stream.
-
Constructor Details
-
CSSDataURL
public CSSDataURL()Default constructor. Default MIME type, no Base64 encoding and no content. -
CSSDataURL
public CSSDataURL(@Nonnull com.helger.commons.mime.IMimeType aMimeType, boolean bBase64Encoded, @Nonnull byte[] aContent) Constructor- Parameters:
aMimeType- The MIME type to be used. If it contains a charset, this charset will be used otherwise the default charset will be used.bBase64Encoded-trueif the content of this data should be Base64 encoded. It is recommended to set this totrueif you have binary data like images.aContent- The content of the data URL as a byte array. May not benull.
-
CSSDataURL
public CSSDataURL(@Nonnull com.helger.commons.mime.IMimeType aMimeType, boolean bBase64Encoded, @Nonnull byte[] aContent, @Nonnull Charset aCharset, @Nullable String sContent) Full constructor- Parameters:
aMimeType- The MIME type to be used. May not benull. If you don't know provide the default MIME type fromCSSDataURLHelper.DEFAULT_MIME_TYPE.bBase64Encoded-trueif the data URL String representation should be Base64 encoded,falseif not. It is recommended to set this totrueif you have binary data like images.aContent- The content of the data URL as a byte array. May not benullbut may be empty. This content may not be Base64 encoded!aCharset- The charset to be used to encode the String. May not benull. The default isCSSDataURLHelper.DEFAULT_CHARSET.sContent- The String representation of the content. It must match the byte array in the specified charset. If this parameter isnullthan the String content representation is lazily created ingetContentAsString().
-
-
Method Details
-
getCharsetFromMimeTypeOrDefault
@Nonnull public static Charset getCharsetFromMimeTypeOrDefault(@Nullable com.helger.commons.mime.IMimeType aMimeType) Determine the charset from the passed MIME type. If no charset was found, return the default charset.- Parameters:
aMimeType- The MIME type to investigate.- Returns:
- Never
null.
-
getMimeType
- Returns:
- The MIME type of the data URL. If none was specified, than the
default MIME Type
CSSDataURLHelper.DEFAULT_MIME_TYPEmust be used.
-
isBase64Encoded
public boolean isBase64Encoded()- Returns:
trueif the parsed data URL was Base64 encoded or if this data URL should be Base64 encoded.
-
getContentLength
- Returns:
- The length of the content in bytes. Always ≥ 0.
-
getContentBytes
Get a copy of all content bytes. No Base64 encoding is performed in this method.- Returns:
- A copy of the binary data of the data URL. Neither
nullbut maybe empty.
-
writeContentBytes
Write all the binary content to the passed output stream. No Base64 encoding is performed in this method.- Parameters:
aOS- The output stream to write to. May not benull.- Throws:
IOException- from OutputStream
-
getCharset
- Returns:
- The charset to be used for String encoding. May not be
null. The default isCSSDataURLHelper.DEFAULT_CHARSET.
-
getContentAsString
Get the data content of this Data URL as String. If no String representation was provided in the constructor, than it is lazily created inside this method in which case instances of this class are not thread-safe. If a non-nullString was provided in the constructor, this object is immutable. No Base64 encoding is performed in this method.- Returns:
- The content in a String representation using the charset of this
object. Never
null.
-
getContentAsBase64EncodedString
Get the content as a Base64 encodedStringin theCharsetspecified bygetCharset(). The encoding is applied independent of theisBase64Encoded()state.- Returns:
- Never
null.
-
getContentAsString
Get the data content of this Data URL as String in the specified charset. No Base64 encoding is performed in this method.- Parameters:
aCharset- The charset to be used. May not benull.- Returns:
- The content in a String representation using the provided charset.
Never
null.
-
getAsString
- Returns:
- The complete representation of the data URL, starting with "data:". All data is emitted, even if it is the default value. Base64 encoding is performed in this method.
-
getAsString
- Parameters:
bOptimizedVersion-trueto create optimized version- Returns:
- The complete representation of the data URL, starting with "data:". All data is emitted, even if it is the default value.
-
equals
-
hashCode
public int hashCode() -
toString
-