public static String probeContentType( final Path path ) throws UnsupportedOperationException, IOException, SecurityException { checkNotNull( "path", path ); if ( notExists( path ) ) { throw new NoSuchFileException( path.toString() ); } if ( !isRegularFile( path ) ) { throw new NoSuchFileException( path.toString() ); } throw new UnsupportedOperationException( "feature not available" ); }
public static Set<PosixFilePermission> getPosixFilePermissions( final Path path, final LinkOption... options ) throws UnsupportedOperationException, IOException, SecurityException { checkNotNull( "path", path ); if ( notExists( path ) ) { throw new NoSuchFileException( path.toString() ); } throw new UnsupportedOperationException( "feature not available" ); }
public static UserPrincipal getOwner( final Path path, final LinkOption... options ) throws UnsupportedOperationException, IOException, SecurityException { checkNotNull( "path", path ); if ( notExists( path ) ) { throw new NoSuchFileException( path.toString() ); } throw new UnsupportedOperationException( "feature not available" ); }
public static Path setOwner( final Path path, final UserPrincipal owner ) throws UnsupportedOperationException, IOException, SecurityException { checkNotNull( "path", path ); checkNotNull( "owner", owner ); if ( notExists( path ) ) { throw new NoSuchFileException( path.toString() ); } throw new UnsupportedOperationException( "feature not available" ); }
public static Path setPosixFilePermissions( final Path path, final Set<PosixFilePermission> perms ) throws UnsupportedOperationException, ClassCastException, IOException, SecurityException { checkNotNull( "path", path ); checkNotNull( "perms", perms ); if ( notExists( path ) ) { throw new NoSuchFileException( path.toString() ); } throw new UnsupportedOperationException( "feature not available" ); }
public static Path createTempDirectory( final Path dir, final String prefix, final FileAttribute<?>... attrs ) throws IllegalArgumentException, UnsupportedOperationException, IOException, SecurityException { checkNotNull( "dir", dir ); if ( notExists( dir ) ) { throw new NoSuchFileException( dir.toString() ); } final StringBuilder sb = new StringBuilder(); if ( prefix != null && prefix.trim().length() > 0 ) { sb.append( prefix ).append( "-" ); } final String baseName = sb.append( System.currentTimeMillis() ).append( "-" ).toString(); for ( int counter = 0; counter < TEMP_DIR_ATTEMPTS; counter++ ) { final Path path2Create = dir.resolve( baseName + counter ); try { return createDirectory( path2Create, attrs ); } catch ( Exception ex ) { } } throw new IllegalStateException( "Failed to create directory within " + TEMP_DIR_ATTEMPTS + " attempts (tried " + baseName + "0 to " + baseName + ( TEMP_DIR_ATTEMPTS - 1 ) + ')' ); }
public static Path createTempFile( final Path dir, final String prefix, final String suffix, final FileAttribute<?>... attrs ) throws IllegalArgumentException, UnsupportedOperationException, IOException, SecurityException { checkNotNull( "dir", dir ); if ( notExists( dir ) ) { throw new NoSuchFileException( dir.toString() ); } final StringBuilder sb = new StringBuilder(); if ( prefix != null && prefix.trim().length() > 0 ) { sb.append( prefix ).append( "-" ); } final String baseName = sb.append( System.currentTimeMillis() ).append( "-" ).toString(); final String realSufix; if ( suffix != null && suffix.trim().length() > 0 ) { realSufix = normalizeSuffix( suffix ); } else { realSufix = ".tmp"; } for ( int counter = 0; counter < TEMP_DIR_ATTEMPTS; counter++ ) { try { return createFile( dir.resolve( baseName + counter + realSufix ), attrs ); } catch ( Exception ex ) { } } throw new IllegalStateException( "Failed to create directory within " + TEMP_DIR_ATTEMPTS + " attempts (tried " + baseName + "0 to " + baseName + ( TEMP_DIR_ATTEMPTS - 1 ) + ')' ); }
/** * @throws UnsupportedOperationException * @throws IllegalArgumentException * @throws IOException * @throws SecurityException * @see <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#readAttributes(java.nio.file.Path, java.lang.String, java.nio.file.LinkOption...)">Original JavaDoc</a> */ public static Map<String, Object> readAttributes( final Path path, final String attributes, final LinkOption... options ) throws UnsupportedOperationException, NoSuchFileException, IllegalArgumentException, IOException, SecurityException { checkNotNull( "path", path ); checkNotEmpty( "attributes", attributes ); if ( notExists( path ) ) { throw new NoSuchFileException( path.toString() ); } return providerOf( path ).readAttributes( path, attributes, options ); }
@Override public void checkAccess( final Path path, final AccessMode... modes ) throws UnsupportedOperationException, NoSuchFileException, AccessDeniedException, IOException, SecurityException { checkNotNull( "path", path ); final JGitPathImpl gPath = toPathImpl( path ); final Pair<PathType, ObjectId> result = checkPath( gPath.getFileSystem().gitRepo(), gPath.getRefTree(), gPath.getPath() ); if ( result.getK1().equals( NOT_FOUND ) ) { throw new NoSuchFileException( path.toString() ); } }
public void deleteBranch( final JGitPathImpl path ) { final Ref branch = getBranch( path.getFileSystem().gitRepo(), path.getRefTree() ); if ( branch == null ) { throw new NoSuchFileException( path.toString() ); } JGitUtil.deleteBranch( path.getFileSystem().gitRepo(), branch ); }
private void copyBranch( final JGitPathImpl source, final JGitPathImpl target ) { checkCondition( "source and taget should have same setup", !hasSameFileSystem( source, target ) ); if ( existsBranch( target ) ) { throw new FileAlreadyExistsException( target.toString() ); } if ( !existsBranch( source ) ) { throw new NoSuchFileException( target.toString() ); } createBranch( source, target ); }
throw new NoSuchFileException( path );
@Override public <A extends BasicFileAttributes> A readAttributes( final Path path, final Class<A> type, final LinkOption... options ) throws NoSuchFileException, UnsupportedOperationException, IOException, SecurityException { checkNotNull( "path", path ); checkNotNull( "type", type ); final JGitPathImpl gPath = toPathImpl( path ); final Pair<PathType, ObjectId> pathResult = checkPath( gPath.getFileSystem().gitRepo(), gPath.getRefTree(), gPath.getPath() ); if ( pathResult.getK1().equals( NOT_FOUND ) ) { throw new NoSuchFileException( path.toString() ); } if ( type == BasicFileAttributesImpl.class || type == BasicFileAttributes.class || type == VersionAttributes.class ) { final JGitVersionAttributeView view = getFileAttributeView( path, JGitVersionAttributeView.class, options ); return (A) view.readAttributes(); } return null; }
@Override public <V extends FileAttributeView> V getFileAttributeView( final Path path, final Class<V> type, final LinkOption... options ) throws NoSuchFileException { checkNotNull( "path", path ); checkNotNull( "type", type ); final JGitPathImpl gPath = toPathImpl( path ); final Pair<PathType, ObjectId> pathResult = checkPath( gPath.getFileSystem().gitRepo(), gPath.getRefTree(), gPath.getPath() ); if ( pathResult.getK1().equals( NOT_FOUND ) ) { throw new NoSuchFileException( path.toString() ); } final V resultView = gPath.getAttrView( type ); if ( resultView == null && ( type == BasicFileAttributeView.class || type == VersionAttributeView.class || type == JGitVersionAttributeView.class ) ) { final V newView = (V) new JGitVersionAttributeView( gPath ); gPath.addAttrView( newView ); return newView; } return resultView; }
public void deleteAsset( final JGitPathImpl path, final DeleteOption... options ) { final Pair<PathType, ObjectId> result = checkPath( path.getFileSystem().gitRepo(), path.getRefTree(), path.getPath() ); if ( result.getK1().equals( PathType.DIRECTORY ) ) { if ( deleteNonEmptyDirectory( options ) ) { deleteResource( path, options ); return; } final List<JGitPathInfo> content = listPathContent( path.getFileSystem().gitRepo(), path.getRefTree(), path.getPath() ); if ( content.size() == 1 && content.get( 0 ).getPath().equals( path.getPath().substring( 1 ) + "/.gitignore" ) ) { delete( path.resolve( ".gitignore" ) ); deleteResource( path, options ); return; } throw new DirectoryNotEmptyException( path.toString() ); } if ( result.getK1().equals( NOT_FOUND ) ) { throw new NoSuchFileException( path.toString() ); } deleteResource( path, options ); }
throw new NoSuchFileException( "Can't find '" + gitPath + "' in tree '" + treeRef + "'" ); } finally { if ( rw != null ) { throw new NoSuchFileException( "" );
private void copyAsset( final JGitPathImpl source, final JGitPathImpl target, final CopyOption... options ) { final Pair<PathType, ObjectId> sourceResult = checkPath( source.getFileSystem().gitRepo(), source.getRefTree(), source.getPath() ); final Pair<PathType, ObjectId> targetResult = checkPath( target.getFileSystem().gitRepo(), target.getRefTree(), target.getPath() ); if ( !isRoot( target ) && targetResult.getK1() != NOT_FOUND ) { if ( !contains( options, StandardCopyOption.REPLACE_EXISTING ) ) { throw new FileAlreadyExistsException( target.toString() ); } } if ( sourceResult.getK1() == NOT_FOUND ) { throw new NoSuchFileException( target.toString() ); } if ( sourceResult.getK1() == DIRECTORY ) { copyDirectory( source, target, options ); return; } copyFile( source, target, options ); }