@Override public void prepare() throws IOException { String argPattern = getArgument(1); if (!caseSensitive) { argPattern = StringUtils.toLowerCase(argPattern); } globPattern = new GlobPattern(argPattern); }
void init(String filePattern, PathFilter filter) throws IOException { try { userFilter = filter; pattern = new GlobPattern(filePattern); } catch (PatternSyntaxException e) { throw new IOException("Illegal file pattern: " + e.getMessage(), e); } }
public static Path getFirstMatch(FileSystem fs, Path path, String globPatternStr, boolean recursive) throws IOException { RemoteIterator<LocatedFileStatus> files = fs.listFiles(path, recursive); GlobPattern globPattern = new GlobPattern(globPatternStr); while (files.hasNext()) { Path aFile = files.next().getPath(); if(globPattern.matches(aFile.getName())) return aFile; } return null; }
@Override protected Pattern compile(String s) { return GlobPattern.compile(s); }
/** * Determines based on config settings and suitability of {@code fixedPath} whether to use * flat globbing logic where we use a single large listing during globStatus to then perform * the core globbing logic in-memory. */ @VisibleForTesting boolean shouldUseFlatGlob(Path fixedPath) { // Config setting overrides all else. if (!enableFlatGlob) { return false; } // Only works for filesystems where the base Hadoop Path scheme matches the underlying URI // scheme for GCS. if (!getUri().getScheme().equals(GoogleCloudStorageFileSystem.SCHEME)) { LOG.debug( "Flat glob is on, but doesn't work for scheme '{}'; using default behavior.", getUri().getScheme()); return false; } // The full pattern should have a wildcard, otherwise there's no point doing the flat glob. GlobPattern fullPattern = new GlobPattern(fixedPath.toString()); if (!fullPattern.hasWildcard()) { LOG.debug( "Flat glob is on, but Path '{}' has no wildcard; using default behavior.", fixedPath); return false; } // To use a flat glob, there must be an authority defined. if (Strings.isNullOrEmpty(fixedPath.toUri().getAuthority())) { LOG.info( "Flat glob is on, but Path '{}' has a empty authority, using default behavior.", fixedPath); return false; } // And the authority must not contain a wildcard. GlobPattern authorityPattern = new GlobPattern(fixedPath.toUri().getAuthority()); if (authorityPattern.hasWildcard()) { LOG.info( "Flat glob is on, but Path '{}' has a wildcard authority, using default behavior.", fixedPath); return false; } return true; }
/** * Compile glob pattern string * * @param globPattern the glob pattern * @return the pattern object */ public static Pattern compile(String globPattern) { return new GlobPattern(globPattern).compiled(); }