We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › saveStream troubles
Page Index Toggle Pages: 1
saveStream troubles (Read 778 times)
saveStream troubles
Apr 4th, 2008, 2:47am
 
Hello, I'm encountering a problem trying to download a number of tables named by date. The trouble I'm having is that not every date has a file (dates like Christmas and the New Year are skipped), and when the program encounters a file that doesn't exist it ceases to work. I imagine there's a simple condition to lay down, but I can't figure it out for the life of me. Any help will be greatly appreciated.

Here's what I have:

Code:


String prefix="http://www.kcbt.com/download/kcprccsv/kcprccsv_";
String suffix=".csv";
String firstDateStamp= "20021122";
String lastDateStamp= "20080403";
int dateCount;
static final long MILLIS_PER_DAY=24*60*60*1000;

DateFormat stampFormat= new SimpleDateFormat("yyyyMMdd");
String[] dateStamp;

void setup(){
getTables();
}

void getTables(){
try{
Date firstDate= stampFormat.parse(firstDateStamp);
long firstDateMillis= firstDate.getTime();
Date lastDate= stampFormat.parse(lastDateStamp);
long lastDateMillis= lastDate.getTime();

dateCount=(int)
((lastDateMillis-firstDateMillis)/MILLIS_PER_DAY)+1;
dateStamp= new String[dateCount];

for(int i=0; i<dateCount; i++){
Date date= new Date(firstDateMillis+MILLIS_PER_DAY*i);
dateStamp[i]= stampFormat.format(date);
String filename= "wheatTables/"+dateStamp[i]+suffix;
String url= prefix+dateStamp[i]+suffix;
println("downloading "+url);

//***HERE'S THE PROBLEM (I think)****
if(?????){
saveStream(filename, url);
}

}
}catch(ParseException e){
die("hmmmmm", e);
}
}

Re: saveStream troubles
Reply #1 - Apr 4th, 2008, 3:10am
 
saveStream is basically loadBytes followed by saveBytes.. so and option would be to use those, and check if the data is null in between. try this:

Code:

byte[] b = loadBytes(url);
if (b != null) {
saveBytes(filename, b);
}
Re: saveStream troubles
Reply #2 - Apr 4th, 2008, 3:21am
 
that did the trick, thanks so much
Page Index Toggle Pages: 1