Skip to content

Commit cd5e3af

Browse files
committed
check for java.util.Base64 presence
1 parent ba12ff6 commit cd5e3af

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ public static Base64 getInstance() {
1919
}
2020

2121
private static Base64 createInstance() {
22-
return new Java8Base64();
22+
if (Java8Base64.isAvailable()) {
23+
return new Java8Base64();
24+
}
25+
throw new IllegalStateException(
26+
"No Base64 implementation was provided. Java 8 Base64, Apache commons codec or JAXB is needed");
2327
}
2428

2529
public static void init(Base64 base64) {

scribejava-core/src/main/java/com/github/scribejava/core/base64/Java8Base64.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,12 @@ protected byte[] internalDecodeMime(String string) {
2020
return JAVA8_BASE64.internalDecodeMime(string);
2121
}
2222

23+
static boolean isAvailable() {
24+
try {
25+
Class.forName("java.util.Base64", false, Java8Base64.class.getClassLoader());
26+
return true;
27+
} catch (ClassNotFoundException cnfE) {
28+
return false;
29+
}
30+
}
2331
}

0 commit comments

Comments
 (0)