List of usage examples for java.nio.file FileSystems getDefault
public static FileSystem getDefault()
From source file:com.geewhiz.pacify.utils.ArchiveUtils.java
private static Boolean matches(String pathName, String regEx) { Path path = FileSystems.getDefault().getPath(pathName); return FileUtils.matches(path, regEx); }
From source file:org.artifactory.security.crypto.CryptoHelper.java
public static void checkPermissionsOnSecurityFolder(File securityFolder) throws IOException { if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) { Set<PosixFilePermission> filePermissions = Files.getPosixFilePermissions(securityFolder.toPath()); if (filePermissions.contains(PosixFilePermission.GROUP_READ) || filePermissions.contains(PosixFilePermission.OTHERS_READ)) { throw new RuntimeException("The folder containing the key file " + securityFolder.getAbsolutePath() + " has too broad permissions!\n" + "Please limit access to the Artifactory user only!"); }/* w ww . j a va2s. c o m*/ } }
From source file:com.datafibers.kafka.connect.FileGenericSourceTask.java
/** * Looks for files that meet the glob criteria. If any found they will be added to the list of * files to be processed/*www . jav a 2 s . co m*/ */ private void findMatch() { final PathMatcher globMatcher = FileSystems.getDefault().getPathMatcher("glob:".concat(glob)); try { Files.walkFileTree(Paths.get(location), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attributes) throws IOException { if (globMatcher.matches(path)) { if (!processedPaths.contains(path)) { inProgressPaths.add(path); } } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException e) throws IOException { return FileVisitResult.CONTINUE; } }); } catch (IOException e) { e.printStackTrace(); } }
From source file:net.solarnetwork.node.setup.s3.S3SetupManager.java
private Set<Path> applySetupSyncPaths(S3SetupConfiguration config, Set<Path> installedFiles) throws IOException { if (config.getSyncPaths() == null || config.getSyncPaths().length < 1) { return Collections.emptySet(); }//www.j av a 2s. c o m Map<String, ?> sysProps = getPathTemplateVariables(); Set<Path> deleted = new LinkedHashSet<>(); for (String syncPath : config.getSyncPaths()) { syncPath = StringUtils.expandTemplateString(syncPath, sysProps); Path path = FileSystems.getDefault().getPath(syncPath).toAbsolutePath().normalize(); Set<Path> result = applySetupSyncPath(path, installedFiles); deleted.addAll(result); } if (!deleted.isEmpty()) { log.info("Deleted files from syncPaths {}: {}", Arrays.asList(config.getSyncPaths()), deleted); } return deleted; }
From source file:com.ethercamp.harmony.service.BlockchainInfoService.java
/** * Get free space of disk where project located. * Verified on multi disk Windows./*from ww w .j a v a 2s . c om*/ * Not tested against sym links */ private long getFreeDiskSpace() { final File currentDir = new File("."); for (Path root : FileSystems.getDefault().getRootDirectories()) { // log.debug(root.toAbsolutePath() + " vs current " + currentDir.getAbsolutePath()); try { final FileStore store = Files.getFileStore(root); final boolean isCurrentDirBelongsToRoot = Paths.get(currentDir.getAbsolutePath()) .startsWith(root.toAbsolutePath()); if (isCurrentDirBelongsToRoot) { final long usableSpace = store.getUsableSpace(); // log.debug("Disk available:" + readableFileSize(usableSpace) // + ", total:" + readableFileSize(store.getTotalSpace())); return usableSpace; } } catch (IOException e) { log.error("Problem querying space: " + e.toString()); } } return 0; }
From source file:femr.business.services.PhotoService.java
private void saveNewEncounterImage(FilePart image, PatientEncounterItem patientEncounter, String descriptionText) { try {/*from w ww .j a va 2 s.c om*/ String imageFileName; //Create photo record: IPhoto pPhoto = new Photo(); pPhoto.setDescription(descriptionText); pPhoto.setFilePath(""); pPhoto = patientPhotoRepository.create(pPhoto); ExpressionList<Photo> findPhotoQuery = QueryProvider.getPhotoQuery().where().eq("id", pPhoto.getId()); IPhoto editPhoto = patientPhotoRepository.findOne(findPhotoQuery); imageFileName = "Patient_" + patientEncounter.getPatientId() + "_Enc_" + patientEncounter.getId() + "_Photo_" + editPhoto.getId(); editPhoto.setFilePath(imageFileName); //Since the record ID is part of the file name // I am setting the filePath field after the record is created patientPhotoRepository.update(editPhoto); //Link photo record in photoEncounter table IPatientEncounterPhoto pep = new PatientEncounterPhoto(); pep.setPhotoId(editPhoto.getId()); pep.setPatientEncounterId(patientEncounter.getId()); patientEncounterPhotoRepository.create(pep); //Save image to disk Path src = FileSystems.getDefault().getPath(image.getFile().getAbsolutePath()); Path dest = FileSystems.getDefault().getPath(this._encounterPhotoPath + imageFileName); java.nio.file.Files.move(src, dest, StandardCopyOption.ATOMIC_MOVE); } catch (Exception ex) { String test = "uh oh"; } }
From source file:org.kitodo.serviceloader.KitodoServiceLoader.java
/** * Loads jars from the pluginsFolder to the classpath, so the ServiceLoader * can find them.//w w w . j a v a2 s.c o m */ private void loadModulesIntoClasspath() { Path moduleFolder = FileSystems.getDefault().getPath(modulePath); URLClassLoader sysLoader; try (DirectoryStream<Path> stream = Files.newDirectoryStream(moduleFolder, JAR)) { for (Path f : stream) { File loc = new File(f.toString()); sysLoader = (URLClassLoader) this.getClass().getClassLoader(); ArrayList<URL> urls = new ArrayList<>(Arrays.asList(sysLoader.getURLs())); URL udir = loc.toURI().toURL(); if (!urls.contains(udir)) { Class<URLClassLoader> sysClass = URLClassLoader.class; Method method = sysClass.getDeclaredMethod("addURL", URL.class); method.setAccessible(true); method.invoke(sysLoader, udir); } } } catch (IOException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { logger.error(ERROR, e.getMessage()); } }
From source file:org.artifactory.security.crypto.CryptoHelper.java
public static void setPermissionsOnSecurityFolder(File securityFolder) throws IOException { // The security folder should accessible only by the owner if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) { Files.setPosixFilePermissions(securityFolder.toPath(), EnumSet.of(PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_READ)); }/* w w w . java2 s. c o m*/ }
From source file:edu.vt.vbi.patric.cache.DataLandingGenerator.java
public boolean createCacheFileAntibioticResistanceGenes(String filePath) { boolean isSuccess = false; JSONObject jsonData = new JSONObject(); JSONObject data;/*from w w w .j a v a2s.c om*/ // from WP // data data = read(baseURL + "/tab/dlp-antibioticresistance-data/?req=passphrase"); if (data != null) { jsonData.put("data", data); } // popular genomes data = this.getPopularGenomesForAntibioticResistanceGene(); if (data != null) { jsonData.put("popularGenomes", data); } // tools data = read(baseURL + "/tab/dlp-antibioticresistance-tools/?req=passphrase"); if (data != null) { jsonData.put("tools", data); } // process data = read(baseURL + "/tab/dlp-antibioticresistance-process/?req=passphrase"); if (data != null) { jsonData.put("process", data); } // download data = read(baseURL + "/tab/dlp-antibioticresistance-download/?req=passphrase"); if (data != null) { jsonData.put("download", data); } // save jsonData to file try (PrintWriter jsonOut = new PrintWriter( Files.newBufferedWriter(FileSystems.getDefault().getPath(filePath), Charset.defaultCharset()));) { jsonData.writeJSONString(jsonOut); isSuccess = true; } catch (IOException e) { LOGGER.error(e.getMessage(), e); } return isSuccess; }
From source file:org.apache.coheigea.bigdata.knox.ranger.KnoxRangerTest.java
private void makeSolrInvocation(int statusCode, String user, String password) throws IOException { String basedir = System.getProperty("basedir"); if (basedir == null) { basedir = new File(".").getCanonicalPath(); }/* www. jav a 2s .co m*/ Path path = FileSystems.getDefault().getPath(basedir, "/src/test/resources/query_response.xml"); solrServer.expect().method("GET").pathInfo("/solr/gettingstarted/select") .queryParam("q", "author_s:William+Shakespeare").respond().status(HttpStatus.SC_OK) .content(IOUtils.toByteArray(path.toUri())).contentType("application/json"); given().auth().preemptive().basic(user, password).header("X-XSRF-Header", "jksdhfkhdsf") .header("Accept", "application/json").when() .get("http://localhost:" + gateway.getAddresses()[0].getPort() + "/gateway/cluster/solr" + "/gettingstarted/select?q=author_s:William+Shakespeare") .then().log().all().statusCode(statusCode); }