how to avoid warning for the Base 64?
java
Solution
Don't use internal com.sun.* packages. If you are on v6 or greater you can use DatatypeConverter. Your code would look like:
String base64String = DatatypeConverter.printBase64Binary(baos.toByteArray());
byte[] bytearray = DatatypeConverter.parseBase64Binary(base64String);
Problem
I have just tried a sample code form net it shows a warning as follows SimpleConvertImage.java:7: warning:com.sun.org.apache.xerces.internal.impl.dv.util.Base64 is internal proprietary API and may be removed in a future release import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; ^ SimpleConvertImage.java:16: warning: com.sun.org.apache.xerces.internal.impl.dv.util. Base64 is internal proprietary API and may be removed in a future release String base64String=Base64.encode(baos.toByteArray()); ^ SimpleConvertImage.java:19: warning: com.sun.org.apache.xerces.internal.impl.dv.util .Base64 is internal proprietary API and may be removed in a future release byte[] bytearray =Base64.decode(base64String); ^ the code is the below one ` ``` import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; public class SimpleConvertImage { public static void main(String[] args) throws IOException{ String dirName="/root/Desktop"; ByteArrayOutputStream baos=new ByteArrayOutputStream(1000); BufferedImage img=ImageIO.read(new File(dirName,"Screenshot.png")); ImageIO.write(img, "png", baos); baos.flush(); String base64String=Base64.encode(baos.toByteArray()); baos.close(); byte[] bytearray =Base64.decode(base64String); BufferedImage imag=ImageIO.read(new ByteArrayInputStream(bytearray)); ImageIO.write(imag, "png", new File(dirName,"snap3.png")); } } ``` `