package markpeng.mahout.test;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.util.ReflectionUtils;

public class HdfsAPITest {

	public void showRemoteFileList(String hdfsPath) throws Exception {
		Configuration conf = new Configuration();
		conf.set("fs.defaultFS", "hdfs://172.16.10.16:8020");

		FileSystem fs = FileSystem.get(conf);
		Path path = new Path(hdfsPath);

		FileStatus[] status = fs.listStatus(path);
		for (int i = 0; i < status.length; i++) {
			System.out.println(status[i].getPath());
		}
	}

	public void showFileList(String hdfsPath) throws Exception {
		Configuration conf = new Configuration();
		conf.set("fs.defaultFS", "hdfs://localhost:9000");

		FileSystem fs = FileSystem.get(conf);
		Path path = new Path(hdfsPath);

		FileStatus[] status = fs.listStatus(path);
		for (int i = 0; i < status.length; i++) {
			System.out.println(status[i].getPath());
		}
	}

	// public void showFileContent(String hdfsPath) throws Exception {
	// Configuration conf = new Configuration();
	// conf.set("fs.defaultFS", "hdfs://172.16.10.16:9000");
	//
	// FileSystem fs = FileSystem.get(conf);
	// Path path = new Path(hdfsPath);
	//
	// SequenceFile.Reader reader = new SequenceFile.Reader(conf,
	// SequenceFile.Reader.file(path));
	// // SequenceFile.Reader reader = new SequenceFile.Reader(FileSystem.get(
	// // URI.create(hdfsPath), conf), new Path(outputFile), conf);
	//
	// Writable key = (Writable) ReflectionUtils.newInstance(
	// reader.getKeyClass(), conf);
	// Writable value = (Writable) ReflectionUtils.newInstance(
	// reader.getValueClass(), conf);
	// System.out.println("Key: " + key.getClass().getName());
	// System.out.println("Value: " + value.getClass().getName());
	// while (reader.next(key, value)) {
	// System.out.println(key + "  <===>  " + value.toString());
	// }
	// reader.close();
	// }

	public static void main(String[] args) throws Exception {
		HdfsAPITest test = new HdfsAPITest();
		// test.showFileList("/user/markpeng/testdata");
		// test.showFileContent("hdfs://localhost:9000/user/markpeng/testoutput");
		// test.showRemoteFileList("/user/hdfs/markpeng/sparse-text-ik/tokenized-documents/part-m-00000");
	}

}

@@ -486,28 +486,26 @@
 %22hdfs://
-172.16.10.16
+dev-host18
 :8020%22);
@@ -1099,19 +1099,16 @@
 %09%7D%0A%09%7D%0A%0A%09
-// 
 public v
@@ -1164,19 +1164,17 @@
 tion %7B%0A%09
-// 
+%09
 Configur
@@ -1208,19 +1208,17 @@
 ion();%0A%09
-// 
+%09
 conf.set
@@ -1263,24 +1263,19 @@
 9000%22);%0A
-%09//%0A%09// 
+%0A%09%09
 FileSyst
@@ -1305,19 +1305,17 @@
 conf);%0A%09
-// 
+%09
 Path pat
@@ -1338,24 +1338,19 @@
 sPath);%0A
-%09//%0A%09// 
+%0A%09%09
 Sequence
@@ -1401,19 +1401,19 @@
 (conf,%0A%09
-// 
+%09%09%09
 Sequence
@@ -1437,22 +1437,20 @@
 path));%0A
+%09
 %09//
- //
  Sequenc
@@ -1512,19 +1512,17 @@
 m.get(%0A%09
-// 
+%09
 // URI.c
@@ -1578,16 +1578,11 @@
 f);%0A
-%09//%0A%09// 
+%0A%09%09
 Writ
@@ -1625,35 +1625,35 @@
 s.newInstance(%0A%09
-// 
+%09%09%09
 reader.getKeyCla
@@ -1666,19 +1666,17 @@
 conf);%0A%09
-// 
+%09
 Writable
@@ -1725,19 +1725,19 @@
 tance(%0A%09
-// 
+%09%09%09
 reader.g
@@ -1756,27 +1756,25 @@
 (), conf);%0A%09
-// 
+%09
 System.out.p
@@ -1818,19 +1818,17 @@
 me());%0A%09
-// 
+%09
 System.o
@@ -1880,19 +1880,17 @@
 me());%0A%09
-// 
+%09
 while (r
@@ -1916,19 +1916,18 @@
 ue)) %7B%0A%09
-// 
+%09%09
 System.o
@@ -1981,17 +1981,13 @@
 );%0A%09
-// %7D%0A%09// 
+%09%7D%0A%09%09
 read
@@ -1999,19 +1999,16 @@
 ose();%0A%09
-// 
 %7D%0A%0A%09publ
@@ -2225,29 +2225,26 @@
 stoutput%22);%0A
+
 %09%09
-// 
 test.showRem

Change remote testing port for HDFS API.