类org.apache.hadoop.fs.GlobFilter源码实例Demo

下面列出了怎么用org.apache.hadoop.fs.GlobFilter的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: datacollector   文件: HdfsFileSystem.java

public HdfsFileSystem(String filePattern, PathMatcherMode mode, boolean processSubdirectories, FileSystem fs) {
  this.filePattern = filePattern;
  this.processSubdirectories = processSubdirectories;
  this.fs = fs;

  try {
    if (mode == GLOB) {
      filter = new GlobFilter(filePattern);
    } else if (mode == REGEX) {
      Pattern pattern = Pattern.compile(filePattern);
      filter = path -> pattern.matcher(path.toString()).matches();
    } else {
      throw new IllegalArgumentException("Unrecognized Path Matcher Mode: " + mode.getLabel());
    }
  } catch(IOException e) {
    throw new IllegalArgumentException("Can't create filter pattern: " + e.toString(), e);
  }
}
 
源代码2 项目: laser   文件: HDFSHelper.java

public static Path[] getFilePaths(Path filePath, String filePattern,
		FileSystem fs) throws IOException {
	if (!fs.exists(filePath)) {
		return new Path[0];
	}
	FileStatus[] hdfsFiles = fs.listStatus(filePath, new GlobFilter(
			filePattern));
	Path[] hdfsFilePaths = FileUtil.stat2Paths(hdfsFiles);
	List<Path> files = new ArrayList<Path>();
	for (Path hdfsFilePath : hdfsFilePaths) {
		FileStatus fileStatus = fs.getFileStatus(hdfsFilePath);
		if (!fileStatus.isDir()) {
			files.add(hdfsFilePath);
		}
	}
	return files.toArray(new Path[0]);
}
 
源代码3 项目: laser   文件: Configuration.java

public synchronized void load(Path path, FileSystem fs) throws IOException {
	final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
	FileStatus[] fileStatus = fs.listStatus(path, new GlobFilter(
			"*.properties"));
	for (FileStatus file : fileStatus) {
		if (file.isFile()) {
			Path p = file.getPath();
			FSDataInputStream in = fs.open(p);
			Collection configuration = OBJECT_MAPPER.readValue(in,
					Collection.class);
			String collection = p.getName().substring(0,
					p.getName().lastIndexOf(".properties"));
			configuration.setCollecion(collection);
			mapper.put(collection, configuration);
		}
	}
}
 
源代码4 项目: envelope   文件: SecurityUtils.java

/**
 * Get a list of token store files for the job. The {@value TOKENS_FILE}
 * prefix is suffixed with "*" to perform a glob search.
 * @param config application section of Envelope job config
 * @param hadoopConf Hadoop Configuration for the FileSystem
 * @return list of {@link Path}s of matching files
 * @throws IOException if the FileSystem cannot be read
 */
public static List<Path> getExistingTokenStoreFiles(Config config, Configuration hadoopConf, boolean onDriver) throws IOException {
  Path tokenFilePrefix = new Path(getTokenStoreFilePath(config, onDriver));
  FileSystem fs = FileSystem.get(hadoopConf);
  FileStatus[] matches = fs.listStatus(tokenFilePrefix.getParent(),
      new GlobFilter(tokenFilePrefix.getName() + "*"));
  List<Path> existingFiles = new ArrayList<>();
  for (FileStatus f : matches) {
    if (!f.getPath().getName().endsWith("READY")) {
      existingFiles.add(f.getPath());
    }
  }
  return existingFiles;
}
 
源代码5 项目: laser   文件: HDFSHelper.java

public static void deleteFiles(Path path, String filePattern, FileSystem fs)
		throws IOException {
	FileStatus[] fileStatus = fs.listStatus(path, new GlobFilter(
			filePattern));
	for (FileStatus file : fileStatus) {
		fs.delete(file.getPath(), true);
	}
}
 
源代码6 项目: hadoop   文件: FSOperations.java

/**
 * Creates a list-status executor.
 *
 * @param path the directory to retrieve the status of its contents.
 * @param filter glob filter to use.
 *
 * @throws IOException thrown if the filter expression is incorrect.
 */
public FSListStatus(String path, String filter) throws IOException {
  this.path = new Path(path);
  this.filter = (filter == null) ? this : new GlobFilter(filter);
}
 
源代码7 项目: big-c   文件: FSOperations.java

/**
 * Creates a list-status executor.
 *
 * @param path the directory to retrieve the status of its contents.
 * @param filter glob filter to use.
 *
 * @throws IOException thrown if the filter expression is incorrect.
 */
public FSListStatus(String path, String filter) throws IOException {
  this.path = new Path(path);
  this.filter = (filter == null) ? this : new GlobFilter(filter);
}
 
 类所在包
 同包方法