@Override public boolean notExists( final Path path ) throws IllegalArgumentException, SecurityException { return Files.notExists( path ); }
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 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 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 ); }
public static Path createDirectories( final Path dir, final FileAttribute<?>... attrs ) throws UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException { checkNotNull( "dir", dir ); final Path absoluteDir = dir.toAbsolutePath(); if ( !notExists( absoluteDir ) ) { throw new FileAlreadyExistsException( absoluteDir.toString() ); } Path parent = absoluteDir.getParent(); while ( parent != null ) { try { providerOf( parent ).checkAccess( parent ); break; } catch ( NoSuchFileException x ) { } parent = parent.getParent(); } if ( parent == null ) { throw new IOException( "Root directory does not exist" ); } // create directories Path child = parent; for ( final Path name : parent.relativize( dir ) ) { child = child.resolve( name ); providerOf( child ).createDirectory( child, attrs ); } return dir; }