-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathUtils.java
More file actions
26 lines (21 loc) · 789 Bytes
/
Utils.java
File metadata and controls
26 lines (21 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package dev.samstevens.totp.util;
import org.apache.commons.codec.binary.Base64;
public final class Utils {
private static Base64 base64Codec = new Base64();
// Class not meant to be instantiated
private Utils() {
}
/**
* Given the raw data of an image and the mime type, returns
* a data URI string representing the image for embedding in
* HTML/CSS.
*
* @param data The raw bytes of the image.
* @param mimeType The mime type of the image.
* @return The data URI string representing the image.
*/
public static String getDataUriForImage(byte[] data, String mimeType) {
String encodedData = new String(base64Codec.encode(data));
return String.format("data:%s;base64,%s", mimeType, encodedData);
}
}