List of usage examples for org.apache.commons.vfs2 FileObject getName
FileName getName();
From source file:io.kahu.hawaii.service.io.FileChangeListener.java
@Override public void fileChanged(FileChangeEvent fce) throws Exception { if (fce != null) { FileObject file = fce.getFile(); if (file.getContent().getSize() > maxFileLength) { logManager.error(new ServerException(ServerError.PARSER_MAX_FILESIZE_EXCEEDED, "Handler '" + handler + "', file at: " + file.getName().getPath())); } else {// w ww . ja va 2s. c om logManager.info(CoreLoggers.SERVER, "File changed '" + fce.getFile().getName().getPath() + "'."); handler.handleFileChange(); } } }
From source file:com.streamsets.pipeline.stage.origin.remote.FTPRemoteDownloadSourceDelegate.java
@Override void queueFiles(FileQueueChecker fqc, NavigableSet<RemoteFile> fileQueue, FileFilter fileFilter) throws IOException, StageException { boolean done = false; int retryCounter = 0; while (!done && retryCounter < MAX_RETRIES) { try {/* w w w . ja v a 2s.co m*/ remoteDir.refresh(); // A call to getChildren() and then refresh() is needed in order to properly refresh if files were updated // A possible bug in VFS? remoteDir.getChildren(); remoteDir.refresh(); done = true; } catch (FileSystemException fse) { // Refresh can fail due to session is down, a timeout, etc; so try getting a new connection if (retryCounter < MAX_RETRIES - 1) { LOG.info("Got FileSystemException when trying to refresh remote directory. '{}'", fse.getMessage(), fse); LOG.warn("Retrying connection to remote directory"); remoteDir = VFS.getManager().resolveFile(remoteURI.toString(), options); } else { throw new StageException(Errors.REMOTE_18, fse.getMessage(), fse); } } retryCounter++; } FileObject[] theFiles = remoteDir.getChildren(); if (conf.processSubDirectories) { theFiles = ArrayUtils.addAll(theFiles, remoteDir.findFiles(fileFilter)); } for (FileObject file : theFiles) { String path = relativizeToRoot(file.getName().getPath()); LOG.debug("Checking {}", path); if (file.getType() != FileType.FILE) { LOG.trace("Skipping {} because it is not a file", path); continue; } //check if base name matches - not full path. Matcher matcher = fileFilter.getRegex().matcher(file.getName().getBaseName()); if (!matcher.matches()) { LOG.trace("Skipping {} because it does not match the regex", path); continue; } RemoteFile tempFile = new FTPRemoteFile(path, getModTime(file), file); if (fqc.shouldQueue(tempFile)) { LOG.debug("Queuing file {} with modtime {}", tempFile.getFilePath(), tempFile.getLastModified()); // If we are done with all files, the files with the final mtime might get re-ingested over and over. // So if it is the one of those, don't pull it in. fileQueue.add(tempFile); } } }
From source file:com.sshtools.appframework.ui.IconStore.java
private Icon get(String name, int size, String cacheKey, FileObject file) throws FileSystemException, IOException { Icon icon;/* ww w. j av a2 s . com*/ if (file.getName().getBaseName().toLowerCase().endsWith(".svg")) { InputStream in = file.getContent().getInputStream(); try { icon = new SVGIcon(name + "-" + size, in, size, size); } finally { in.close(); } } else { DataInputStream din = new DataInputStream(file.getContent().getInputStream()); try { byte[] imgData = new byte[(int) file.getContent().getSize()]; din.readFully(imgData); icon = new ImageIcon(imgData); } finally { din.close(); } } if (icon.getIconWidth() != size && icon instanceof ImageIcon) { Image img = ((ImageIcon) icon).getImage(); img = img.getScaledInstance(size, size, Image.SCALE_SMOOTH); icon = new ImageIcon(img); } cache.put(cacheKey, icon); return icon; }
From source file:com.sludev.commons.vfs2.provider.azure.AzFileProviderTest.java
/** * By default FileObject.getChildren() will use doListChildrenResolved() if available * /* w ww . j a v a 2 s. c om*/ * @throws Exception */ @Test public void A005_listChildren() throws Exception { String currAccountStr = testProperties.getProperty("azure.account.name"); String currKey = testProperties.getProperty("azure.account.key"); String currContainerStr = testProperties.getProperty("azure.test0001.container.name"); String currHost = testProperties.getProperty("azure.host"); // <account>.blob.core.windows.net DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(AzConstants.AZSBSCHEME, new AzFileProvider()); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); String currFileNameStr = "uploadFile02"; String currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); FileObject[] currObjs = currFile.getChildren(); for (FileObject obj : currObjs) { FileName currName = obj.getName(); Boolean res = obj.exists(); FileType ft = obj.getType(); log.info(String.format("\nNAME.PATH : '%s'\nEXISTS : %b\nTYPE : %s\n\n", currName.getPath(), res, ft)); } }
From source file:hadoopInstaller.installation.Installer.java
private void getBundleHashes(FileObject file) throws FileSystemException, InstallationFatalError { String fileName = file.getName().getBaseName(); getLog().trace("HadoopInstaller.MD5.Start", fileName); //$NON-NLS-1$ if (file.getType().equals(FileType.FILE)) { try {/*w ww .j av a 2 s.c o m*/ String md5 = MD5Calculator.calculateFor(file); getFileHashes().put(fileName, md5); getLog().trace("HadoopInstaller.MD5.Success", fileName, //$NON-NLS-1$ md5); } catch (NoSuchAlgorithmException | IOException e) { throw new InstallationFatalError(e, "HadoopInstaller.MD5.Error", fileName); //$NON-NLS-1$ } } }
From source file:com.nesscomputing.velocity.VelocityGuiceModule.java
protected void walk(Set<String> foundTemplates, final String prefix, FileObject root) throws FileSystemException, URISyntaxException { List<FileObject> foundFiles = Lists.newArrayList(); root.findFiles(new MacroFileSelector(), true, foundFiles); for (FileObject file : foundFiles) { String templateName = StringUtils.removeEndIgnoreCase(root.getName().getRelativeName(file.getName()), ".vm"); String bindName = prefix + "." + templateName; if (!foundTemplates.add(bindName)) { continue; }//from w ww.j a v a 2 s . c o m UriTemplateProvider provider = new UriTemplateProvider(file.getURL().toURI()); bind(Template.class).annotatedWith(Names.named(bindName)).toProvider(provider).in(Scopes.SINGLETON); } }
From source file:com.mirth.connect.util.MessageImporter.java
private void importVfsFileRecursive(FileObject file, MessageWriter messageWriter, int[] result) throws InterruptedException, MessageImportException { try {/*ww w . ja va2 s.c om*/ switch (file.getType()) { case FOLDER: logger.debug("Reading folder: " + file.getName().getURI()); for (FileObject child : file.getChildren()) { ThreadUtils.checkInterruptedStatus(); importVfsFileRecursive(child, messageWriter, result); } break; case FILE: importVfsFile(file, messageWriter, result); break; } } catch (FileSystemException e) { logger.error("An error occurred when accessing: " + file.getName().getURI(), e); } }
From source file:com.flicklib.folderscanner.AdvancedFolderScanner.java
private String getNameWithoutExt(FileObject file) { String name = file.getName().getBaseName(); int lastDotPos = name.lastIndexOf('.'); if (lastDotPos != -1 && lastDotPos != 0 && lastDotPos < name.length() - 1) { return name.substring(0, lastDotPos); }/*ww w .j a v a2s .co m*/ return name; }
From source file:com.flicklib.folderscanner.AdvancedFolderScanner.java
private String getExtension(FileObject file) { return getExtension(file.getName().getBaseName()); }
From source file:com.googlecode.vfsjfilechooser2.filechooser.AbstractVFSFileSystemView.java
/** * Type description for a file, directory, or folder as it would be displayed in * a system file browser. Example from Windows: the "Desktop" folder * is desribed as "Desktop"./* w ww .j a va2 s . c om*/ * * Override for platforms with native ShellFolder implementations. * * @param f a <code>File</code> object * @return the file type description as it would be displayed by a native file chooser * or null if no native information is available. * @see JFileChooser#getTypeDescription * @since 1.4 */ public String getSystemTypeDescription(FileObject f) { return VFSUtils.getFriendlyName(f.getName().toString()); }