List of usage examples for java.nio.file FileSystems getDefault
public static FileSystem getDefault()
From source file:org.kitodo.serviceloader.KitodoServiceLoader.java
/** * If the found jar files have frontend files, they will be extracted and * copied into the frontend folder of the core module. Before copying, * existing frontend files of the same module will be deleted from the core * module. Afterwards the created temporary folder will be deleted as well. *//*from ww w . j a v a 2 s . c o m*/ private void loadFrontendFilesIntoCore() { Path moduleFolder = FileSystems.getDefault().getPath(modulePath); try (DirectoryStream<Path> stream = Files.newDirectoryStream(moduleFolder, JAR)) { for (Path f : stream) { File loc = new File(f.toString()); try (JarFile jarFile = new JarFile(loc)) { if (hasFrontendFiles(jarFile)) { Path temporaryFolder = Files.createTempDirectory(SYSTEM_TEMP_FOLDER, TEMP_DIR_PREFIX); File tempDir = new File(Paths.get(temporaryFolder.toUri()).toAbsolutePath().toString()); extractFrontEndFiles(loc.getAbsolutePath(), tempDir); String moduleName = extractModuleName(tempDir); if (!moduleName.isEmpty()) { FacesContext facesContext = FacesContext.getCurrentInstance(); HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false); String filePath = session.getServletContext().getRealPath(File.separator + PAGES_FOLDER) + File.separator + moduleName; FileUtils.deleteDirectory(new File(filePath)); String resourceFolder = String.join(File.separator, Arrays.asList(tempDir.getAbsolutePath(), META_INF_FOLDER, RESOURCES_FOLDER)); copyFrontEndFiles(resourceFolder, filePath); } else { logger.info("No module found in JarFile '" + jarFile.getName() + "'."); } FileUtils.deleteDirectory(tempDir); } } } } catch (Exception e) { logger.error(ERROR, e.getMessage()); } }
From source file:edu.wpi.checksims.submission.Submission.java
/** * Identify all files matching in a single directory. * * @param directory Directory to find files within * @param glob Match pattern used to identify files to include * @return Array of files which match in this single directory *//* w w w . j a v a2 s .c om*/ static File[] getMatchingFilesFromDir(File directory, String glob) throws NoSuchFileException, NotDirectoryException { checkNotNull(directory); checkNotNull(glob); checkArgument(!glob.isEmpty(), "Glob pattern cannot be empty"); PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + glob); if (!directory.exists()) { throw new NoSuchFileException("Does not exist: " + directory.getAbsolutePath()); } else if (!directory.isDirectory()) { throw new NotDirectoryException("Not a directory: " + directory.getAbsolutePath()); } return directory.listFiles((f) -> matcher.matches(Paths.get(f.getAbsolutePath()).getFileName())); }
From source file:com.ccserver.digital.controller.AdminControllerTest.java
@Test public void downloadApplicationNullDocument() throws IOException { CreditCardApplicationDTO ccApp = getCreditCardApplicationDTOMock(1L); ccApp.setApplicationLOS(null);//from w w w . jav a2s . c o m Mockito.when(ccAppService.getApplication(1L)).thenReturn(ccApp); File ifile = new File("./src/main/resources/sample"); Path idDocPath = FileSystems.getDefault().getPath(ifile.getAbsolutePath(), "IdDoc.pdf"); byte[] idDocByteArray = Files.readAllBytes(idDocPath); Map<String, byte[]> docs = new HashMap<String, byte[]>(); docs.put("abc", idDocByteArray); Map<String, byte[]> doc = new HashMap<String, byte[]>(); Mockito.when(docsService.getFullDocumentsByApplicationId(1L)).thenReturn(doc); Mockito.when(response.getOutputStream()).thenReturn(servletOutputStream); Mockito.when(zipFileService.zipIt(docs)).thenReturn(idDocByteArray); // when ResponseEntity<?> application = controller.downloadApplication(1L, response); // then Assert.assertEquals(HttpStatus.BAD_REQUEST, application.getStatusCode()); Assert.assertEquals(Constants.APPLICATION_DETAIL_OBJECT_REQUIRED, ((ErrorObject) application.getBody()).getId()); }
From source file:gobblin.scheduler.JobScheduler.java
public JobScheduler(Properties properties, SchedulerService scheduler) throws Exception { this.properties = properties; this.scheduler = scheduler; this.jobExecutor = Executors.newFixedThreadPool( Integer.parseInt(properties.getProperty(ConfigurationKeys.JOB_EXECUTOR_THREAD_POOL_SIZE_KEY, Integer.toString(ConfigurationKeys.DEFAULT_JOB_EXECUTOR_THREAD_POOL_SIZE))), ExecutorsUtils.newThreadFactory(Optional.of(LOG), Optional.of("JobScheduler-%d"))); this.jobConfigFileExtensions = Sets.newHashSet(Splitter.on(",").omitEmptyStrings() .split(this.properties.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_EXTENSIONS_KEY, ConfigurationKeys.DEFAULT_JOB_CONFIG_FILE_EXTENSIONS))); long pollingInterval = Long.parseLong( this.properties.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_MONITOR_POLLING_INTERVAL_KEY, Long.toString(ConfigurationKeys.DEFAULT_JOB_CONFIG_FILE_MONITOR_POLLING_INTERVAL))); this.pathAlterationDetector = new PathAlterationObserverScheduler(pollingInterval); this.waitForJobCompletion = Boolean .parseBoolean(this.properties.getProperty(ConfigurationKeys.SCHEDULER_WAIT_FOR_JOB_COMPLETION_KEY, ConfigurationKeys.DEFAULT_SCHEDULER_WAIT_FOR_JOB_COMPLETION)); if (this.properties.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY) && !this.properties.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY)) { String path = FileSystems.getDefault() .getPath(this.properties.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY)).normalize() .toAbsolutePath().toString(); this.properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY, "file:///" + path); }/* w w w . ja v a 2s. co m*/ if (this.properties.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY)) { this.jobConfigFileDirPath = new Path( this.properties.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY)); this.listener = new PathAlterationListenerAdaptorForMonitor(jobConfigFileDirPath, this); } else { // This is needed because HelixJobScheduler does not use the same way of finding changed paths this.jobConfigFileDirPath = null; this.listener = null; } }
From source file:cpd3314.project.CPD3314ProjectTest.java
@Test public void testFormatSQL() throws Exception { System.out.println("main"); String[] args = { "-format=SQL" }; CPD3314Project.main(args);//from w ww. j av a2 s . c o m File expected = FileSystems.getDefault().getPath("testFiles", "formatSQL.sql").toFile(); File result = new File("CPD3314.sql"); assertTrue("Output File Doesn't Exist", result.exists()); assertFilesEqual(expected, result); }
From source file:com.twosigma.beaker.core.rest.FileIORest.java
@POST @Consumes("application/x-www-form-urlencoded") @Path("setPosixFileOwnerAndPermissions") @Produces(MediaType.TEXT_PLAIN)/*from w ww. j a va 2 s. c o m*/ public Response setPosixFilePermissions(@FormParam("path") String pathString, @FormParam("owner") String owner, @FormParam("group") String group, @FormParam("permissions[]") List<String> permissions) throws IOException { HashSet<PosixFilePermission> filePermissions = getPosixFilePermissions(permissions); try { java.nio.file.Path path = Paths.get(pathString); Files.setPosixFilePermissions(path, filePermissions); UserPrincipalLookupService userPrincipalLookupService = FileSystems.getDefault() .getUserPrincipalLookupService(); if (StringUtils.isNoneBlank(owner)) { Files.setOwner(path, userPrincipalLookupService.lookupPrincipalByName(owner)); } if (StringUtils.isNoneBlank(group)) { Files.getFileAttributeView(path, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS) .setGroup(userPrincipalLookupService.lookupPrincipalByGroupName(group)); } return status(OK).build(); } catch (FileSystemException e) { return status(INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); } }
From source file:com.twosigma.beaker.scala.util.ScalaEvaluator.java
public void setShellOptions(String cp, String in, String od) throws IOException { if (od == null || od.isEmpty()) { od = FileSystems.getDefault().getPath(System.getenv("beaker_tmp_dir"), "dynclasses", sessionId) .toString();/* w w w . j a va 2 s .com*/ } else { od = od.replace("$BEAKERDIR", System.getenv("beaker_tmp_dir")); } // check if we are not changing anything if (currentClassPath.equals(cp) && currentImports.equals(in) && outDir.equals(od)) return; currentClassPath = cp; currentImports = in; outDir = od; if (cp == null || cp.isEmpty()) classPath = new ArrayList<String>(); else classPath = Arrays.asList(cp.split("[\\s" + File.pathSeparatorChar + "]+")); if (imports == null || in.isEmpty()) imports = new ArrayList<String>(); else imports = Arrays.asList(in.split("\\s+")); try { (new File(outDir)).mkdirs(); } catch (Exception e) { } resetEnvironment(); }
From source file:com.liferay.sync.engine.service.persistence.SyncFilePersistence.java
public List<SyncFile> findByPF_L(String parentFilePathName, long localSyncTime) throws SQLException { QueryBuilder<SyncFile, Long> queryBuilder = queryBuilder(); Where<SyncFile, Long> where = queryBuilder.where(); FileSystem fileSystem = FileSystems.getDefault(); parentFilePathName = StringUtils.replace(parentFilePathName + fileSystem.getSeparator(), "\\", "\\\\"); where.like("filePathName", new SelectArg(parentFilePathName + "%")); where.lt("localSyncTime", localSyncTime); where.or(where.eq("state", SyncFile.STATE_SYNCED), where.eq("uiEvent", SyncFile.UI_EVENT_UPLOADING)); where.ne("type", SyncFile.TYPE_SYSTEM); where.and(4);//from w ww. j a v a2 s. co m return where.query(); }
From source file:com.oneops.util.SearchSenderTest.java
private boolean isRetryDirectoryEmpty() { DirectoryStream<Path> dirStream = null; try {//from ww w .j a va2 s. co m Path retryPath = FileSystems.getDefault().getPath(retryDir); dirStream = java.nio.file.Files.newDirectoryStream(retryPath); return !dirStream.iterator().hasNext(); } catch (IOException e) { e.printStackTrace(); } finally { try { dirStream.close(); } catch (IOException e) { e.printStackTrace(); } } return true; }
From source file:io.stallion.assets.AssetsController.java
public Long getTimeStampForAssetFile(String path) { String filePath = Context.settings().getTargetFolder() + "/assets/" + path; if (getTimeStampByPath().containsKey(filePath)) { Long ts = getTimeStampByPath().get(filePath); if (ts > 0) { return ts; }//from w ww . ja v a2 s . c o m } Path pathObj = FileSystems.getDefault().getPath(filePath); File file = new File(filePath); Long ts = file.lastModified(); getTimeStampByPath().put(filePath, ts); return ts; }