22
22
import org .openrewrite .java .MethodMatcher ;
23
23
import org .openrewrite .java .search .UsesType ;
24
24
import org .openrewrite .java .tree .J ;
25
+ import org .openrewrite .java .tree .JavaSourceFile ;
25
26
import org .openrewrite .java .tree .JavaType ;
26
27
27
28
import java .time .Duration ;
@@ -53,6 +54,8 @@ protected JavaIsoVisitor<ExecutionContext> getVisitor() {
53
54
private final MethodMatcher apacheEncodeToString = new MethodMatcher ("org.apache.commons.codec.binary.Base64 encodeBase64String(byte[])" );
54
55
private final MethodMatcher apacheEncode64 = new MethodMatcher ("org.apache.commons.codec.binary.Base64 encodeBase64(byte[])" );
55
56
private final MethodMatcher apacheDecode = new MethodMatcher ("org.apache.commons.codec.binary.Base64 decodeBase64(..)" );
57
+ private final MethodMatcher apacheEncode64UrlSafe = new MethodMatcher ("org.apache.commons.codec.binary.Base64 encodeBase64URLSafe(..)" );
58
+ private final MethodMatcher apacheEncode64UrlSafeString = new MethodMatcher ("org.apache.commons.codec.binary.Base64 encodeBase64URLSafeString(..)" );
56
59
57
60
@ Override
58
61
public J .MethodInvocation visitMethodInvocation (J .MethodInvocation method , ExecutionContext executionContext ) {
@@ -65,6 +68,10 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
65
68
templatePrefix = "Base64.getEncoder().encode(#{anyArray()})" ;
66
69
} else if (apacheDecode .matches (mi )) {
67
70
templatePrefix = "Base64.getDecoder().decode(#{any(String)})" ;
71
+ } else if (apacheEncode64UrlSafe .matches (mi )) {
72
+ templatePrefix = "Base64.getUrlEncoder().withoutPadding().encode(#{anyArray()})" ;
73
+ } else if (apacheEncode64UrlSafeString .matches (mi )) {
74
+ templatePrefix = "Base64.getUrlEncoder().withoutPadding().encodeToString(#{anyArray()})" ;
68
75
}
69
76
if (templatePrefix != null ) {
70
77
JavaTemplate t = JavaTemplate .builder (this ::getCursor , templatePrefix ).imports ("java.util.Base64" ).build ();
0 commit comments