/**
 * @Company:
 * @Author: lancer
 * @Date: 14-12-9 下午5:26
 * @Version: 1.0
 */
package com.github.sample.hadoop;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;


/**
 * <b>HadoopTest</b>
 * <p><b>详细说明：</b></p>
 * 在这里添加详细说明
 * <p><b>修改列表：</b></p>
 * <table width="" cellspacing=1 cellpadding=3 border=1>
 * <tr bgcolor="#CCCCFF"><td>序号</td><td>作者</td><td>修改日期</td><td>修改内容</td></tr>
 * <!--在此添加修改列表，参考第一行内容-->
 * <tr bgcolor="#CCCCFF"><td>1</td><td>lancer</td><td>14-12-9 下午5:26</td><td>新建内容</td></tr>
 */
public class HadoopTest {

    public static void main(String[] args) {
        String uri = "hdfs://localhost:9000/user/lancer/data/test.txt";
        String output = "hdfs://localhost:9000/user/lancer/data/output2";
        try {
            readHadoop(uri);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    static void readHadoop(String uri) throws IOException {
        InputStream in = null;
        Configuration configuration = new Configuration();
        FileSystem fs = FileSystem.get(URI.create(uri), configuration);
        try {
            in = fs.open(new Path(uri));
            IOUtils.copyBytes(in, System.out, 4096, false);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeStream(in);
        }
    }

}

@@ -196,16 +196,71 @@
 System;%0A
+import org.apache.hadoop.fs.FsUrlStreamHandlerFactory;%0A
 import o
@@ -395,19 +395,79 @@
 ava.net.
-URI
+MalformedURLException;%0Aimport java.net.URI;%0Aimport java.net.URL
 ;%0A%0A%0A/**%0A
@@ -913,37 +913,32 @@
 /localhost:9000/
-user/
 lancer/data/test
@@ -937,16 +937,18 @@
 ata/
-test.txt
+get-pip.py
 %22;%0A 
@@ -1020,34 +1020,17 @@
 tput2%22;%0A
-        try %7B%0A    
+%0A
         
@@ -1043,92 +1043,16 @@
 doop
+2
 (uri);%0A
-        %7D catch (IOException e) %7B%0A            e.printStackTrace();%0A        %7D%0A
     
@@ -1096,27 +1096,8 @@
 uri)
- throws IOException
  %7B%0A 
@@ -1181,24 +1181,42 @@
 guration();%0A
+        try %7B%0A    
         File
@@ -1279,38 +1279,24 @@
 n);%0A        
-try %7B%0A        
     in = fs.
@@ -1373,16 +1373,537 @@
 6, false
+);%0A        %7D catch (IOException e) %7B%0A            e.printStackTrace();%0A        %7D finally %7B%0A            IOUtils.closeStream(in);%0A        %7D%0A    %7D%0A%0A    static void readHadoop2(String uri) %7B%0A        // must be setting this config%0A        URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());%0A        InputStream in = null;%0A        try %7B%0A            in = new URL(uri).openStream();%0A            IOUtils.copyBytes(in, System.out, 4096, false);%0A        %7D catch (MalformedURLException e) %7B%0A            e.printStackTrace(
 );%0A     

add hdfs samples