package ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
/**
* Download pictures of remote websites and set Referer to anti-link theft.
*
* @author JAVA Century Network (, )
*/
public class ImageDownloader {
/**
* Download the file to the specified location
* @param imgurl Download link
* @param f target file
* @return Return file successfully, return null if failed
*/
public static File download(String imgurl, File f) {
try {
URL url = new URL(imgurl);
URLConnection con = ();
int index = ("/", 10);
("Host", index == -1 ? (7) : (7, index));
("Referer", imgurl);
InputStream is = ();
if (() != null && ().equalsIgnoreCase("gzip")) {
is = new GZIPInputStream(());
}
byte[] bs = new byte[1024];
int len = -1;
OutputStream os = new FileOutputStream(f);
try {
while ((len = (bs)) != -1) {
(bs, 0, len);
}
} finally {
try {
();
} catch (Exception ex) {}
try {
();
} catch (Exception ex) {}
}
return f;
} catch (Exception ex) {
();
return null;
}
}
}