public static File asFile( FileObject fileObject ) { return new File( fileObject.getName().getPath() ); } }
public void putFile(final FileObject file) { Map files = getOrCreateFilesystemCache(file.getFileSystem()); files.put(file.getName(), file); }
@Override public boolean includeFile(FileSelectInfo fileInfo) { LOGGER.fine("Uncompressing " + fileInfo.getFile().getName().getFriendlyURI()); return true; } };
private GroupCommand createGroupCommand(final FileObject file) throws FileSystemException { assert file != null; log.trace("Creating command for group: {}", file); GroupCommand command = container.getBean(GroupCommand.class); String path = fileSystemAccess.dereference(commandsRoot).getName().getRelativeName(file.getName()); if (".".equals(path)) { path = "/"; } command.setPath(path); return command; } }
@Override public void fileDeleted(FileChangeEvent fileChangeEvent) throws FileSystemException { FileObject fileObject = fileChangeEvent.getFile(); LOGGER.info(String.format("Received file deletion event for file: %s", fileObject)); File file = new File(fileObject.getName().getPath()); if (ConfigFileFilter.isFileSupported(file)) { configurationService.delete(file.getParentFile().getName()); Map<String, Object> params = new HashMap<>(); params.put(ConfigurationConstants.FILE_PATH, file.getAbsolutePath()); sendEvent(ConfigurationConstants.FILE_DELETED_EVENT_SUBJECT, params); } }
private void display(final CommandContext context, final FileObject file, final FileObject root) throws FileSystemException { assert context != null; assert file != null; String path; try { path = new URI(this.path).resolve(root.getURL().toURI().relativize(file.getURL().toURI())).toString(); } catch (Exception e) { path = file.getName().getPath(); } IO io = context.getIo(); io.info(path); }
public void touchFile(final FileObject file) { // this moves the file back on top getFile(file.getFileSystem(), file.getName()); } }
/** * Creates a layered file system. This method is called if the file system is not cached. * * @param scheme The URI scheme. * @param file The file to create the file system on top of. * @return The file system. */ protected FileSystem doCreateFileSystem(final String scheme, final FileObject file, final FileSystemOptions options) throws FileSystemException { FileName name = new LayeredFileName(scheme, file.getName(), FileName.ROOT_PATH, FileType.FOLDER); return new TruezipFileSystem(name, file, options); }
protected FileSystem doCreateFileSystem(final String scheme, final FileObject file, final FileSystemOptions fileSystemOptions) throws FileSystemException { final FileName rootName = new LayeredFileName( scheme, file.getName(), FileName.ROOT_PATH, FileType.FOLDER); return new IsoFileSystem(rootName, file, fileSystemOptions); } }
@Override public void fileCreated(FileChangeEvent fileChangeEvent) throws IOException { FileObject fileObject = fileChangeEvent.getFile(); LOGGER.info(String.format("Received file creation event for file: %s", fileObject)); File file = new File(fileObject.getName().getPath()); if (ConfigFileFilter.isFileSupported(file)) { configurationService.addOrUpdate(file); Map<String, Object> params = new HashMap<>(); params.put(ConfigurationConstants.FILE_PATH, file.getAbsolutePath()); sendEvent(ConfigurationConstants.FILE_CREATED_EVENT_SUBJECT, params); } }
@Override public void fileChanged(FileChangeEvent fileChangeEvent) { FileObject fileObject = fileChangeEvent.getFile(); LOGGER.info(String.format("Received file update event for file: %s", fileObject)); File file = new File(fileObject.getName().getPath()); if (ConfigFileFilter.isFileSupported(file)) { configurationService.addOrUpdate(file); Map<String, Object> params = new HashMap<>(); params.put(ConfigurationConstants.FILE_PATH, file.getAbsolutePath()); sendEvent(ConfigurationConstants.FILE_CHANGED_EVENT_SUBJECT, params); } }
protected void ensureFileExists(final FileObject file) throws FileSystemException { assert file != null; if (!file.exists()) { FileObjects.close(file); throw new ResultNotification("File not found: " + file.getName(), Result.FAILURE); } }
/** * @see org.apache.commons.vfs.FileSelector#includeFile(org.apache.commons.vfs.FileSelectInfo) */ public boolean includeFile( FileSelectInfo fileInfo ) { String fileName = fileInfo.getFile().getName().getBaseName(); return matcher.matches( fileName, pattern ); }
public boolean includeFile(final FileSelectInfo selection) throws Exception { assert selection != null; return matcher.matches(selection.getFile().getName().getBaseName(), pattern); }
protected void ensureFileIsReadable(final FileObject file) throws FileSystemException { assert file != null; if (!file.getType().hasChildren()) { FileObjects.close(file); throw new ResultNotification("File is not readable: " + file.getName(), Result.FAILURE); } }
protected void ensureFileHasContent(final FileObject file) throws FileSystemException { assert file != null; if (!file.getType().hasContent()) { FileObjects.close(file); throw new ResultNotification("File has no content: " + file.getName(), Result.FAILURE); } }
public boolean includeFile( FileSelectInfo fileSelectInfo ) throws Exception { FileObject fileObject = fileSelectInfo.getFile(); FileName name = fileObject.getName(); if ( fileType != null && fileObject.getType() != fileType ) { return false; } String relativePath = root.getRelativeName( name ); return matches( relativePath ); }
protected void ensureFileHasChildren(final FileObject file) throws FileSystemException { assert file != null; if (!file.getType().hasChildren()) { FileObjects.close(file); throw new ResultNotification("File has no children: " + file.getName(), Result.FAILURE); } }
public Object execute(final CommandContext context) throws Exception { assert context != null; IO io = context.getIo(); FileObject dir = getCurrentDirectory(context); io.info(dir.getName().getURI()); FileObjects.close(dir); return Result.SUCCESS; } }
public static UnixFsObject.Directory dirFromFileObject( RelativePath toFile, FileObject fromFile, FileAttributes attributes ) throws FileSystemException { if ( !fromFile.getType().equals( FileType.FOLDER ) ) { throw new FileSystemException( "Not a directory: " + fromFile.getName().getPath() + ", was: " + fromFile.getType() ); } FileContent content = fromFile.getContent(); return UnixFsObject.directory( toFile, new LocalDateTime( content.getLastModifiedTime() ), attributes ); } }