Java Code Examples for org.apache.hadoop.fs.FileUtil#canRead()

The following examples show how to use org.apache.hadoop.fs.FileUtil#canRead() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FSImagePreTransactionalStorageInspector.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: DiskChecker.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
  }
}
 
Example 3
Source File: FSImagePreTransactionalStorageInspector.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: DiskChecker.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
  }
}
 
Example 5
Source File: DiskChecker.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
  }
}
 
Example 6
Source File: NNStorage.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * @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;
}
 
Example 7
Source File: NNStorage.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * @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;
}
 
Example 8
Source File: NNStorage.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 9
Source File: StreamJob.java    From hadoop with Apache License 2.0 5 votes vote down vote up
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.");
    }
  }
}
 
Example 10
Source File: PathFinder.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 11
Source File: NNStorage.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * @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;
}
 
Example 12
Source File: NNStorage.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * @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;
}
 
Example 13
Source File: NNStorage.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 14
Source File: StreamJob.java    From big-c with Apache License 2.0 5 votes vote down vote up
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.");
    }
  }
}
 
Example 15
Source File: PathFinder.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}