List of usage examples for java.nio.file Path equals
boolean equals(Object other);
From source file:playRepository.GitRepository.java
/** * Clones a local repository.//ww w .j a va 2s.c o m * * This doesn't copy Git objects but hardlink them to save disk space. * * @param originalProject * @param forkProject * @throws IOException */ protected static void cloneHardLinkedRepository(Project originalProject, Project forkProject) throws IOException { Repository origin = GitRepository.buildGitRepository(originalProject); Repository forked = GitRepository.buildGitRepository(forkProject); forked.create(); final Path originObjectsPath = Paths.get(new File(origin.getDirectory(), "objects").getAbsolutePath()); final Path forkedObjectsPath = Paths.get(new File(forked.getDirectory(), "objects").getAbsolutePath()); // Hardlink files .git/objects/ directory to save disk space, // but copy .git/info/alternates because the file can be modified. SimpleFileVisitor<Path> visitor = new SimpleFileVisitor<Path>() { public FileVisitResult visitFile(Path file, BasicFileAttributes attr) throws IOException { Path newPath = forkedObjectsPath.resolve(originObjectsPath.relativize(file.toAbsolutePath())); if (file.equals(forkedObjectsPath.resolve("/info/alternates"))) { Files.copy(file, newPath); } else { FileUtils.mkdirs(newPath.getParent().toFile(), true); Files.createLink(newPath, file); } return java.nio.file.FileVisitResult.CONTINUE; } }; Files.walkFileTree(originObjectsPath, visitor); // Import refs. for (Map.Entry<String, Ref> entry : origin.getAllRefs().entrySet()) { RefUpdate updateRef = forked.updateRef(entry.getKey()); Ref ref = entry.getValue(); if (ref.isSymbolic()) { updateRef.link(ref.getTarget().getName()); } else { updateRef.setNewObjectId(ref.getObjectId()); updateRef.update(); } } }
From source file:org.apache.taverna.databundle.TestDataBundles.java
@Test public void getListItemChecksExtension() throws Exception { Path inputs = DataBundles.getInputs(dataBundle); Path portIn1 = DataBundles.getPort(inputs, "in1"); Path list = DataBundles.newListItem(portIn1); Path item = DataBundles.newListItem(list); Path ref = DataBundles.setReference(item, URI.create("http://example.com/")); Path itemAgain = DataBundles.getListItem(list, 0); assertEquals(ref, itemAgain);// w w w. j a va 2 s .c om assertFalse(itemAgain.equals(portIn1)); assertTrue(Files.exists(itemAgain)); }
From source file:org.apache.taverna.databundle.TestDataBundles.java
@Test public void getPortChecksExtension() throws Exception { Path inputs = DataBundles.getInputs(dataBundle); Path portIn1 = DataBundles.getPort(inputs, "in1"); assertFalse(Files.exists(portIn1)); Path ref = DataBundles.setReference(portIn1, URI.create("http://example.com/")); Path portIn1Again = DataBundles.getPort(inputs, "in1"); assertEquals(ref, portIn1Again);/* w ww .j av a 2 s .com*/ assertFalse(portIn1Again.equals(portIn1)); assertTrue(Files.exists(portIn1Again)); }
From source file:codes.thischwa.c5c.DispatcherPUT.java
private void imageProcessingAndSizeCheck(Path tempPath, String sanitizedName, long fileSize, FilemanagerConfig conf) throws C5CException, IOException { Integer maxSize = (conf.getUpload().isFileSizeLimitAuto()) ? PropertiesLoader.getMaxUploadSize() : conf.getUpload().getFileSizeLimit(); if (fileSize > maxSize.longValue() * 1024 * 1024) throw new FilemanagerException(FilemanagerAction.UPLOAD, FilemanagerException.Key.UploadFilesSmallerThan, String.valueOf(maxSize)); String extension = FilenameUtils.getExtension(sanitizedName); // check image only boolean isImageExt = checkImageExtension(sanitizedName, conf.getUpload().isImagesOnly(), conf.getImages().getExtensions()); if (!isImageExt) return;//from w w w. j a v a 2s . co m // remove exif data Path woExifPath = UserObjectProxy.removeExif(tempPath); if (!tempPath.equals(woExifPath)) { Files.move(woExifPath, tempPath, StandardCopyOption.REPLACE_EXISTING); } // check if the file is really an image InputStream in = new BufferedInputStream(Files.newInputStream(tempPath, StandardOpenOption.READ)); Dimension dim = getDimension(in); if (isImageExt && dim == null) throw new FilemanagerException(FilemanagerAction.UPLOAD, FilemanagerException.Key.UploadImagesOnly); IOUtils.closeQuietly(in); // check if resize is enabled and fix it, if necessary Resize resize = conf.getImages().getResize(); if (resize.isEnabled() && (dim.getHeight() > resize.getMaxHeight() || dim.getWidth() > resize.getMaxWidth())) { logger.debug("process resize"); StreamContent sc = connector.resize(new BufferedInputStream(Files.newInputStream(tempPath)), extension, new Dimension(resize.getMaxWidth(), resize.getMaxHeight())); Files.copy(sc.getInputStream(), tempPath, StandardCopyOption.REPLACE_EXISTING); IOUtils.closeQuietly(sc.getInputStream()); } }
From source file:net.pms.configuration.ConfigurableProgramPaths.java
/** * Sets the {@link ProgramExecutableType#CUSTOM} path for the given * {@link ExternalProgramInfo}./* w ww .ja va 2 s. c om*/ * * @param customPath the custom executable {@link Path}. * @param programInfo the {@link ExternalProgramInfo} for which to set the * {@link ProgramExecutableType#CUSTOM} {@link Path}. * @param configurationKey the {@link Configuration} key under which to * store the {@code path}. Cannot be {@code null} if * {@code setConfiguration} is {@code true}. * @param setConfiguration whether or not {@code customPath} should also be * stored in the current {@link Configuration}. */ protected void setCustomProgramPath(@Nullable Path customPath, @Nullable ExternalProgramInfo programInfo, @Nullable String configurationKey, boolean setConfiguration) { if (programInfo == null || configuration == null) { return; } if (setConfiguration && isBlank(configurationKey)) { throw new IllegalArgumentException("configurationKey can't be blank if setConfiguration is true"); } if (setConfiguration) { setCustomProgramPathConfiguration(customPath, configurationKey); } customPath = resolveCustomProgramPath(customPath); ReentrantReadWriteLock lock = programInfo.getLock(); lock.writeLock().lock(); try { if (customPath == null) { if (programInfo.getExecutableInfo(ProgramExecutableType.CUSTOM) != null) { programInfo.setExecutableInfo(ProgramExecutableType.CUSTOM, null); programInfo.setOriginalDefault(); LOGGER.debug("Cleared custom {} path", programInfo.getName()); } } else { ExecutableInfo executableInfo = programInfo.getExecutableInfo(ProgramExecutableType.CUSTOM); if (executableInfo == null || !customPath.equals(executableInfo.getPath())) { programInfo.setPath(ProgramExecutableType.CUSTOM, customPath); programInfo.setDefault(ProgramExecutableType.CUSTOM); LOGGER.debug("Set custom {} path \"{}\"", programInfo.getName(), customPath); } } } finally { lock.writeLock().unlock(); } }
From source file:com.liferay.sync.engine.file.system.SyncWatchEventProcessor.java
protected void addFolder(SyncWatchEvent syncWatchEvent) throws Exception { Path targetFilePath = Paths.get(syncWatchEvent.getFilePathName()); if (sanitizeFileName(targetFilePath) || isInErrorState(targetFilePath)) { return;// w ww . j a v a 2 s . c o m } Path parentTargetFilePath = targetFilePath.getParent(); SyncFile parentSyncFile = SyncFileService.fetchSyncFile(parentTargetFilePath.toString()); if ((parentSyncFile == null) || (!parentSyncFile.isSystem() && (parentSyncFile.getTypePK() == 0))) { queueSyncWatchEvent(parentTargetFilePath.toString(), syncWatchEvent); return; } SyncFile syncFile = SyncFileService.fetchSyncFile(targetFilePath.toString()); if (syncFile == null) { syncFile = SyncFileService.fetchSyncFile(FileKeyUtil.getFileKey(targetFilePath)); if (!verifySite(syncFile, parentSyncFile)) { syncFile = null; } } if (syncFile == null) { SyncFileService.addFolderSyncFile(targetFilePath, parentSyncFile.getTypePK(), parentSyncFile.getRepositoryId(), _syncAccountId); return; } Path sourceFilePath = Paths.get(syncFile.getFilePathName()); if (targetFilePath.equals(sourceFilePath)) { if (isPendingTypePK(syncFile)) { queueSyncWatchEvent(syncFile.getFilePathName(), syncWatchEvent); return; } FileKeyUtil.writeFileKey(targetFilePath, String.valueOf(syncFile.getSyncFileId()), true); } else if (FileUtil.exists(sourceFilePath)) { SyncFileService.addFolderSyncFile(targetFilePath, parentSyncFile.getTypePK(), parentSyncFile.getRepositoryId(), _syncAccountId); return; } else if (parentTargetFilePath.equals(sourceFilePath.getParent())) { if (isPendingTypePK(syncFile)) { queueSyncWatchEvent(syncFile.getFilePathName(), syncWatchEvent); return; } SyncFileService.updateFolderSyncFile(targetFilePath, _syncAccountId, syncFile); } else { if (isPendingTypePK(syncFile)) { queueSyncWatchEvent(syncFile.getFilePathName(), syncWatchEvent); return; } SyncFileService.moveFolderSyncFile(targetFilePath, parentSyncFile.getTypePK(), _syncAccountId, syncFile); Path sourceFileNameFilePath = sourceFilePath.getFileName(); if (!sourceFileNameFilePath.equals(targetFilePath.getFileName())) { SyncFileService.updateFolderSyncFile(targetFilePath, _syncAccountId, syncFile); } } SyncAccount syncAccount = SyncAccountService.fetchSyncAccount(_syncAccountId); if (syncAccount.getState() == SyncAccount.STATE_CONNECTED) { SyncWatchEvent relatedSyncWatchEvent = SyncWatchEventService.fetchSyncWatchEvent( SyncWatchEvent.EVENT_TYPE_DELETE, syncWatchEvent.getFilePathName(), syncWatchEvent.getTimestamp()); if (relatedSyncWatchEvent != null) { _processedSyncWatchEventIds.add(relatedSyncWatchEvent.getSyncWatchEventId()); } } }
From source file:org.apache.nifi.controller.repository.FileSystemRepository.java
protected boolean archive(final Path curPath) throws IOException { // check if already archived final boolean alreadyArchived = ARCHIVE_DIR_NAME.equals(curPath.getParent().toFile().getName()); if (alreadyArchived) { return false; }/*from ww w . j av a 2 s .com*/ final Path archivePath = getArchivePath(curPath); if (curPath.equals(archivePath)) { LOG.warn("Cannot archive {} because it is already archived", curPath); return false; } try { Files.move(curPath, archivePath); return true; } catch (final NoSuchFileException nsfee) { // If the current path exists, try to create archive path and do the move again. // Otherwise, either the content was removed or has already been archived. Either way, // there's nothing that can be done. if (Files.exists(curPath)) { // The archive directory doesn't exist. Create now and try operation again. // We do it this way, rather than ensuring that the directory exists ahead of time because // it will be rare for the directory not to exist and we would prefer to have the overhead // of the Exception being thrown in these cases, rather than have the overhead of checking // for the existence of the directory continually. Files.createDirectories(archivePath.getParent()); Files.move(curPath, archivePath); return true; } return false; } }
From source file:org.roda.core.model.ModelService.java
public synchronized void findOldLogsAndMoveThemToStorage(Path logDirectory, Path currentLogFile) throws RequestNotValidException, AuthorizationDeniedException, NotFoundException { try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(logDirectory)) { for (Path path : directoryStream) { if (!path.equals(currentLogFile)) { try { StoragePath logPath = ModelUtils.getLogStoragePath(path.getFileName().toString()); storage.createBinary(logPath, new FSPathContentPayload(path), false); Files.delete(path); } catch (IOException | GenericException | AlreadyExistsException e) { LOGGER.error("Error archiving log file", e); }/* ww w. java2 s.c o m*/ } } } catch (IOException e) { LOGGER.error("Error listing directory for log files", e); } }
From source file:com.liferay.sync.engine.file.system.SyncWatchEventProcessor.java
protected void addFile(SyncWatchEvent syncWatchEvent) throws Exception { final Path targetFilePath = Paths.get(syncWatchEvent.getFilePathName()); if (FileUtil.notExists(targetFilePath) || sanitizeFileName(targetFilePath) || isInErrorState(targetFilePath)) { return;/*from w ww. jav a 2s . com*/ } Path parentTargetFilePath = targetFilePath.getParent(); final SyncFile parentSyncFile = SyncFileService.fetchSyncFile(parentTargetFilePath.toString()); if ((parentSyncFile == null) || (!parentSyncFile.isSystem() && (parentSyncFile.getTypePK() == 0))) { queueSyncWatchEvent(parentTargetFilePath.toString(), syncWatchEvent); return; } SyncFile syncFile = SyncFileService.fetchSyncFile(targetFilePath.toString()); if (syncFile == null) { syncFile = SyncFileService.fetchSyncFile(FileKeyUtil.getFileKey(targetFilePath)); if (!verifySite(syncFile, parentSyncFile)) { syncFile = null; } } if (syncFile == null) { Runnable runnable = new Runnable() { @Override public void run() { try { SyncSite syncSite = SyncSiteService.fetchSyncSite(parentSyncFile.getRepositoryId(), _syncAccountId); if ((syncSite == null) || !syncSite.isActive() || !FileUtil.checkFilePath(targetFilePath)) { return; } SyncFileService.addFileSyncFile(targetFilePath, parentSyncFile.getTypePK(), parentSyncFile.getRepositoryId(), _syncAccountId); } catch (Exception e) { if (SyncFileService.fetchSyncFile(targetFilePath.toString()) == null) { _logger.error(e.getMessage(), e); } } } }; _executorService.execute(runnable); return; } Path sourceFilePath = Paths.get(syncFile.getFilePathName()); if (targetFilePath.equals(sourceFilePath)) { if (isPendingTypePK(syncFile) || (syncFile.getState() == SyncFile.STATE_IN_PROGRESS)) { queueSyncWatchEvent(syncFile.getFilePathName(), syncWatchEvent); return; } if (FileUtil.isModified(syncFile)) { SyncFileService.updateFileSyncFile(targetFilePath, _syncAccountId, syncFile); } } else if (FileUtil.exists(sourceFilePath)) { try { if ((Files.size(targetFilePath) == 0) || FileUtil.isModified(syncFile, targetFilePath) || isInErrorState(sourceFilePath)) { SyncFileService.addFileSyncFile(targetFilePath, parentSyncFile.getTypePK(), parentSyncFile.getRepositoryId(), _syncAccountId); } else { SyncFileService.copySyncFile(syncFile, targetFilePath, parentSyncFile.getTypePK(), parentSyncFile.getRepositoryId(), _syncAccountId); } } catch (Exception e) { if (SyncFileService.fetchSyncFile(targetFilePath.toString()) == null) { _logger.error(e.getMessage(), e); } } return; } else if (parentTargetFilePath.equals(sourceFilePath.getParent())) { if (isPendingTypePK(syncFile) || (syncFile.getState() == SyncFile.STATE_IN_PROGRESS)) { queueSyncWatchEvent(syncFile.getFilePathName(), syncWatchEvent); return; } SyncFileService.updateFileSyncFile(targetFilePath, _syncAccountId, syncFile); } else { if (isPendingTypePK(syncFile) || (syncFile.getState() == SyncFile.STATE_IN_PROGRESS)) { queueSyncWatchEvent(syncFile.getFilePathName(), syncWatchEvent); return; } SyncFileService.moveFileSyncFile(targetFilePath, parentSyncFile.getTypePK(), _syncAccountId, syncFile); Path sourceFileNameFilePath = sourceFilePath.getFileName(); if (!sourceFileNameFilePath.equals(targetFilePath.getFileName())) { SyncFileService.updateFileSyncFile(targetFilePath, _syncAccountId, syncFile); } } SyncAccount syncAccount = SyncAccountService.fetchSyncAccount(_syncAccountId); if (syncAccount.getState() == SyncAccount.STATE_CONNECTED) { SyncWatchEvent relatedSyncWatchEvent = SyncWatchEventService.fetchSyncWatchEvent( SyncWatchEvent.EVENT_TYPE_DELETE, syncWatchEvent.getFilePathName(), syncWatchEvent.getTimestamp()); if (relatedSyncWatchEvent != null) { _processedSyncWatchEventIds.add(relatedSyncWatchEvent.getSyncWatchEventId()); } } }
From source file:org.tinymediamanager.core.movie.tasks.MovieUpdateDatasourceTask2.java
private void parseMovieDirectory(Path movieDir, Path dataSource) { List<Path> movieDirList = listFilesAndDirs(movieDir); ArrayList<Path> files = new ArrayList<>(); ArrayList<Path> dirs = new ArrayList<>(); // FIXME: what for....? HashSet<String> normalizedVideoFiles = new HashSet<>(); // just for // identifying MMD boolean isDiscFolder = false; boolean isMultiMovieDir = false; boolean videoFileFound = false; Path movieRoot = movieDir; // root set to current dir - might be adjusted by // disc folders for (Path path : movieDirList) { if (Utils.isRegularFile(path)) { files.add(path.toAbsolutePath()); // do not construct a fully MF yet // just minimal to get the type out of filename MediaFile mf = new MediaFile(); mf.setPath(path.getParent().toString()); mf.setFilename(path.getFileName().toString()); mf.setType(mf.parseType());/*from w w w .j av a 2 s. c om*/ // System.out.println("************ " + mf); if (mf.getType() == MediaFileType.VIDEO) { videoFileFound = true; if (mf.isDiscFile()) { isDiscFolder = true; break; // step out - this is all we need to know } else { // detect unique basename, without stacking etc String[] ty = ParserUtils.detectCleanMovienameAndYear( FilenameUtils.getBaseName(Utils.cleanStackingMarkers(mf.getFilename()))); normalizedVideoFiles.add(ty[0] + ty[1]); } } } else if (Files.isDirectory(path)) { dirs.add(path.toAbsolutePath()); } } if (!videoFileFound) { // hmm... we never found a video file (but maybe others, trailers) so NO // need to parse THIS folder return; } if (isDiscFolder) { // if inside own DiscFolder, walk backwards till movieRoot folder Path relative = dataSource.relativize(movieDir); while (relative.toString().toUpperCase(Locale.ROOT).contains("VIDEO_TS") || relative.toString().toUpperCase(Locale.ROOT).contains("BDMV")) { movieDir = movieDir.getParent(); relative = dataSource.relativize(movieDir); } movieRoot = movieDir; } else { // no VIDEO files in this dir - skip this folder if (normalizedVideoFiles.size() == 0) { return; } // more than one (unstacked) movie file in directory (or DS root) -> must // parsed as multiMovieDir if (normalizedVideoFiles.size() > 1 || movieDir.equals(dataSource)) { isMultiMovieDir = true; } } if (cancel) { return; } // ok, we're ready to parse :) if (isMultiMovieDir) { createMultiMovieFromDir(dataSource, movieRoot, files); } else { createSingleMovieFromDir(dataSource, movieRoot, isDiscFolder); } }