Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. public class S3ATextInputFormat extends TextInputFormat {
  2. private static final PathFilter hiddenFileFilter = p -> {
  3. String name = p.getName();
  4. return !name.startsWith("_") && !name.startsWith(".");
  5. };
  6.  
  7. private static class MultiPathFilter implements PathFilter {
  8. private List<PathFilter> filters;
  9.  
  10. public MultiPathFilter(List<PathFilter> filters) {
  11. this.filters = filters;
  12. }
  13.  
  14. public boolean accept(Path path) {
  15. for (PathFilter filter : filters) {
  16. if (!filter.accept(path)) {
  17. return false;
  18. }
  19. }
  20. return true;
  21. }
  22. }
  23.  
  24. @Override
  25. protected List<FileStatus> listStatus(JobContext job) throws IOException {
  26. Path[] inputPaths = getInputPaths(job);
  27. Configuration conf = job.getConfiguration();
  28.  
  29. List<PathFilter> filters = new ArrayList<PathFilter>();
  30. filters.add(hiddenFileFilter);
  31. PathFilter jobFilter = getInputPathFilter(job);
  32. if (jobFilter != null) {
  33. filters.add(jobFilter);
  34. }
  35. PathFilter inputFilter = new MultiPathFilter(filters);
  36.  
  37. return Arrays
  38. .stream(inputPaths)
  39. .flatMap(
  40. inputPath -> {
  41. try {
  42. return inputPath.getFileSystem(conf).listFiles(inputPath, true)
  43. } catch (IOException e) {
  44. throw new RuntimeException(e);
  45. }
  46. }
  47. )
  48. .collect(Collectors.toList());
  49.  
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement