Changes between Version 2 and Version 3 of III131019/Lab12


Ignore:
Timestamp:
Oct 19, 2013, 10:59:25 PM (11 years ago)
Author:
jazz
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • III131019/Lab12

    v2 v3  
    55= 實作十二 Lab12 =
    66
     7 * 延續上一個實作,我們也可以參考 FsShell.java 的 test(String argv[], int i) 函數,來撰寫檢驗 HDFS 狀態的程式
     8{{{
     9#!java
     10 751   int test(String argv[], int i) throws IOException {
     11 752     if (!argv[i].startsWith("-") || argv[i].length() > 2)
     12 753       throw new IOException("Not a flag: " + argv[i]);
     13 754     char flag = argv[i].toCharArray()[1];
     14 755     Path f = new Path(argv[++i]);
     15 756     FileSystem srcFs = f.getFileSystem(getConf());
     16 757     switch(flag) {
     17 758       case 'e':
     18 759         return srcFs.exists(f) ? 0 : 1;
     19 760       case 'z':
     20 761         return srcFs.getFileStatus(f).getLen() == 0 ? 0 : 1;
     21 762       case 'd':
     22 763         return srcFs.getFileStatus(f).isDir() ? 0 : 1;
     23 764       default:
     24 765         throw new IOException("Unknown flag: " + flag);
     25 766     }
     26 767   }
     27}}}
    728{{{
    829cd ~/hadoop_labs/lab006
     
    1334}}}
    1435
    15 == Reference javadoc ==
    16 
    17  * http://hadoop.apache.org/docs/r1.0.4/api/org/apache/hadoop/fs/FileSystem.html
     36 * 更多關於 HDFS FileSystem API 的用法,請參考 org.apache.hadoop.fs.FileSystem 的 javadoc
     37  * http://hadoop.apache.org/docs/r1.0.4/api/org/apache/hadoop/fs/FileSystem.html