org.apache.hadoop.fs.FileUtil#canRead ( )源码实例Demo

下面列出了org.apache.hadoop.fs.FileUtil#canRead ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Determine the checkpoint time of the specified StorageDirectory
 *
 * @param sd StorageDirectory to check
 * @return If file exists and can be read, last checkpoint time. If not, 0L.
 * @throws IOException On errors processing file pointed to by sd
 */
static long readCheckpointTime(StorageDirectory sd) throws IOException {
  File timeFile = NNStorage.getStorageFile(sd, NameNodeFile.TIME);
  long timeStamp = 0L;
  if (timeFile.exists() && FileUtil.canRead(timeFile)) {
    DataInputStream in = new DataInputStream(new FileInputStream(timeFile));
    try {
      timeStamp = in.readLong();
      in.close();
      in = null;
    } finally {
      IOUtils.cleanup(LOG, in);
    }
  }
  return timeStamp;
}
 
源代码2 项目: hadoop   文件: DiskChecker.java
/**
 * Checks that the current running process can read, write, and execute the
 * given directory by using methods of the File object.
 * 
 * @param dir File to check
 * @throws DiskErrorException if dir is not readable, not writable, or not
 *   executable
 */
private static void checkAccessByFileMethods(File dir)
    throws DiskErrorException {
  if (!FileUtil.canRead(dir)) {
    throw new DiskErrorException("Directory is not readable: "
                                 + dir.toString());
  }

  if (!FileUtil.canWrite(dir)) {
    throw new DiskErrorException("Directory is not writable: "
                                 + dir.toString());
  }

  if (!FileUtil.canExecute(dir)) {
    throw new DiskErrorException("Directory is not executable: "
                                 + dir.toString());
  }
}
 
/**
 * Determine the checkpoint time of the specified StorageDirectory
 *
 * @param sd StorageDirectory to check
 * @return If file exists and can be read, last checkpoint time. If not, 0L.
 * @throws IOException On errors processing file pointed to by sd
 */
static long readCheckpointTime(StorageDirectory sd) throws IOException {
  File timeFile = NNStorage.getStorageFile(sd, NameNodeFile.TIME);
  long timeStamp = 0L;
  if (timeFile.exists() && FileUtil.canRead(timeFile)) {
    DataInputStream in = new DataInputStream(new FileInputStream(timeFile));
    try {
      timeStamp = in.readLong();
      in.close();
      in = null;
    } finally {
      IOUtils.cleanup(LOG, in);
    }
  }
  return timeStamp;
}
 
源代码4 项目: big-c   文件: DiskChecker.java
/**
 * Checks that the current running process can read, write, and execute the
 * given directory by using methods of the File object.
 * 
 * @param dir File to check
 * @throws DiskErrorException if dir is not readable, not writable, or not
 *   executable
 */
private static void checkAccessByFileMethods(File dir)
    throws DiskErrorException {
  if (!FileUtil.canRead(dir)) {
    throw new DiskErrorException("Directory is not readable: "
                                 + dir.toString());
  }

  if (!FileUtil.canWrite(dir)) {
    throw new DiskErrorException("Directory is not writable: "
                                 + dir.toString());
  }

  if (!FileUtil.canExecute(dir)) {
    throw new DiskErrorException("Directory is not executable: "
                                 + dir.toString());
  }
}
 
源代码5 项目: lucene-solr   文件: DiskChecker.java
/**
 * Checks that the current running process can read, write, and execute the
 * given directory by using methods of the File object.
 *
 * @param dir File to check
 * @throws DiskErrorException if dir is not readable, not writable, or not
 *   executable
 */
private static void checkAccessByFileMethods(File dir)
    throws DiskErrorException {
  if (!dir.isDirectory()) {
    throw new DiskErrorException("Not a directory: "
        + dir.toString());
  }

  if (!FileUtil.canRead(dir)) {
    throw new DiskErrorException("Directory is not readable: "
        + dir.toString());
  }

  if (!FileUtil.canWrite(dir)) {
    throw new DiskErrorException("Directory is not writable: "
        + dir.toString());
  }
}
 
源代码6 项目: hadoop   文件: NNStorage.java
/**
 * @return The first image file with the given txid and image type.
 */
public File getFsImageName(long txid, NameNodeFile nnf) {
  for (Iterator<StorageDirectory> it = dirIterator(NameNodeDirType.IMAGE);
      it.hasNext();) {
    StorageDirectory sd = it.next();
    File fsImage = getStorageFile(sd, nnf, txid);
    if (FileUtil.canRead(sd.getRoot()) && fsImage.exists()) {
      return fsImage;
    }
  }
  return null;
}
 
源代码7 项目: hadoop   文件: NNStorage.java
/**
 * @return The first image file whose txid is the same with the given txid and
 * image type is one of the given types.
 */
public File getFsImage(long txid, EnumSet<NameNodeFile> nnfs) {
  for (Iterator<StorageDirectory> it = dirIterator(NameNodeDirType.IMAGE);
      it.hasNext();) {
    StorageDirectory sd = it.next();
    for (NameNodeFile nnf : nnfs) {
      File fsImage = getStorageFile(sd, nnf, txid);
      if (FileUtil.canRead(sd.getRoot()) && fsImage.exists()) {
        return fsImage;
      }
    }
  }
  return null;
}
 
源代码8 项目: hadoop   文件: NNStorage.java
/**
 * Return the first readable storage file of the given name
 * across any of the 'current' directories in SDs of the
 * given type, or null if no such file exists.
 */
private File findFile(NameNodeDirType dirType, String name) {
  for (StorageDirectory sd : dirIterable(dirType)) {
    File candidate = new File(sd.getCurrentDir(), name);
    if (FileUtil.canRead(sd.getCurrentDir()) &&
        candidate.exists()) {
      return candidate;
    }
  }
  return null;
}
 
源代码9 项目: hadoop   文件: StreamJob.java
private void validate(final List<String> values)
throws IllegalArgumentException {
  for (String file : values) {
    File f = new File(file);
    if (!FileUtil.canRead(f)) {
      fail("File: " + f.getAbsolutePath()
        + " does not exist, or is not readable.");
    }
  }
}
 
源代码10 项目: hadoop   文件: PathFinder.java
/**
 * Returns the full path name of this file if it is listed in the path
 */
public File getAbsolutePath(String filename) {
  if (pathenv == null || pathSep == null || fileSep == null) {
    return null;
  }
  int val = -1;
  String classvalue = pathenv + pathSep;

  while (((val = classvalue.indexOf(pathSep)) >= 0)
      && classvalue.length() > 0) {
    // Extract each entry from the pathenv
    String entry = classvalue.substring(0, val).trim();
    File f = new File(entry);

    if (f.isDirectory()) {
      // this entry in the pathenv is a directory.
      // see if the required file is in this directory
      f = new File(entry + fileSep + filename);
    }
    // see if the filename matches and we can read it
    if (f.isFile() && FileUtil.canRead(f)) {
      return f;
    }
    classvalue = classvalue.substring(val + 1).trim();
  }
  return null;
}
 
源代码11 项目: big-c   文件: NNStorage.java
/**
 * @return The first image file with the given txid and image type.
 */
public File getFsImageName(long txid, NameNodeFile nnf) {
  for (Iterator<StorageDirectory> it = dirIterator(NameNodeDirType.IMAGE);
      it.hasNext();) {
    StorageDirectory sd = it.next();
    File fsImage = getStorageFile(sd, nnf, txid);
    if (FileUtil.canRead(sd.getRoot()) && fsImage.exists()) {
      return fsImage;
    }
  }
  return null;
}
 
源代码12 项目: big-c   文件: NNStorage.java
/**
 * @return The first image file whose txid is the same with the given txid and
 * image type is one of the given types.
 */
public File getFsImage(long txid, EnumSet<NameNodeFile> nnfs) {
  for (Iterator<StorageDirectory> it = dirIterator(NameNodeDirType.IMAGE);
      it.hasNext();) {
    StorageDirectory sd = it.next();
    for (NameNodeFile nnf : nnfs) {
      File fsImage = getStorageFile(sd, nnf, txid);
      if (FileUtil.canRead(sd.getRoot()) && fsImage.exists()) {
        return fsImage;
      }
    }
  }
  return null;
}
 
源代码13 项目: big-c   文件: NNStorage.java
/**
 * Return the first readable storage file of the given name
 * across any of the 'current' directories in SDs of the
 * given type, or null if no such file exists.
 */
private File findFile(NameNodeDirType dirType, String name) {
  for (StorageDirectory sd : dirIterable(dirType)) {
    File candidate = new File(sd.getCurrentDir(), name);
    if (FileUtil.canRead(sd.getCurrentDir()) &&
        candidate.exists()) {
      return candidate;
    }
  }
  return null;
}
 
源代码14 项目: big-c   文件: StreamJob.java
private void validate(final List<String> values)
throws IllegalArgumentException {
  for (String file : values) {
    File f = new File(file);
    if (!FileUtil.canRead(f)) {
      fail("File: " + f.getAbsolutePath()
        + " does not exist, or is not readable.");
    }
  }
}
 
源代码15 项目: big-c   文件: PathFinder.java
/**
 * Returns the full path name of this file if it is listed in the path
 */
public File getAbsolutePath(String filename) {
  if (pathenv == null || pathSep == null || fileSep == null) {
    return null;
  }
  int val = -1;
  String classvalue = pathenv + pathSep;

  while (((val = classvalue.indexOf(pathSep)) >= 0)
      && classvalue.length() > 0) {
    // Extract each entry from the pathenv
    String entry = classvalue.substring(0, val).trim();
    File f = new File(entry);

    if (f.isDirectory()) {
      // this entry in the pathenv is a directory.
      // see if the required file is in this directory
      f = new File(entry + fileSep + filename);
    }
    // see if the filename matches and we can read it
    if (f.isFile() && FileUtil.canRead(f)) {
      return f;
    }
    classvalue = classvalue.substring(val + 1).trim();
  }
  return null;
}