Example usage for org.apache.hadoop.hdfs DFSClient open

List of usage examples for org.apache.hadoop.hdfs DFSClient open

Introduction

In this page you can find the example usage for org.apache.hadoop.hdfs DFSClient open.

Prototype

public DFSInputStream open(String src) throws IOException 

Source Link

Usage

From source file:org.opencloudengine.flamingo.mapreduce.util.HdfsUtils.java

License:Apache License

/**
 * DFS Client?  ? ./* w  w w  .ja va2s.com*/
 *
 * @param client   DFS Client
 * @param filename ? 
 * @return  
 * @throws java.io.IOException HDFS IO    
 */
public static InputStream getInputStream(DFSClient client, String filename) throws IOException {
    return client.open(filename);
}

From source file:util.ResourceFile.java

License:Open Source License

public static InputStream getInputStream(String fileURI) throws IOException {
    if (isHDFSFile(fileURI)) {
        // Meta data file is a file within HDFS
        Configuration conf = new Configuration();
        DFSClient dfsClient = new DFSClient(conf);
        String hdfsFileName = hdfsFileName(fileURI);

        if (!dfsClient.exists(hdfsFileName))
            return null;

        Log.info("Opening HDFS file (" + hdfsFileName + ")");
        return dfsClient.open(hdfsFileName);
    } else {//w ww . ja  va2s .c  o m
        File metaFile = new File(fileURI);
        if (metaFile.exists()) {
            // Meta data file is a file on local file system
            Log.info("Opening local file (" + metaFile + ")");
            return new FileInputStream(metaFile);
        } else {
            // Try meta data file as resource available in jar
            try {
                throw new IOException("foo");
            } catch (IOException e) {
                String className = e.getStackTrace()[1].getClassName();
                try {
                    Class<?> callerClass = Class.forName(className);
                    Log.info("Opening resource file (" + fileURI + ")");
                    Log.info("using class (" + className + ")");
                    return callerClass.getResourceAsStream(fileURI);
                } catch (ClassNotFoundException e1) {
                    e1.printStackTrace();
                    throw new RuntimeException(e1);
                }
            }
        }
    }
}