List of usage examples for java.nio.file FileSystemException getMessage
@Override
public String getMessage()
From source file:com.liferay.sync.engine.document.library.handler.DownloadFileHandler.java
protected void copyFile(final SyncFile syncFile, Path filePath, InputStream inputStream, boolean append) throws Exception { OutputStream outputStream = null; Watcher watcher = WatcherManager.getWatcher(getSyncAccountId()); try {//from w w w .j a v a 2s . c o m Path tempFilePath = FileUtil.getTempFilePath(syncFile); boolean exists = FileUtil.exists(filePath); if (append) { outputStream = Files.newOutputStream(tempFilePath, StandardOpenOption.APPEND); IOUtils.copyLarge(inputStream, outputStream); } else { if (exists && (boolean) getParameterValue("patch")) { if (_logger.isDebugEnabled()) { _logger.debug("Patching {}", syncFile.getFilePathName()); } Files.copy(filePath, tempFilePath, StandardCopyOption.REPLACE_EXISTING); IODeltaUtil.patch(tempFilePath, inputStream); } else { Files.copy(inputStream, tempFilePath, StandardCopyOption.REPLACE_EXISTING); } } watcher.addDownloadedFilePathName(filePath.toString()); if (GetterUtil.getBoolean(syncFile.getLocalExtraSettingValue("restoreEvent"))) { syncFile.unsetLocalExtraSetting("restoreEvent"); syncFile.setUiEvent(SyncFile.UI_EVENT_RESTORED_REMOTE); } else if (exists) { syncFile.setUiEvent(SyncFile.UI_EVENT_DOWNLOADED_UPDATE); } else { syncFile.setUiEvent(SyncFile.UI_EVENT_DOWNLOADED_NEW); } FileKeyUtil.writeFileKey(tempFilePath, String.valueOf(syncFile.getSyncFileId()), false); FileUtil.setModifiedTime(tempFilePath, syncFile.getModifiedTime()); if (MSOfficeFileUtil.isLegacyExcelFile(filePath)) { syncFile.setLocalExtraSetting("lastSavedDate", MSOfficeFileUtil.getLastSavedDate(tempFilePath)); } Files.move(tempFilePath, filePath, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING); ExecutorService executorService = SyncEngine.getExecutorService(); Runnable runnable = new Runnable() { @Override public void run() { IODeltaUtil.checksums(syncFile); syncFile.setState(SyncFile.STATE_SYNCED); SyncFileService.update(syncFile); } }; executorService.execute(runnable); } catch (FileSystemException fse) { if (fse instanceof AccessDeniedException) { _logger.error(fse.getMessage(), fse); syncFile.setState(SyncFile.STATE_ERROR); syncFile.setUiEvent(SyncFile.UI_EVENT_ACCESS_DENIED_LOCAL); SyncFileService.update(syncFile); return; } else if (fse instanceof NoSuchFileException) { if (isEventCancelled()) { SyncFileService.deleteSyncFile(syncFile); return; } } watcher.removeDownloadedFilePathName(filePath.toString()); String message = fse.getMessage(); _logger.error(message, fse); syncFile.setState(SyncFile.STATE_ERROR); if (message.contains("File name too long")) { syncFile.setUiEvent(SyncFile.UI_EVENT_FILE_NAME_TOO_LONG); } SyncFileService.update(syncFile); } finally { StreamUtil.cleanUp(outputStream); } }
From source file:com.twosigma.beaker.core.rest.FileIORest.java
@POST @Consumes("application/x-www-form-urlencoded") @Path("setPosixFileOwnerAndPermissions") @Produces(MediaType.TEXT_PLAIN)// w w w .j a va2s. c om 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.liferay.sync.engine.document.library.handler.GetSyncDLObjectUpdateHandler.java
protected void processSyncFile(SyncFile targetSyncFile) { SyncFile sourceSyncFile = SyncFileService.fetchSyncFile(targetSyncFile.getRepositoryId(), getSyncAccountId(), targetSyncFile.getTypePK()); if ((sourceSyncFile != null) && (sourceSyncFile.getState() == SyncFile.STATE_ERROR)) { if (_logger.isDebugEnabled()) { _logger.debug("Skipping file {}. File is in an error state.", sourceSyncFile.getFilePathName()); }// w w w .j a v a 2s . c o m return; } String event = targetSyncFile.getEvent(); if (event.equals(SyncFile.EVENT_DELETE) || event.equals(SyncFile.EVENT_TRASH)) { if (sourceSyncFile != null) { try { deleteFile(sourceSyncFile, targetSyncFile); } catch (Exception e) { _logger.error(e.getMessage(), e); } } return; } SyncFile parentSyncFile = SyncFileService.fetchSyncFile(targetSyncFile.getRepositoryId(), getSyncAccountId(), targetSyncFile.getParentFolderId()); if (parentSyncFile == null) { queueSyncFile(targetSyncFile.getParentFolderId(), targetSyncFile); return; } try { String filePathName = FileUtil.getFilePathName(parentSyncFile.getFilePathName(), FileUtil.getSanitizedFileName(targetSyncFile.getName(), targetSyncFile.getExtension())); if (sourceSyncFile == null) { sourceSyncFile = SyncFileService.fetchSyncFile(filePathName); } if (isIgnoredFilePath(sourceSyncFile, filePathName)) { return; } if ((sourceSyncFile != null) && (sourceSyncFile.getModifiedTime() == targetSyncFile.getModifiedTime())) { if (!Validator.isBlank(targetSyncFile.getChecksum())) { sourceSyncFile.setChecksum(targetSyncFile.getChecksum()); SyncFileService.update(sourceSyncFile); } return; } if ((sourceSyncFile != null) && !sourceSyncFile.isUnsynced()) { sourceSyncFile.setState(SyncFile.STATE_IN_PROGRESS); } targetSyncFile.setFilePathName(filePathName); targetSyncFile.setState(SyncFile.STATE_IN_PROGRESS); if (event.equals(SyncFile.EVENT_ADD) || event.equals(SyncFile.EVENT_GET) || event.equals(SyncFile.EVENT_MOVE) || event.equals(SyncFile.EVENT_UPDATE)) { if (sourceSyncFile == null) { addFile(targetSyncFile, filePathName); } else { updateFile(sourceSyncFile, targetSyncFile, filePathName); } } else if (event.equals(SyncFile.EVENT_RESTORE)) { if (Validator.isBlank(targetSyncFile.getName())) { // Workaround for SYNC-1690 return; } else if (sourceSyncFile != null) { updateFile(sourceSyncFile, targetSyncFile, filePathName); } else if (isParentUnsynced(targetSyncFile)) { if (targetSyncFile.isFolder()) { targetSyncFile.setModifiedTime(0); targetSyncFile.setState(SyncFile.STATE_UNSYNCED); targetSyncFile.setSyncAccountId(getSyncAccountId()); targetSyncFile.setUiEvent(SyncFile.UI_EVENT_NONE); SyncFileService.update(targetSyncFile); } return; } else { targetSyncFile.setLocalExtraSetting("restoreEvent", true); SyncFileService.update(targetSyncFile); addFile(targetSyncFile, filePathName); } } processDependentSyncFiles(targetSyncFile); if (getParameterValue("parentFolderId") != null) { SyncFile syncFile = SyncFileService.fetchSyncFile((Long) getParameterValue("repositoryId"), getSyncAccountId(), (Long) getParameterValue("parentFolderId")); if (syncFile != null) { syncFile.setState(SyncFile.STATE_IN_PROGRESS); syncFile.setUiEvent(SyncFile.UI_EVENT_RESYNCING); SyncFileService.update(syncFile); } } } catch (FileSystemException fse) { String message = fse.getMessage(); if (message.contains("File name too long")) { targetSyncFile.setState(SyncFile.STATE_ERROR); targetSyncFile.setUiEvent(SyncFile.UI_EVENT_FILE_NAME_TOO_LONG); SyncFileService.update(targetSyncFile); } } catch (Exception e) { _logger.error(e.getMessage(), e); } }