2011-08-01 31 views

回答

2

也許我誤解了這個問題。使用API​​實現了hadoop fs -tail -f不是嗎?

org.apache.hadoop.fs.FsShell.tail(String[], int)

long fileSize = srcFs.getFileStatus(path).getLen(); 
long offset = (fileSize > 1024) ? fileSize - 1024: 0; 

while (true) { 
    FSDataInputStream in = srcFs.open(path); 
    in.seek(offset); 
    IOUtils.copyBytes(in, System.out, 1024, false); 
    offset = in.getPos(); 
    in.close(); 
    if (!foption) { 
    break; 
    } 
    fileSize = srcFs.getFileStatus(path).getLen(); 
    offset = (fileSize > offset) ? offset: fileSize; 
    try { 
    Thread.sleep(5000); 
    } catch (InterruptedException e) { 
    break; 
    } 
}