@Override public boolean exists( final Path path ) throws IllegalArgumentException, SecurityException { return Files.exists( path ); }
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" ); }
@Override public DirectoryStream<Path> newDirectoryStream( final Path dir ) throws IllegalArgumentException, NotDirectoryException, IOException, SecurityException { return Files.newDirectoryStream( dir ); }
@Override public synchronized Path move( final Path source, final Path target, final CopyOption... options ) throws UnsupportedOperationException, FileAlreadyExistsException, DirectoryNotEmptyException, AtomicMoveNotSupportedException, IOException, SecurityException { if ( Files.exists( dot( source ) ) ) { Files.move( dot( source ), dot( target ), forceBuildOptions( options ) ); } else if ( Files.exists( dot( target ) ) ) { Files.delete( dot( target ) ); } final Path result = Files.move( source, target, options ); return result; }
public List<Path> loadScenarioPaths(final Path path) { // Check Path exists final List<Path> items = new ArrayList<Path>(); if (!Files.exists(paths.convert(path))) { return items; } // Ensure Path represents a Folder org.kie.commons.java.nio.file.Path pPath = paths.convert(path); if (!Files.isDirectory(pPath)) { pPath = pPath.getParent(); } LinkedFilter filter = new LinkedDotFileFilter(); filter.setNextFilter( new LinkedMetaInfFolderFilter() ); // Get list of immediate children final DirectoryStream<org.kie.commons.java.nio.file.Path> directoryStream = ioService .newDirectoryStream(pPath); for (final org.kie.commons.java.nio.file.Path p : directoryStream) { if (filter.accept(p)) { if (Files.isRegularFile(p)) { items.add(paths.convert(p)); } else if (Files.isDirectory(p)) { items.add(paths.convert(p)); } } } // Add ability to move up one level in the hierarchy //items.add(new ParentPackageItem(paths.convert(pPath.getParent()), "..")); return items; }
if ( !Files.exists( paths.convert( path ) ) ) { return items; if ( !Files.isDirectory( pPath ) ) { pPath = pPath.getParent(); for ( final org.kie.commons.java.nio.file.Path pChild : directoryStream ) { if ( Files.isRegularFile( pChild ) ) { items.add( new FileItem( paths.convert( pChild ) ) ); } else if ( Files.isDirectory( pChild ) ) { if ( projectRootPath != null ) { final org.kie.commons.java.nio.file.Path pRoot = paths.convert( projectRootPath ); isProject = Files.isSameFile( pChild, pRoot );
if ( Files.isRegularFile( pathToSearch ) ) { if ( filter.accept( pathToSearch ) ) { discoveredFiles.add( pathToSearch ); if ( !Files.isDirectory( pathToSearch ) ) { return discoveredFiles; final DirectoryStream<Path> paths = Files.newDirectoryStream( pathToSearch ); for ( final Path path : paths ) { if ( Files.isRegularFile( path ) ) { if ( filter.accept( path ) ) { discoveredFiles.add( path ); } else if ( recursive && Files.isDirectory( path ) ) { discoveredFiles.addAll( discoverFiles( path, filter,
@Override public boolean accept( final org.kie.commons.java.nio.file.Path path ) { boolean accept = super.accept( path ); if ( !accept ) { return accept; } if ( !Files.isRegularFile( path ) ) { return false; } final String uri = path.toUri().toString(); if ( uri.substring( uri.length() - extension.length() ).equals( extension ) ) { return true; } return false; }
if ( Files.isRegularFile( nioResource ) ) { nioResource = nioResource.getParent(); boolean includeAttributes = Files.exists( nioMainSrcPath.resolve( packagePath ) ); final Path mainSrcPath = paths.convert( nioMainSrcPath.resolve( packagePath ), includeAttributes ); includeAttributes = Files.exists( nioTestSrcPath.resolve( packagePath ) ); final Path testSrcPath = paths.convert( nioTestSrcPath.resolve( packagePath ), includeAttributes ); includeAttributes = Files.exists( nioMainResourcesPath.resolve( packagePath ) ); final Path mainResourcesPath = paths.convert( nioMainResourcesPath.resolve( packagePath ), includeAttributes ); includeAttributes = Files.exists( nioTestResourcesPath.resolve( packagePath ) ); final Path testResourcesPath = paths.convert( nioTestResourcesPath.resolve( packagePath ), includeAttributes );
@Override public synchronized Path copy( final Path source, final Path target, final CopyOption... options ) throws UnsupportedOperationException, FileAlreadyExistsException, DirectoryNotEmptyException, IOException, SecurityException { if ( Files.exists( dot( source ) ) ) { Files.copy( dot( source ), dot( target ), forceBuildOptions( options ) ); } else if ( Files.exists( dot( target ) ) ) { Files.delete( dot( target ) ); } final Path result = Files.copy( source, target, buildOptions( options ) ); return result; }
private void visitPaths( final DirectoryStream<org.kie.commons.java.nio.file.Path> directoryStream ) { for ( final org.kie.commons.java.nio.file.Path path : directoryStream ) { if ( Files.isDirectory( path ) ) { visitPaths( Files.newDirectoryStream( path ) ); } else if ( filter.accept( path ) ) { final String destinationPath = path.toUri().toString().substring( projectPrefix.length() + 1 ); final InputStream is = ioService.newInputStream( path ); final BufferedInputStream bis = new BufferedInputStream( is ); kieFileSystem.write( destinationPath, KieServices.Factory.get().getResources().newInputStreamResource( bis ) ); handles.put( destinationPath, paths.convert( path ) ); } } }
@Override public synchronized Path setAttributes( final Path path, final FileAttribute<?>... attrs ) throws UnsupportedOperationException, IllegalArgumentException, ClassCastException, IOException, SecurityException { checkNotNull( "path", path ); if ( Files.isDirectory( path ) ) { return internalCreateDirectory( path, true, attrs ); } return write( path, readAllBytes( path ), Collections.<OpenOption>emptySet(), 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 ) + ')' ); }
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 ) + ')' ); }
BasicFileAttributes attrs = null; try { attrs = Files.readAttributes(file, BasicFileAttributes.class); } catch (IOException ex) { exc = ex; stream = Files.newDirectoryStream(file); } catch (IOException ex) { return visitor.visitFileFailed(file, ex);
@Override public synchronized void delete( final Path path, final DeleteOption... options ) throws IllegalArgumentException, NoSuchFileException, DirectoryNotEmptyException, IOException, SecurityException { Files.delete( path, options ); try { Files.deleteIfExists( dot( path ), options ); } catch ( Exception ex ) { } if ( path instanceof AttrHolder ) { ( (AttrHolder) path ).getAttrStorage().clear(); } }
@Override public void delete( final Path path, final DeleteOption... options ) throws IllegalArgumentException, NoSuchFileException, DirectoryNotEmptyException, IOException, SecurityException { Files.delete( path, options ); }
@Override public Path createTempDirectory( final String prefix, final FileAttribute<?>... attrs ) throws IllegalArgumentException, UnsupportedOperationException, IOException, SecurityException { return Files.createTempDirectory( prefix, attrs ); }
@Override public Path createDirectory( final Path dir, final FileAttribute<?>... attrs ) throws IllegalArgumentException, UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException { return Files.createDirectory( dir, attrs ); }
@Override public Path createTempFile( final Path dir, final String prefix, final String suffix, final FileAttribute<?>... attrs ) throws IllegalArgumentException, UnsupportedOperationException, IOException, SecurityException { return Files.createTempFile( dir, prefix, suffix, attrs ); }