/** * Retrieve a compressed image from a base-64 encoded PNG file. * @param base64 - the base 64-encoded PNG. * @return The compressed image. */ public static CompressedImage fromBase64Png(String base64) { try { return new EncodedCompressedImage("data:image/png;base64," + base64); } catch (IllegalArgumentException e) { // Remind the caller throw new IllegalArgumentException("Must be a pure base64 encoded string. Cannot be an encoded text.", e); } }
@Override public String getMime() { initialize(); return super.getMime(); }
@Override protected byte[] getData() { initialize(); return super.getData(); }
/** * Ensure that we have decoded the content of the encoded text. */ protected void initialize() { if (mime == null || data == null) { decode(); } }
/** * Retrieve a compressed image from an encoded text. * @param text - the encoded text. * @return The corresponding compressed image. */ public static CompressedImage fromEncodedText(String text) { return new EncodedCompressedImage(text); }