package creatImg; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.net.Authenticator; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.PasswordAuthentication; import java.net.Proxy; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; import FileRead.Read; import Jdbc.Jdbc; import Jdbc.SqlCreate; public class getImg { public getImg() throws Exception { Jdbc db = new Jdbc(); Read read = new Read(); SqlCreate sqlCreate = new SqlCreate(); String selectSql = sqlCreate.selectCreate(" BB_FZ_TYPE_KIKAKU ", read.oldList); selectSql += "where KKK_KOSEI_CD='N010003' and GAZO_FILE_NM is not null"; ArrayList<ArrayList> valueList = db.select(selectSql, "testxjj5", read.oldList); int i=0; for (ArrayList list : valueList) { //030 String areaCd = (String) list.get(0); //System.out.println(list.get(0)); //N010002 String kkkCd = (String) list.get(1); //System.out.println(list.get(1)); //00010005 String nc = (String) list.get(2); // System.out.println(list.get(2)); //00010005_C11.jpg String imgNm = (String) list.get(3); // System.out.println(list.get(3)); //D:/project/workspace2/xjj-ol-front/webapp/jjcommon/KEISAI_AREA_CD/KKK_KOSEI_CD/img/PROJECT_CD(2)/GAZO_FILE_NM pathManager(areaCd, kkkCd, nc, imgNm); System.out.println(valueList.size()-i); i++; } System.out.println("End"); } // private void pathManager(String areaCd, String kkkCd, String nc, String imgNm) throws Exception { String path = "D:/project/workspace2/xjj-ol-front/webapp/jjcommon/gazo/bukken"; path += "/" + areaCd; pathExist(path); path += "/" + kkkCd; pathExist(path); path += "/img"; pathExist(path); path += "/" + nc.substring(nc.length() - 2, nc.length()); pathExist(path); //String imgNmT = imgNm.split(".")[0]+".jpg"; String pathT = path + "/" + imgNm.substring(0,imgNm.indexOf("."))+"_t_00.jpg"; fileExist(pathT); path += "/" + imgNm; fileExist(path); } private void pathExist(String path) throws Exception { // System.out.println(path); File file = new File(path); if (!file.exists()) { file.mkdir(); } } private void fileExist(String path) throws Exception { // System.out.println(path); File file = new File(path); if (!file.exists()) { //http://192.168.0.93/web/hthome/jj/front/gazo //http://wwwtst.k2.suumo.jp:10300/front/gazo/bukken String strUrl = "http://wwwtst.k2.suumo.jp:10300/front/gazo/bukken" + path.split("D:/project/workspace2/xjj-ol-front/webapp/jjcommon/gazo/bukken")[1]; // System.out.println(strUrl); try{ writeFile(strUrl, path); System.out.println(path); System.out.println(strUrl); System.out.println("OK"); }catch(Exception e){ if(e.getMessage().contains("Server returned HTTP response code: 407")){ }else{ // e.printStackTrace(); } } //file.createNewFile(); } } public static void writeFile(String strUrl, String fileName) throws Exception { InetAddress addr = InetAddress.getByName("192.174.10.205"); InetSocketAddress sa = new InetSocketAddress(addr, 8080); Proxy proxy = new Proxy(Proxy.Type.HTTP, sa); initProxy("192.174.10.205",8080,"testtest","testtest"); URL url = new URL(strUrl); // URLConnection conn = url.openConnection(); URLConnection conn = url.openConnection(proxy); InputStream is = conn.getInputStream(); OutputStream os = new FileOutputStream(fileName); int bytesRead = 0; byte[] buffer = new byte[8192]; while ((bytesRead = is.read(buffer, 0, 8192)) != -1) { os.write(buffer, 0, bytesRead); } } public static void initProxy(String host, int port, final String username, final String password) { Authenticator.setDefault(new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, new String(password).toCharArray()); } }); } }