Breaking News
Home / Java / Java Snippets (page 2)

Java Snippets

How to download Image from URL and save it in Java?

Snippet import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import; import; import;   public class ImageDownloader {           public static void main(String[] args )     {         BufferedImage image =null;         try{               URL …

Read More »

How to check if WEP Key is valid in Java?

Snippet  private static final Pattern HEX_DIGITS = Pattern.compile("[0-9A-Fa-f]+");     /**    * Check if wepKey is a valid hexadecimal string.    * @param wepKey the input to be checked    * @return true if the input string is indeed hex or empty.    * False if the input string …

Read More »

How to convert a String as Quoted String in Java?

Snippet  /**    * Encloses the incoming string inside double quotes, if it isn’t already quoted.    * @param string: the input string    * @return a quoted string, of the form "input".  If the input string is null, it returns null    * as well.    */   static …

Read More »

How to convert a Base64 Encoded Stream into an Image using Java?

Snippet import java.awt.image.BufferedImage; import; import;   import javax.imageio.ImageIO;   import sun.misc.BASE64Decoder;   public class Base64ImageTest {     public static void main(String args[]);      {         // this is not the real stream just for example         String base64String = "BORw0KGgoAAAANSUhEUgAAAUAAAAHgCAYAAADUjLREAAAgAElEQVR4AexdB4B …

Read More »

No Registered ImageReader claims to be able to read the resulting stream, null is returned.

Exception While trying to read and write image as PNG  with the code sas BufferedImage image = ByteArrayInputStream(decodedBytes));            if (image == null) {                log.error(“Buffered Image is null”);            }            File f = new File(uploadFile);             ImageIO.write(image, “png”, f);<!

Read More »