@Override public Path createDirectory( final Path dir, final FileAttribute<?>... attrs ) throws IllegalArgumentException, UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException { return Files.createDirectory( dir, attrs ); }
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 ) + ')' ); }
protected synchronized Path internalCreateDirectory( final Path dir, final boolean skipAlreadyExistsException, final FileAttribute<?>... attrs ) throws IllegalArgumentException, UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException { checkNotNull( "dir", dir ); FileAttribute<?>[] allAttrs = attrs; try { Files.createDirectory( dir, attrs ); } catch ( final FileAlreadyExistsException ex ) { final Properties properties = new Properties(); if ( exists( dot( dir ) ) ) { properties.load( newInputStream( dot( dir ) ) ); } allAttrs = consolidate( properties, attrs ); if ( !skipAlreadyExistsException ) { throw ex; } } buildDotFile( dir, newOutputStream( dot( dir ) ), allAttrs ); return dir; }