List of usage examples for org.apache.commons.vfs2 FileObject getName
FileName getName();
From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignProvider.java
private static void determineChangedResources(int resourceType, FileObject categoryFolder, FileObject source, FileObject target, FileObject baseFolder, String sourceEncoding, String targetEncoding, OverlayStatus status, Logger log, DesignFileValidator validator) throws WGDesignSyncException, NoSuchAlgorithmException, IOException { for (FileObject sourceFile : source.getChildren()) { if (!isValidDesignFile(sourceFile, validator)) { continue; }//from ww w .j a v a 2 s . co m FileObject targetFile = target.resolveFile(sourceFile.getName().getBaseName()); String resourcePath = baseFolder.getName().getRelativeName(targetFile.getName()); if (sourceFile.getType().equals(FileType.FOLDER)) { if (!targetFile.exists()) { status.getNewFolders().add(targetFile.getName().getPath()); } else if (targetFile.getType().equals(FileType.FILE)) { throw new WGDesignSyncException("Unable to apply overlay. Folder '" + baseFolder.getName().getRelativeName(targetFile.getName()) + " already exists as file. Delete it to enable overlay management again"); } determineChangedResources(resourceType, categoryFolder, sourceFile, targetFile, baseFolder, sourceEncoding, targetEncoding, status, log, validator); } else if (sourceFile.getType().equals(FileType.FILE)) { // File does not exist. if (!targetFile.exists()) { // Was it once deployed? ResourceData originalHash = status.getOverlayData().getOverlayResources().get(resourcePath); if (originalHash == null) { // No, so it must be new in base status.addChangedResource(resourceType, sourceFile, targetFile, categoryFolder, OverlayStatus.ChangeType.NEW, resourcePath, null); } else { // Yes, Check if the base file changed since deployment String newHash = MD5HashingInputStream .getStreamHash(sourceFile.getContent().getInputStream()); if (newHash.equals(originalHash.getMd5Hash())) { // Nope. So this is no change. The overlay just chose not to use the file continue; } else { // Yes, so it is indeed a conflict status.addChangedResource(resourceType, sourceFile, targetFile, categoryFolder, OverlayStatus.ChangeType.CONFLICT, resourcePath, null); } } } // File does exist: Determine if is updated in base since the overlay file was deployed else { ResourceData originalHash = status.getOverlayData().getOverlayResources().get(resourcePath); if (originalHash == null) { if (!status.isUpdatedBaseDesign()) { log.info("There is no information about the original deployment state of resource " + resourcePath + ". Setting original deployment state now to the current base version."); OverlayData.ResourceData resource = new OverlayData.ResourceData(); resource.setMd5Hash( MD5HashingInputStream.getStreamHash(sourceFile.getContent().getInputStream())); status.getOverlayData().setOverlayResource(resourcePath, resource); } else { log.info("Cannot update overlay resource " + resourcePath + " as there is no information of its original deployment state."); } continue; } // First determine if the resource really changed from what was distributed String newHash = MD5HashingInputStream.getStreamHash(sourceFile.getContent().getInputStream()); if (newHash.equals(originalHash.getMd5Hash())) { continue; } // Determine if the target file is the same as was distributed. If not then it was user modified, so it is a conflict String currentHash = MD5HashingInputStream .getStreamHash(targetFile.getContent().getInputStream()); if (!currentHash.equals(originalHash.getMd5Hash())) { status.addChangedResource(resourceType, sourceFile, targetFile, categoryFolder, OverlayStatus.ChangeType.CONFLICT, resourcePath, null); } // It is a normal change else { status.addChangedResource(resourceType, sourceFile, targetFile, categoryFolder, OverlayStatus.ChangeType.CHANGED, resourcePath, null); } } } } }
From source file:com.streamsets.pipeline.stage.origin.remote.TestFileFilter.java
private FileSelectInfo createFileSelectInfo(String fileName, boolean isFile) throws Exception { FileSelectInfo fileSelectInfo = Mockito.mock(FileSelectInfo.class); FileObject fileObject = Mockito.mock(FileObject.class); Mockito.when(fileSelectInfo.getFile()).thenReturn(fileObject); if (isFile) { Mockito.when(fileObject.getType()).thenReturn(FileType.FILE); } else {//from www .j a v a 2 s.c om Mockito.when(fileObject.getType()).thenReturn(FileType.FOLDER); } FileName fName = Mockito.mock(FileName.class); Mockito.when(fileObject.getName()).thenReturn(fName); Mockito.when(fName.getBaseName()).thenReturn(fileName); return fileSelectInfo; }
From source file:net.sf.jabb.web.action.VfsTreeAction.java
/** * It transforms FileObject into JsTreeNodeData. * @param file the file whose information will be encapsulated in the node data structure. * @return The node data structure which presents the file. * @throws FileSystemException /*w ww . ja va2s . c o m*/ */ protected JsTreeNodeData populateTreeNodeData(FileObject file, boolean noChild, String relativePath) throws FileSystemException { JsTreeNodeData node = new JsTreeNodeData(); String baseName = file.getName().getBaseName(); FileContent content = file.getContent(); FileType type = file.getType(); node.setData(baseName); Map<String, Object> attr = new HashMap<String, Object>(); node.setAttr(attr); attr.put("id", relativePath); attr.put("rel", type.getName()); attr.put("fileType", type.getName()); if (content != null) { long fileLastModifiedTime = file.getContent().getLastModifiedTime(); attr.put("fileLastModifiedTime", fileLastModifiedTime); attr.put("fileLastModifiedTimeForDisplay", DateFormat.getDateTimeInstance().format(new Date(fileLastModifiedTime))); if (file.getType() != FileType.FOLDER) { attr.put("fileSize", content.getSize()); attr.put("fileSizeForDisplay", FileUtils.byteCountToDisplaySize(content.getSize())); } } // these fields should not appear in JSON for leaf nodes if (!noChild) { node.setState(JsTreeNodeData.STATE_CLOSED); } return node; }
From source file:de.innovationgate.wgpublisher.design.fs.AbstractDesignFile.java
public AbstractDesignFile(FileSystemDesignManager manager, FileObject file, int type) throws FileSystemException, WGDesignSyncException { this(manager, manager.getRelativePath(file), file.getName().getBaseName(), type); }
From source file:hadoopInstaller.installation.Installer.java
private void getBundleInstallDirectory(String resource, FileObject file) throws InstallationFatalError { getLog().trace("HadoopInstaller.InstallationDirectory.Start", resource); //$NON-NLS-1$ try {// w ww . j av a 2 s . c om String uri = URI.create(file.getName().getURI().replaceFirst("file:", "tgz:")) //$NON-NLS-1$ //$NON-NLS-2$ .toString(); FileObject tgzFile; tgzFile = VFS.getManager().resolveFile(uri); String name = tgzFile.getChildren()[0].getName().getBaseName(); getDirectories().put(resource, name); getLog().debug("HadoopInstaller.InstallationDirectory.Success", //$NON-NLS-1$ resource, name); } catch (FileSystemException e) { throw new InstallationFatalError(e, "HadoopInstaller.InstallationDirectory.Error", //$NON-NLS-1$ file.getName().getBaseName()); } }
From source file:com.sludev.commons.vfs.simpleshell.SimpleShell.java
/** * Does a 'cd' command./*from w ww.j a v a 2s. c o m*/ * If the taget directory does not exist, a message is printed to <code>System.err</code>. */ public void cd(final String[] cmd) throws Exception { final String path; if (cmd.length > 1) { path = cmd[1]; } else { path = System.getProperty("user.home"); } // Locate and validate the folder FileObject tmp = mgr.resolveFile(cwd, path); if (tmp.exists()) { cwd = tmp; } else { System.out.println("Folder does not exist: " + tmp.getName()); } System.out.println("Current folder is " + cwd.getName()); }
From source file:com.flicklib.folderscanner.AdvancedFolderScanner.java
/** * Scans the folders// w w w .ja va2 s .c o m * * @param folders * @return a List of MovieInfo * * TODO get rid of the synchronized and create a factory or pass all state data */ @Override public synchronized List<FileGroup> scan(final Set<FileObject> folders, AsyncMonitor monitor) { movies = new ArrayList<FileGroup>(); if (monitor != null) { monitor.start(); } for (FileObject folder : folders) { try { URL url = folder.getURL(); if (folder.exists()) { currentLabel = folder.getName().getBaseName(); LOGGER.info("scanning " + url); try { browse(folder, monitor); } catch (InterruptedException ie) { LOGGER.info("task is cancelled!" + ie.getMessage()); return null; } } else { LOGGER.warn("folder " + folder.getURL() + " does not exist!"); } } catch (FileSystemException e) { LOGGER.error("error during checking " + folder + ", " + e.getMessage(), e); } } if (monitor != null) { monitor.finish(); } return movies; }
From source file:com.sonicle.webtop.vfs.PublicService.java
private void writeStoreFile(HttpServletResponse response, int storeId, String filePath, String outFileName) { try {//from www.ja v a 2s.co m FileObject fo = null; try { fo = manager.getStoreFile(storeId, filePath); if (fo.isFile()) { String mediaType = ServletHelper.guessMediaType(fo.getName().getBaseName(), true); ServletUtils.setFileStreamHeaders(response, mediaType, DispositionType.ATTACHMENT, outFileName); ServletUtils.setContentLengthHeader(response, fo.getContent().getSize()); IOUtils.copy(fo.getContent().getInputStream(), response.getOutputStream()); } else if (fo.isFolder()) { ServletUtils.setFileStreamHeaders(response, "application/zip", DispositionType.ATTACHMENT, outFileName); ZipOutputStream zos = new ZipOutputStream(response.getOutputStream()); try { VfsUtils.zipFileObject(fo, zos, true); zos.flush(); } finally { IOUtils.closeQuietly(zos); } } } finally { IOUtils.closeQuietly(fo); } } catch (Exception ex) { logger.error("Error in DownloadFile", ex); ServletUtils.sendError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:com.yenlo.synapse.transport.vfs.VFSTransportSender.java
private void acquireLockForSending(FileObject responseFile, VFSOutTransportInfo vfsOutInfo) throws AxisFault { int tryNum = 0; // wait till we get the lock while (!VFSUtils.acquireLock(fsManager, responseFile)) { if (vfsOutInfo.getMaxRetryCount() == tryNum++) { handleException("Couldn't send the message to file : " + responseFile.getName() + ", unable to acquire the " + "lock even after " + tryNum + " retries"); } else {// www .ja v a2s . c o m log.warn("Couldn't get the lock for the file : " + VFSUtils.maskURLPassword(responseFile.getName().getURI()) + ", retry : " + tryNum + " scheduled after : " + vfsOutInfo.getReconnectTimeout()); try { Thread.sleep(vfsOutInfo.getReconnectTimeout()); } catch (InterruptedException ignore) { } } } }
From source file:de.innovationgate.wgpublisher.design.fs.AbstractDesignFile.java
protected boolean isExcludedFileContainerFile(FileObject file) throws FileSystemException { if (!getManager().isValidDesignFile(file)) { return true; }/*ww w.j a va 2s.co m*/ if (file.getType().equals(FileType.FOLDER)) { return true; } if (file.getName().getBaseName() .equals(FILECONTAINER_METADATA_FILENAME + DesignDirectory.SUFFIX_METADATA)) { return true; } return false; }