Package imageCrawler.FileProcessing

Source Code of imageCrawler.FileProcessing.SaveImages

package imageCrawler.FileProcessing;

import javax.imageio.ImageIO;

import Infrastructure.DAO;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.sql.SQLException;


public class SaveImages {

  static DAO d;
 
  public static DAO Instance()
  {
    if(d==null)
      d=new DAO();
       return d;
  }

  public static void saveImageFromURL(URL url)
  {
   
    BufferedImage image =null;
         
      try{
        String [] extension=url.toString().split("/");
       String fileName=extension[extension.length -1];
       String[]imageex1=fileName.split("\\.");
          
       if(imageex1.length  >1)
           {
            String imageex=imageex1[1];
          //read the url and load  
             
            //for different format of images
            if(imageex.equalsIgnoreCase("png"))
            {
              image = ImageIO.read(url);
                ImageIO.write(image, "png",new File(ImageConstants.SAVELOCATION+"\\"+fileName));
            }
            else if(imageex.equalsIgnoreCase("jpg"))
            {
              image = ImageIO.read(url);
                ImageIO.write(image, "jpg",new File(ImageConstants.SAVELOCATION+"\\"+fileName));
            }
            else if(imageex.equalsIgnoreCase("gif"))
            {
              image = ImageIO.read(url);
              ImageIO.write(image, "gif",new File(ImageConstants.SAVELOCATION+"\\"+fileName));
            }
            else if(imageex.equalsIgnoreCase("jpeg"))
            {
              image = ImageIO.read(url);
              ImageIO.write(image, "jpeg",new File(ImageConstants.SAVELOCATION+"\\"+fileName));
           
           
            try
            {
                SaveImages.Instance().SetImages(url.toString(),fileName);
            }
            catch(SQLException e)
            {
              System.out.println("Error Occured in SQL:"+e.getMessage());
            }
           
           }
        
    }
      catch(IOException e){
     
              e.printStackTrace();
      }
   
  }
 
 
}
TOP

Related Classes of imageCrawler.FileProcessing.SaveImages

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.