package com.application.pgm.util;


import java.awt.Color;

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

import java.net.URL;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;


import javax.imageio.ImageIO;


public class ImageFileDownload {


public static void main(String[] args) {

// TODO Auto-generated method stub

FileReader fr = null;

String imgUrl = "";

try{

fr = new FileReader("D:\\dev\\workspace\\URL_TEST\\src\\com\\application\\pgm\\util\\imgFileList.txt");

BufferedReader list_br = new BufferedReader(fr);

String list_Line = new String();

String imgFileName = new String();

List downLoadList = new ArrayList<>();

while((list_Line = list_br.readLine()) != null){

imgUrl = list_Line.trim();

imgUrl = imgUrl.replaceAll("image1", "image5");

imgUrl = imgUrl.replaceAll("usahanatour","hanatour");

System.out.println();

imgUrl = imgUrl.substring(0, imgUrl.trim().length()-5);

Map rowMap = new HashMap<String, String>();

rowMap.put("imgUrlPath_S", imgUrl+"S.jpg");

rowMap.put("imgName_S", rowMap.get("imgUrlPath_S").toString().substring(imgUrl.lastIndexOf("/")+1, rowMap.get("imgUrlPath_S").toString().length()));

rowMap.put("imgUrlPath_M", imgUrl+"M.jpg");

rowMap.put("imgName_M", rowMap.get("imgUrlPath_M").toString().substring(imgUrl.lastIndexOf("/")+1, rowMap.get("imgUrlPath_M").toString().length()));

rowMap.put("imgUrlPath_L", imgUrl+"L.jpg");

rowMap.put("imgName_L", rowMap.get("imgUrlPath_L").toString().substring(imgUrl.lastIndexOf("/")+1, rowMap.get("imgUrlPath_L").toString().length()));

downLoadList.add(rowMap);

}

String downImg = new String();

BufferedImage image = null;

BufferedImage bufferedImage = null;

Graphics2D graphics = null;

for(int inx = 0; inx < downLoadList.size(); inx++){

Map rowMap = (Map)downLoadList.get(inx);


image = ImageIO.read(new URL(rowMap.get("imgUrlPath_S").toString()));

if(image.getData() != null){

bufferedImage = new BufferedImage(image.getWidth(),image.getHeight(), BufferedImage.TYPE_INT_BGR);

graphics = (Graphics2D) bufferedImage.getGraphics();

graphics.setBackground(Color.WHITE);

graphics.drawImage(image, 0, 0, null);

ImageIO.write(bufferedImage, "jpg", new File("D:\\000.Document\\003.운영업무\\미주지역\\상품이미지업로드\\2014.12.18\\"+rowMap.get("imgName_S")));

System.out.println(rowMap.get("imgName_S")+" 다운완료");

}

image = ImageIO.read(new URL(rowMap.get("imgUrlPath_M").toString()));

if(image.getData() != null){

bufferedImage = new BufferedImage(image.getWidth(),image.getHeight(), BufferedImage.TYPE_INT_BGR);

graphics = (Graphics2D) bufferedImage.getGraphics();

graphics.setBackground(Color.WHITE);

graphics.drawImage(image, 0, 0, null);

ImageIO.write(bufferedImage, "jpg", new File("D:\\000.Document\\003.운영업무\\미주지역\\상품이미지업로드\\2014.12.18\\"+rowMap.get("imgName_M")));

System.out.println(rowMap.get("imgName_M")+" 다운완료");

}

image = ImageIO.read(new URL(rowMap.get("imgUrlPath_L").toString()));

if(image.getData() != null){

bufferedImage = new BufferedImage(image.getWidth(),image.getHeight(), BufferedImage.TYPE_INT_BGR);

graphics = (Graphics2D) bufferedImage.getGraphics();

graphics.setBackground(Color.WHITE);

graphics.drawImage(image, 0, 0, null);

ImageIO.write(bufferedImage, "jpg", new File("D:\\"+rowMap.get("imgName_L")));

System.out.println(rowMap.get("imgName_L")+" 다운완료");

}

}

System.out.println("작업 끝났음 +_+");

/*

*/

}catch(Exception e){

e.printStackTrace();

}

}


}

+ Recent posts