Changes between Initial Version and Version 1 of III140118/Lab12


Ignore:
Timestamp:
Jan 18, 2014, 12:24:19 AM (10 years ago)
Author:
jazz
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • III140118/Lab12

    v1 v1  
     1◢ <[wiki:III140118/Lab11 實作十一]> | <[wiki:III140118 回課程大綱]> ▲ | <[wiki:III140118/Lab13 實作十三]> ◣
     2
     3= 實作十二 Lab12 =
     4
     5{{{
     6#!html
     7<p style="text-align: center;"><big style="font-weight: bold;"><big>Hadoop FileSystem API 實作(三)<br/>判斷檔案是否存在、屬性為何<br/>Testing HDFS Directories and Files</big></big></p>
     8}}}
     9[[PageOutline]]
     10{{{
     11#!text
     12請先連線至 nodeN.3du.me , N 為您的報名編號
     13}}}
     14
     15 * 延續上一個實作,我們也可以參考 !FsShell.java 的 test(String argv[], int i) 函數,來撰寫檢驗 HDFS 狀態的程式
     16{{{
     17#!java
     18 751   int test(String argv[], int i) throws IOException {
     19 752     if (!argv[i].startsWith("-") || argv[i].length() > 2)
     20 753       throw new IOException("Not a flag: " + argv[i]);
     21 754     char flag = argv[i].toCharArray()[1];
     22 755     Path f = new Path(argv[++i]);
     23 756     FileSystem srcFs = f.getFileSystem(getConf());
     24 757     switch(flag) {
     25 758       case 'e':
     26 759         return srcFs.exists(f) ? 0 : 1;
     27 760       case 'z':
     28 761         return srcFs.getFileStatus(f).getLen() == 0 ? 0 : 1;
     29 762       case 'd':
     30 763         return srcFs.getFileStatus(f).isDir() ? 0 : 1;
     31 764       default:
     32 765         throw new IOException("Unknown flag: " + flag);
     33 766     }
     34 767   }
     35}}}
     36 * 讓我們來執行觀察程式運作的情形,請剪貼以下步驟,並嘗試思考觀察到的結果:
     37{{{
     38cd ~/hadoop_labs/lab006
     39ant
     40hadoop jar isFile.jar input
     41hadoop jar isFile.jar file
     42hadoop jar isFile.jar empty
     43}}}
     44
     45 * 更多關於 HDFS !FileSystem API 的用法,請參考 org.apache.hadoop.fs.!FileSystem 的 javadoc
     46  * http://hadoop.apache.org/docs/r1.0.4/api/org/apache/hadoop/fs/FileSystem.html