@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Path relativePath = oldApkPath.relativize(file); Path newPath = newApkPath.resolve(relativePath); String patternKey = relativePath.toString().replace("\\", "/"); if (Utils.checkFileInPattern(config.mResFilePattern, patternKey)) { //not contain in new path, is deleted if (!newPath.toFile().exists()) { deletedFiles.add(patternKey); writeResLog(newPath.toFile(), file.toFile(), TypedValue.DEL); } return FileVisitResult.CONTINUE; } return FileVisitResult.CONTINUE; } }
public static void writePluginServices(Iterable<String> plugins, File root) throws IOException { Path path = root.toPath().resolve(SERVICES_FILE); createDirectories(path.getParent()); try (Writer out = new OutputStreamWriter(new FileOutputStream(path.toFile()), UTF_8)) { for (String plugin : plugins) { out.write(plugin + "\n"); } } }
public JavapProcess() throws FileNotFoundException { super(); Path javaHome = Paths.get(System.getProperty("java.home")); executablePath = Paths.get(javaHome.toString(), "..", "bin", EXECUTABLE_NAME); if (!executablePath.toFile().exists()) { executablePath = Paths.get(javaHome.toString(), "bin", EXECUTABLE_NAME); if (!executablePath.toFile().exists()) { throw new FileNotFoundException("Could not find " + EXECUTABLE_NAME); } } executablePath = executablePath.normalize(); }
@Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Path relative = sourcePath.relativize(dir); Path target = targetPath.resolve(relative); File folder = target.toFile(); if (!folder.exists()) { mkdirs(folder); } return FileVisitResult.CONTINUE; }
@Override public File resolve(final CacheDescriptor item) { String version = item.getVersion() .replace("^", "") .replace("v", ""); String classifier = Optional.ofNullable(item.getClassifier()) .map(it -> "-" + it) .orElse(""); Path artifactId = Paths.get(item.getName()).resolve(version) .resolve(item.getName() + "-" + version + classifier + "." + item.getExtension()); return repository.resolve(groupId).resolve(artifactId).toAbsolutePath().toFile(); } }
private static void updateBallerinaPathModificationTracker(Project project, ProjectStatus status) { String balSdkPath = getBallerinaSdk(project); if (balSdkPath != null) { Path balxPath = Paths.get(balSdkPath, ballerinaSourcePath); if (balxPath.toFile().isDirectory()) { if (status == ProjectStatus.OPENED) { BallerinaPathModificationTracker.addPath(balxPath.toString()); } else if (status == ProjectStatus.CLOSED) { BallerinaPathModificationTracker.removePath(balxPath.toString()); } } } }
@Override public File[] listFiles( File directory, final FilenameFilter filter ) { try ( Stream<Path> listing = Files.list( path( directory ) ) ) { return listing .filter( entry -> filter.accept( entry.getParent().toFile(), entry.getFileName().toString() ) ) .map( Path::toFile ) .toArray( File[]::new ); } catch ( IOException e ) { return null; } }
private Path createDownloadDir(String workDir, String fileUrl) { Path downloadDirPath = Paths.get(workDir, DOWNLOAD_DIR); File downloadDirFile = downloadDirPath.toFile(); try { Log.info(String.format("Creating download dir %s", downloadDirFile.toPath().toString())); FileUtils.forceMkdir(downloadDirFile); } catch (IOException e) { throw new RuntimeException(String .format("Unable to create download location for archive: %s at %s", fileUrl, downloadDirPath.toString())); } Log.info(String.format("Created download dir %s", downloadDirFile.toPath().toString())); return downloadDirPath; }
public boolean tryLock() { try { lockRandomAccessFile = new RandomAccessFile(lockFilePath.toFile(), "rw"); lockChannel = lockRandomAccessFile.getChannel(); lockFile = lockChannel.tryLock(0, 1024, false); return lockFile != null; } catch (IOException e) { throw new IllegalStateException("Failed to create lock in " + lockFilePath.toString(), e); } }
@Test public void testMoveForgottenFiles() { Collection<File> files = allFiles.stream().map(Path::toFile).collect(Collectors.toList()); forgottenFilesManager.moveForgottenFiles( new File(configuration.getDataFileLocation()), files); Path lostFoundDir = Paths.get(configuration.getDataFileLocation(), forgottenFilesManager.LOST_FOUND); Collection<File> movedFiles = FileUtils.listFiles(lostFoundDir.toFile(), null, false); Assert.assertEquals(allFiles.size(), movedFiles.size()); for (Path file : allFiles) Assert.assertTrue( movedFiles.contains( Paths.get(lostFoundDir.toString(), file.getFileName().toString()) .toFile())); }
private Optional<Long> getPid() { Path pidFile = this.homeDir.resolve( "run/neo4j.pid" ); if ( this.fs.fileExists( pidFile.toFile() ) ) { // The file cannot be opened with write permissions on Windows try ( InputStream inputStream = Files.newInputStream( pidFile, StandardOpenOption.READ ); BufferedReader reader = new BufferedReader( new InputStreamReader( inputStream ) ) ) { String pidFileContent = reader.readLine(); try { return Optional.of( Long.parseLong( pidFileContent ) ); } catch ( NumberFormatException e ) { printError( pidFile.toString() + " does not contain a valid id. Found: " + pidFileContent ); } } catch ( IOException e ) { printError( "Error reading the .pid file. Reason: " + e.getMessage(), e ); } } return Optional.empty(); } }
private String createClassOutsideClasspath(String className) throws Exception { File dir = Files.createTempDirectory("vertx").toFile(); dir.deleteOnExit(); File source = new File(dir, className + ".java"); Files.write(source.toPath(), ("public class " + className + " extends io.vertx.core.AbstractVerticle {} ").getBytes()); URLClassLoader loader = new URLClassLoader(new URL[]{dir.toURI().toURL()}, Thread.currentThread().getContextClassLoader()); CompilingClassLoader compilingClassLoader = new CompilingClassLoader(loader, className + ".java"); compilingClassLoader.loadClass(className); byte[] bytes = compilingClassLoader.getClassBytes(className); assertNotNull(bytes); File classFile = new File(dir, className + ".class"); Files.write(classFile.toPath(), bytes); return dir.getAbsolutePath(); }
private void readVersion() throws IOException { Path versionFile = topologyBasicBlobsRootDir.resolve(type.getVersionFileName()); if (!fsOps.fileExists(versionFile)) { version = NOT_DOWNLOADED_VERSION; } else { String ver = FileUtils.readFileToString(versionFile.toFile(), "UTF8").trim(); version = Long.parseLong(ver); } }
public JavapProcess() throws FileNotFoundException { super(); Path javaHome = Paths.get(System.getProperty("java.home")); executablePath = Paths.get(javaHome.toString(), "..", "bin", EXECUTABLE_NAME); if (!executablePath.toFile().exists()) { executablePath = Paths.get(javaHome.toString(), "bin", EXECUTABLE_NAME); if (!executablePath.toFile().exists()) { throw new FileNotFoundException("Could not find " + EXECUTABLE_NAME); } } executablePath = executablePath.normalize(); }