@Override public boolean resourceExists( Configuration conf ) throws IOException { // unfortunately getFileSystem( conf ).exists( getPath() ); does not account for "/*" etc // nor is there an more efficient means to test for existence FileStatus[] fileStatuses = getFileSystem( conf ).globStatus( getPath() ); return fileStatuses != null && fileStatuses.length > 0; }
@Override public boolean resourceExists( Configuration conf ) throws IOException { // unfortunately getFileSystem( conf ).exists( getPath() ); does not account for "/*" etc // nor is there an more efficient means to test for existence FileStatus[] fileStatuses = getFileSystem( conf ).globStatus( getPath() ); return fileStatuses != null && fileStatuses.length > 0; }
/** * Given a file-system object, it makes an array of paths * * @param conf of type JobConf * @throws IOException on failure */ private void makeStatuses( Configuration conf ) throws IOException { if( statuses != null ) return; statuses = getFileSystem( conf ).listStatus( getPath() ); }
@Override public String getFullIdentifier( Configuration conf ) { return getPath().makeQualified( getFileSystem( conf ) ).toString(); }
/** * Given a file-system object, it makes an array of paths * * @param conf of type JobConf * @throws IOException on failure */ private void makeStatuses( Configuration conf ) throws IOException { if( statuses != null ) return; statuses = getFileSystem( conf ).listStatus( getPath() ); }
@Override public String getFullIdentifier( Configuration conf ) { return getPath().makeQualified( getFileSystem( conf ) ).toString(); }
public FileStatus getFileStatus( Configuration conf ) throws IOException { return getFileSystem( conf ).getFileStatus( getPath() ); }
public FileStatus getFileStatus( Configuration conf ) throws IOException { return getFileSystem( conf ).getFileStatus( getPath() ); }
@Override public boolean createResource( Configuration conf ) throws IOException { if( LOG.isDebugEnabled() ) LOG.debug( "making dirs: {}", getFullIdentifier( conf ) ); return getFileSystem( conf ).mkdirs( getPath() ); }
@Override public boolean createResource( Configuration conf ) throws IOException { if( LOG.isDebugEnabled() ) LOG.debug( "making dirs: {}", getFullIdentifier( conf ) ); return getFileSystem( conf ).mkdirs( getPath() ); }
public boolean deleteChildResource( Configuration conf, String childIdentifier ) throws IOException { resetFileStatuses(); Path childPath = new Path( childIdentifier ).makeQualified( getFileSystem( conf ) ); if( !childPath.toString().startsWith( getFullIdentifier( conf ) ) ) return false; return deleteFullIdentifier( conf, childPath.toString() ); }
public boolean deleteChildResource( Configuration conf, String childIdentifier ) throws IOException { resetFileStatuses(); Path childPath = new Path( childIdentifier ).makeQualified( getFileSystem( conf ) ); if( !childPath.toString().startsWith( getFullIdentifier( conf ) ) ) return false; return deleteFullIdentifier( conf, childPath.toString() ); }
private void getChildPaths( Configuration conf, Set<String> results, int trim, Path path, int depth ) throws IOException { if( depth == 0 ) { String substring = path.toString().substring( trim ); String identifier = getIdentifier(); if( identifier == null || identifier.isEmpty() ) results.add( new Path( substring ).toString() ); else results.add( new Path( identifier, substring ).toString() ); return; } FileStatus[] statuses = getFileSystem( conf ).listStatus( path, HIDDEN_FILES_FILTER ); if( statuses == null ) return; for( FileStatus fileStatus : statuses ) getChildPaths( conf, results, trim, fileStatus.getPath(), depth - 1 ); }
private void getChildPaths( Configuration conf, Set<String> results, int trim, Path path, int depth ) throws IOException { if( depth == 0 ) { String substring = path.toString().substring( trim ); String identifier = getIdentifier(); if( identifier == null || identifier.isEmpty() ) results.add( new Path( substring ).toString() ); else results.add( new Path( identifier, substring ).toString() ); return; } FileStatus[] statuses = getFileSystem( conf ).listStatus( path, HIDDEN_FILES_FILTER ); if( statuses == null ) return; for( FileStatus fileStatus : statuses ) getChildPaths( conf, results, trim, fileStatus.getPath(), depth - 1 ); }
private boolean deleteFullIdentifier( Configuration conf, String fullIdentifier ) throws IOException { if( LOG.isDebugEnabled() ) LOG.debug( "deleting: {}", fullIdentifier ); resetFileStatuses(); Path fullPath = new Path( fullIdentifier ); // do not delete the root directory if( fullPath.depth() == 0 ) return true; FileSystem fileSystem = getFileSystem( conf ); try { return fileSystem.delete( fullPath, true ); } catch( NullPointerException exception ) { // hack to get around npe thrown when fs reaches root directory // removes coupling to the new aws hadoop artifacts that may not be deployed if( !( fileSystem.getClass().getSimpleName().equals( "NativeS3FileSystem" ) ) ) throw exception; } return true; }
private boolean deleteFullIdentifier( Configuration conf, String fullIdentifier ) throws IOException { if( LOG.isDebugEnabled() ) LOG.debug( "deleting: {}", fullIdentifier ); resetFileStatuses(); Path fullPath = new Path( fullIdentifier ); // do not delete the root directory if( fullPath.depth() == 0 ) return true; FileSystem fileSystem = getFileSystem( conf ); try { return fileSystem.delete( fullPath, true ); } catch( NullPointerException exception ) { // hack to get around npe thrown when fs reaches root directory // removes coupling to the new aws hadoop artifacts that may not be deployed if( !( fileSystem.getClass().getSimpleName().equals( "NativeS3FileSystem" ) ) ) throw exception; } return true; }
@Override public boolean isDirectory( Configuration conf ) throws IOException { if( !resourceExists( conf ) ) return false; return getFileSystem( conf ).getFileStatus( getPath() ).isDir(); }
@Override public long getSize( Configuration conf ) throws IOException { if( !resourceExists( conf ) ) return 0; FileStatus fileStatus = getFileStatus( conf ); if( fileStatus.isDir() ) return 0; return getFileSystem( conf ).getFileStatus( getPath() ).getLen(); }
@Override public boolean isDirectory( Configuration conf ) throws IOException { if( !resourceExists( conf ) ) return false; return getFileSystem( conf ).getFileStatus( getPath() ).isDir(); }
@Override public long getSize( Configuration conf ) throws IOException { if( !resourceExists( conf ) ) return 0; FileStatus fileStatus = getFileStatus( conf ); if( fileStatus.isDir() ) return 0; return getFileSystem( conf ).getFileStatus( getPath() ).getLen(); }