Refine search
private void repositoryWriter(String content, Path filePath) { if(Files.exists(filePath) && !Files.isWritable(filePath)){ log.error("Error file is not writable: " + filePath); return; } if(Files.notExists(filePath.getParent())) { try { Files.createDirectories(filePath.getParent()); } catch (IOException e) { log.error("Error creating the directory: " + filePath + " message: " + e.getMessage(), e); } } try { Path target = null; if(Files.exists(filePath)) { target = FileSystems.getDefault().getPath(filePath.getParent().toString(), "group.db.old"); Files.move(filePath, target); } Files.write(filePath, content.getBytes(), StandardOpenOption.CREATE); if(target != null) Files.delete(target); } catch (IOException e) { log.error("Error writing the file: " + filePath + " message: " + e.getMessage(), e); } }
URI archiveAbsoluteURI = URI.create( "jar:file:" + destinationZip.toURI().getRawPath() ); try ( FileSystem zipFs = FileSystems.newFileSystem( archiveAbsoluteURI, env ) ) Path zipFsPath = fileSystem.isDirectory( sourceToCompress ) ? zipFs.getPath( rootPath.relativize( sourcePath ).toString() ) : zipFs.getPath( sourcePath.getFileName().toString() ); if ( zipFsPath.getParent() != null ) Files.createDirectories( zipFsPath.getParent() ); Files.copy( sourcePath, zipFsPath );
synchronized (this) { if (uri.getScheme().equals("jar")) { FileSystem fileSystem = null; try { try { fileSystem = FileSystems.getFileSystem(uri); } catch (FileSystemNotFoundException e) { fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap(), classLoader); pathObject = fileSystem.getPath(path); return pathObject == null || Files.isDirectory(pathObject); } finally { if (fileSystem != null && fileSystem.isOpen()) { try { fileSystem.close(); } catch (IOException e) { if (LOG.isDebugEnabled()) { } else if (uri.getScheme().equals("file")) { pathObject = Paths.get(uri); return pathObject == null || Files.isDirectory(pathObject);
@Override public FileSystem load(@Nonnull URI key) throws Exception { try { return FileSystems.getFileSystem(key); } catch (FileSystemNotFoundException e) { try { return FileSystems.newFileSystem(key, Collections.emptyMap()); } catch (FileSystemAlreadyExistsException f) { return FileSystems.getFileSystem(key); } } } });
private void initFileSystem(URI uri) throws IOException { try { FileSystems.getFileSystem(uri); } catch (FileSystemNotFoundException e) { FileSystems.newFileSystem(uri, Collections.emptyMap()); } catch (IllegalArgumentException e) { FileSystems.getDefault(); } }
/** * Returns a zip file system * @param zipFilename to construct the file system from * @param create true if the zip file should be created * @return a zip file system * @throws IOException */ private static FileSystem createZipFileSystem(String zipFilename, boolean create) throws IOException { // convert the filename to a URI final Path path = Paths.get(zipFilename); if(Files.notExists(path.getParent())) { Files.createDirectories(path.getParent()); } final URI uri = URI.create("jar:file:" + path.toUri().getPath()); final Map<String, String> env = new HashMap<>(); if (create) { env.put("create", "true"); } return FileSystems.newFileSystem(uri, env); }
public JrtfsCodeBase(ICodeBaseLocator codeBaseLocator, @Nonnull String fileName) { super(codeBaseLocator); this.fileName = fileName; URL url; try { url = Paths.get(fileName).toUri().toURL(); URLClassLoader loader = new URLClassLoader(new URL[] { url }); fs = FileSystems.newFileSystem(URI.create("jrt:/"), Collections.emptyMap(), loader); root = fs.getPath("modules"); packageToModuleMap = createPackageToModuleMap(fs); } catch (IOException e) { e.printStackTrace(); } }
protected String readSchemaFileAsString(String filePath) throws IOException { try { URI uri = this.getClass().getClassLoader().getResource(filePath).toURI(); String[] array = uri.toString().split("!"); Path path; if (array.length > 1) { LOG.info("Creating fs for {}", array[0]); FileSystem fs; try { fs = FileSystems.newFileSystem(URI.create(array[0]), new HashMap<String, String>()); } catch (FileSystemAlreadyExistsException e) { fs = FileSystems.getFileSystem(URI.create(array[0])); } path = fs.getPath(array[1]); } else { path = Paths.get(uri); } return new String(Files.readAllBytes(path)); } catch (URISyntaxException e) { LOG.error("Can't generate configs {}", e); } return null; }
Path destinationFolder = destination.getParent(); Files.createDirectories( destinationFolder ); URI uri = URI.create("jar:file:" + destination.toAbsolutePath().toUri().getRawPath() ); try ( FileSystem fs = FileSystems.newFileSystem( uri, env ) ) Path path = fs.getPath( source.destinationPath() ); if ( path.getParent() != null ) Files.createDirectories( path.getParent() );
try Path path = Paths.get(suspendFileFolderPath); watchService = FileSystems.getDefault().newWatchService(); path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE); } catch (IOException e1)
private static void updateZip(File zip, File entry, String entryName) throws IOException { Map<String, String> env = new HashMap<>(); String uriPath = "jar:" + zip.toURI().toString(); URI uri = URI.create(uriPath); try (FileSystem fs = FileSystems.newFileSystem(uri, env)) { fs.provider().checkAccess(fs.getPath(entryName), AccessMode.READ); Path target = fs.getPath(entryName); Path source = entry.toPath(); Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { throw e; } }
Path path = FileSystems.getDefault().getPath(userDir, "target", "classes"); if (Files.exists(path)){ cp.add(path.toString()); path = FileSystems.getDefault().getPath(userDir, "build", "classes","java", "main"); if (Files.exists(path)){ cp.add(path.toString()); File libDir = Paths.get(userDir, "../lib").toFile();
public String[] list(String subFolder) throws IOException { if(dir == null) { Path subFolderPath = path.resolve(subFolder); if(subFolder == null || !Files.isDirectory(subFolderPath)) { return null; } return subFolderPath.toFile().list(); } return dir.list(Paths.get(path.toString(),subFolder).toString().replace(FileSystems.getDefault().getSeparator(),separator)); }
Files.createFile( testDirectory.file( "neo4j.conf" ).toPath() ); Files.write( Paths.get( run.getAbsolutePath(), "neo4j.pid" ), String.valueOf( pid ).getBytes() ); final URI uri = URI.create( "jar:file:" + report.toUri().getRawPath() ); try ( FileSystem fs = FileSystems.newFileSystem( uri, Collections.emptyMap() ) ) String threadDump = new String( Files.readAllBytes( fs.getPath( "threaddump.txt" ) ) ); assertThat( threadDump, containsString( DiagnosticsReportCommandIT.class.getCanonicalName() ) );
if (location.getScheme().equals("jar")) { try { fileSystem = FileSystems.getFileSystem(location); } catch (FileSystemNotFoundException e) { fileSystem = FileSystems.newFileSystem(location, Collections.<String, String>emptyMap()); myPath = fileSystem.getPath(dir); } else { myPath = Paths.get(location); Stream<Path> files = Files.walk(myPath, 1); for (Path path : (Iterable<Path>) () -> files.iterator()) { System.out.println(path); final String name = path.getFileName().toString(); File fwConfig = new File(firmwareConfig, name); if (name.endsWith(".json")) { boolean copyFile = !fwConfig.exists(); ControllerSettings jarSetting = getSettingsForStream(Files.newInputStream(path)); if (fileSystem != null) { try { fileSystem.close(); } catch (IOException ex) { logger.log(Level.SEVERE, "Problem closing filesystem.", ex);
if (uri.getScheme().equals("jar")) { fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap()); myPath = fileSystem.getPath("/" + path); } else { myPath = Paths.get(uri); return Files.walk(myPath, 1).flatMap(next -> { if (next.equals(myPath)) { return Stream.of(); return Stream.of(CharMatcher.is('/').trimFrom(next.getFileName().toString())); }).collect(Collectors.toList()); } finally { if (fileSystem != null) { fileSystem.close(); } finally { if (fileSystem != null) { fileSystem.close();
try { Path filePath = FileSystems.getDefault().getPath(resourcePath).toAbsolutePath(); File f = filePath.toFile(); if (f.exists() && f.isFile() && f.canRead()) { result = new BufferedInputStream(new FileInputStream(f)); try { Path current = FileSystems.getDefault().getPath(".").toAbsolutePath(); Path absolute = current.resolve(Paths.get(resourcePath)).toAbsolutePath(); File f = absolute.toFile(); if (f.exists() && f.isFile() && f.canRead()) {
Path child = dir.resolve(name); if(kind.equals(ENTRY_CREATE)){ if (Files.isDirectory(child, NOFOLLOW_LINKS)) { registerAll(child); continue; if(!fileProcessingQueue.offer(child.toString())){ Path dir = Paths.get(dirName); final WatchDir watchDir = new WatchDir(dir, recursive); watchDir.closeProcessingThread = false; WatchKey key = dir.register(watcher, ENTRY_CREATE); if (trace) { Path prev = keys.get(key); Files.walkFileTree(start, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { fileProcessingQueue = new ArrayBlockingQueue<String>(WatchDirParameters.fileQueueSize, false); processedFileQueue = new ArrayBlockingQueue<String>(WatchDirParameters.fileQueueSize, false); this.watcher = FileSystems.getDefault().newWatchService(); this.keys = new HashMap<WatchKey,Path>(); this.recursive = recursive;
private void addDetails() throws IOException { Path path = Paths.get(this.path); this.absolutePath = path.toAbsolutePath().toString().replace('\\', '/'); if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) { PosixFileAttributes attrs = Files.getFileAttributeView(path, PosixFileAttributeView.class).readAttributes(); permissions = PosixFilePermissions.toString(attrs.permissions()); UserPrincipal ownerPrincipal = attrs.owner(); owner = ownerPrincipal.toString(); UserPrincipal groupPrincipal = attrs.group(); group = groupPrincipal.toString(); size = path.toFile().length(); numLinks = path.toFile().list().length + 2; } }
@Override public String toString(final Object obj) { final Path path = (Path)obj; if (path.getFileSystem() == FileSystems.getDefault()) { final String localPath = path.toString(); if (File.separatorChar != '/') { return localPath.replace(File.separatorChar, '/'); } else { return localPath; } } else { return path.toUri().toString(); } } }