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

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

Introduction

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

Prototype

public boolean exists(String src) throws IOException 

Source Link

Document

Implemented using getFileInfo(src)

Usage

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

License:Apache License

/**
 *   .//from  www. ja v a2  s  . c  o  m
 *
 * @param client    DFS Client
 * @param path       
 * @param recursive Recusive ? 
 * @return  <tt>true</tt>
 * @throws java.io.IOException ??    
 */
public static boolean remove(DFSClient client, String path, boolean recursive) throws IOException {
    if (client.exists(path)) {
        logger.info(" [{}] ??  . Recursive  [{}]", path,
                recursive);
        return client.delete(path, recursive);
    }
    logger.info(" [{}] ??  .", path);
    return false;
}

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

License:Apache License

/**
 *    ?./*from  w w w . java 2 s .  co m*/
 *
 * @param client DFS Client
 * @param path     ? 
 * @return  <tt>true</tt>
 * @throws java.io.IOException HDFS IO    
 */
public static boolean exists(DFSClient client, String path) throws IOException {
    return client.exists(path);
}

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 {/*  ww w  .j av  a2  s.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);
                }
            }
        }
    }
}