• hadoop读取数据


    package hadoopshiyan;
    
    
    import org.apache.hadoop.fs.*;
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    
    public class hadoopduqu extends FSDataInputStream {
    
        private static hadoopduqu myFSDataInputStream;
        private static InputStream inputStream;
    
        private hadoopduqu(InputStream in) {
            super(in);
            inputStream = in;
        }
    
        public static hadoopduqu getInstance(InputStream inputStream){
            if (null == myFSDataInputStream){
                synchronized (hadoopduqu.class){
                    if (null == myFSDataInputStream){
                        myFSDataInputStream = new hadoopduqu(inputStream);
                    }
                }
            }
            return myFSDataInputStream;
        }
    
        public static String readline(FileSystem fileStatus){
            try {
    //            FSDataInputStream inputStream = fileStatus.open(remotePath);
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                String line = null;
                if ((line = bufferedReader.readLine()) != null){
                    bufferedReader.close();
                    inputStream.close();
                    return line;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    
    }
    package hadoopshiyan;
    
    import org.apache.hadoop.fs.FileSystem;
    import org.apache.hadoop.fs.FsUrlStreamHandlerFactory;
    import org.apache.hadoop.fs.Path;
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.net.URL;
    
    public class shuchu {
    
        private Path remotePath;
        private FileSystem fileSystem;
    
        public shuchu(FileSystem fileSystem, Path remotePath){
            this.fileSystem = fileSystem;
            this.remotePath = remotePath;
        }
    
        public void show(){
            try {
                URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());
                InputStream inputStream = new URL("hdfs","localhost",8020,remotePath.toString()).openStream();
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                String line = null;
                while ((line = bufferedReader.readLine()) != null){
                    System.out.println(line);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    
    }
  • 相关阅读:
    Tech road one step Dec-5 to Dec-11
    Tech road one step Nov-28 to Dec-4
    Tech road one step 13-Nov to 20-Nov
    Unity 相机花式分屏
    Unity渲染
    Perfect Rectangle(完美矩形)
    Max Points on a Line(直线上最多的点数)
    Unity之CharacterController 碰撞问题总结
    cocos2dx 实现flappybird
    effectiveC++ 内存管理 学习笔记
  • 原文地址:https://www.cnblogs.com/520520520zl/p/14199327.html
Copyright © 2020-2023  润新知