changed filesaving to use counter to prevent duplicate filename issues

This commit is contained in:
Hannes
2017-11-10 00:55:20 +01:00
parent 0c21dec95c
commit 0cb9063458

View File

@@ -16,9 +16,10 @@ public class ImageDownloader {
downloadedImages = new LinkedList<>(); downloadedImages = new LinkedList<>();
} }
private void downloadImage(final String url, final String folderPath) throws IOException { private void downloadImage(final String url, final String folderPath, final int counter) throws IOException {
final InputStream in = new URL(url).openStream(); final InputStream in = new URL(url).openStream();
final String fileName = url.substring(url.lastIndexOf("/")).replaceAll("[^A-Za-z0-9.]", ""); final String fileName = "Comic_" + counter;// url.substring(url.lastIndexOf("/")).replaceAll("[^A-Za-z0-9.]",
// "");
downloadedImages.add(folderPath + fileName); downloadedImages.add(folderPath + fileName);
@@ -28,9 +29,9 @@ public class ImageDownloader {
} }
public void downloadAllImages(final List<String> images, final String folderPath) { public void downloadAllImages(final List<String> images, final String folderPath) {
for (final String img : images) { for (int i = 0; i < images.size(); i++) {
try { try {
this.downloadImage(img, folderPath); this.downloadImage(images.get(i), folderPath, i);
} catch (final IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
return; return;