Idea compile error report sun.misc.BASE64Decoder upgrade processing
warn:
17:01:15 /deploy/jenkins/workspace/auto-java-test/utils/ImageBase64Utils.java:67: warning: BASE64Encoder is internal proprietary API and may be removed in a future release
17:01:15 BASE64Encoder encoder = new BASE64Encoder();
import sun.misc.BASE64Decoder;
Alternative writing:
//Since JDK 1.8, the JDK public APIs of java.util.Base64.Decoder and java.util.Base64.Encoder have been provided, which can replace the JDK internal APIs of sun.misc.BASE64Decoder and sun.misc.BASE64Encoder.
//byte[] bytes = new BASE64Decoder().decodeBuffer(base64);
byte[] bytes = Base64.getDecoder().decode(base64);
//Or use method
import org.apache.commons.codec.binary.Base64;
return Base64.encodeBase64String(encrypted);
demo test class
@Test public void test2() throws Exception{ //Decoder and java.util.Base64.Encoder are available from JDK 1.8 onwards, replacing the internal JDK APIs of sun.misc. . //byte[] bytes = new BASE64Decoder().decodeBuffer(base64); System.out.println("-----------------------Early Write ----------------------"); String text = "String text"; BASE64Encoder encoder = new BASE64Encoder(); BASE64Decoder decoder = new BASE64Decoder(); byte[] textByte = text.getBytes("UTF-8"); //Code String encodedText = encoder.encode(textByte); System.out.println(encodedText); //Decoding System.out.println(new String(decoder.decodeBuffer(encodedText), "UTF-8")); /** * Compared with the Base64 codecs provided by sun.mis c suite and Apache Commons Codec, the Base64 provided by Java 8 has better performance. In the actual test of encoding and decoding speed, Base64 provided by Java 8 is at least 11 times faster than that provided by sun.mis c suite and at least 3 times faster than that provided by Apache Commons Codec. So if you want to use Base64 in Java, the Base64 category provided by the java .util package under Java 8 is definitely the first choice! * https://blog.csdn.net/zhou_kapenter/article/details/62890262 */ System.out.println("-----------------------New writing style----------------------"); byte[] test11 = Base64.getEncoder().encode(textByte); System.out.println("test11_string="+new String(test11, "UTF-8")); byte[] bytes11 = Base64.getDecoder().decode(test11); System.out.println("test11="+new String(bytes11, "UTF-8")); System.out.println("-----------------------apache writing style----------------------"); String test22 = org.apache.tomcat.util.codec.binary.Base64.encodeBase64String(textByte); System.out.println("test22_string="+test22); byte[] bytes22 = org.apache.tomcat.util.codec.binary.Base64.decodeBase64(test22); System.out.println("test22="+new String(bytes22, "UTF-8")); /** * Print results: Consistent results * ----------------------- early write ---------------------- * 5a2X5Liy5paH5a2X * String text * ----------------------- new write ---------------------- * test11 string = 5a2X5Liy5paH5a2X * test11=string literal * -----------------------apache writeup ---------------------- * test22 string=5a2X5Liy5paH5a2X * test22=word string literal */ }
Similar Posts:
- IDEA sun.misc.BASE64Encoder
- Sun.misc.base64decoder import exception and handling ideas
- Steps of MyEclipse / eclipse importing sun.misc.base64encoder jar package
- [Solved] Eclipse Error: Access restriction: The type ‘BASE64Decoder’ is not API
- Java – Convert bytes to unsigned bytes
- The solution of base64decoder prompt error under eclipse
- [Solved] exception is java.lang.NoClassDefFoundError: com.sun.crypto.provider.SunJCE
- [Solved] Hadoop running jar package error: java.lang.exception: java.lang.arrayindexoutofboundsexception: 1
- Solution to the problem of Java program “resource leak: ‘SC’ is never closed” in vscode
- AES secret key length error: java.security.InvalidKeyException: Illegal key size or default parameters [Solved]