Image Download JavaAgent - URL to Local Drive

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Random;

import javax.imageio.ImageIO;

/** Created from Copy: 2013.01.06.1.00.AM

public final class RandomizeMyNumForImages {

  public static final void main(String[] aArgs){

 
    int START = 1;
    int END = 300;
    Random random = new Random();
    for (int idx = 1; idx <= 300; ++idx){
      showRandomInteger(START, END, random);
    }

    log(END);
  }

  private static void showRandomInteger(int aStart, int aEnd, Random aRandom){
    if ( aStart > aEnd ) {
      throw new IllegalArgumentException("Start cannot exceed End.");
    }
    
    
    BufferedImage image =null;
	  try{
    	
		//get the range, casting to long to avoid overflow problems
		    long range = (long)aEnd - (long)aStart + 1;
		    // compute a fraction of the range, 0 <= frac < range
		    long fraction = (long)(range * aRandom.nextDouble());
		    int randomNumber =  (int)(fraction + aStart);    
			  
		    System.out.println(randomNumber);
		    
		    int LogCounter;
		    

		    LogCounter=log(randomNumber);
		    


    URL url =new URL("http://www.yourwebsiteurl.com/yourimagenames"+LogCounter+".jpg");
    // read the url
   image = ImageIO.read(url);

    // save files a JPEG
    ImageIO.write(image, "jpg",new File("F:/Documents/Downloads/WEB_FILES/DELETE/"+"NewFileNames"+LogCounter+".jpg"));
	  
    //System.out.println(image);	  
    
}catch(IOException e){
    e.printStackTrace();
}

  }

  private static int log(int randomNumber){
      	  
	  
	    System.out.println(randomNumber);
		return randomNumber;	 

  }
} 





Use this sample to download images from URL based on similarly available names (having digit(s) at the end of the name to differentiate images), rename all image files and submit to your C;\ Drive at once.  Plug away at this one a bit, not fully tested, run as JavaAgent...

TIP: The above can be used in conjunction with the file-fetch into combo box on Xpages, submitted earlier.

Java
Köll S Cherizard
January 23, 2013 1:44 AM
Rating
25

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



No comments yetLogin first to comment...