oozie java api

破棉襖發表於2014-08-23
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Properties;

public class GenerateLookupDirs {

    
/**
    * 
@param args
    
*/
    
public static final long dayMillis = 1000 * 60 * 60 * 24;
    
private static final String OOZIE_ACTION_OUTPUT_PROPERTIES = "oozie.action.output.properties";

    
public static void main(String[] args) throws Exception {
        Calendar curDate 
= new GregorianCalendar();
        
int year, month, date;
        String propKey, propVal;

        String oozieProp 
= System.getProperty(OOZIE_ACTION_OUTPUT_PROPERTIES);
        
if (oozieProp != null) {
            File propFile 
= new File(oozieProp);
            Properties props 
= new Properties();

            
for (int i = 0; I < 8++i) {
                year 
= curDate.get(Calendar.YEAR);
                month 
= curDate.get(Calendar.MONTH) + 1;
                date 
= curDate.get(Calendar.DATE);
                propKey 
= "dir"+i;
                propVal 
= year + "-" +
                    (month 
< 10 ? "0" + month : month) + "-" +
                    (date 
< 10 ? "0" + date : date);
                props.setProperty(propKey, propVal);
                curDate.setTimeInMillis(curDate.getTimeInMillis() 
- dayMillis);
            }
            OutputStream os 
= new FileOutputStream(propFile);
            props.store(os, 
"");
            os.close();
        } 
else
            
throw new RuntimeException(OOZIE_ACTION_OUTPUT_PROPERTIES
             
+ " System property not defined");
        }
}

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29754888/viewspace-1256485/,如需轉載,請註明出處,否則將追究法律責任。

相關文章