List of usage examples for org.apache.commons.io FilenameUtils getPath
public static String getPath(String filename)
From source file:org.ngrinder.script.service.FileEntryService.java
/** * Get Lib and Resources. This method will collect the files of lib and resources folder on the * same folder whre script is located.//from w ww .j av a 2 s. com * * @param user * user * @param scriptPath * path of script * @param revision * revision number. If head, it should be -1. * @return {@link FileEntry} list */ public List<FileEntry> getLibAndResourcesEntries(User user, String scriptPath, Long revision) { String path = FilenameUtils.getPath(scriptPath); List<FileEntry> fileList = new ArrayList<FileEntry>(); List<FileEntry> fileEntries = getFileEntries(user, path + "lib/", revision); for (FileEntry eachFileEntry : fileEntries) { // Skip jython 2.5... it's already included. if (startsWithIgnoreCase(eachFileEntry.getFileName(), "jython-2.5.") || startsWithIgnoreCase(eachFileEntry.getFileName(), "jython-standalone-2.5.")) { continue; } FileType fileType = eachFileEntry.getFileType(); if (fileType.isLibDistribtable()) { fileList.add(eachFileEntry); } } fileEntries = getFileEntries(user, path + "resources/", revision); for (FileEntry eachFileEntry : fileEntries) { FileType fileType = eachFileEntry.getFileType(); if (fileType.isResourceDistributable()) { fileList.add(eachFileEntry); } } return fileList; }
From source file:org.okj.commons.net.FtpUtils.java
/** * FTP// w w w . j a v a2 s . com * * @param localFile * @param newName * * @param remoteFoldPath * @throws Exception */ public boolean uploadFile(InputStream input, String remotePath) { boolean success = false; try { String filename = FilenameUtils.getName(remotePath); String path = FilenameUtils.getPath(remotePath); // createDirectory(path); success = ftp.storeFile(filename, input); if (LOGGER.isInfoEnabled()) { LOGGER.info("[FTPHelper] success=" + success + ", filename=" + filename + ", path=" + path); } } catch (IOException ex) { LogUtils.error(LOGGER, "", ex); } finally { IOUtils.closeQuietly(input); if (ftp.isConnected()) { try { ftp.disconnect(); } catch (IOException f) { LogUtils.error(LOGGER, "FTP", f); } } } return success; }
From source file:org.okj.commons.net.FtpUtils.java
/** * /*from w w w . j a v a2 s . c o m*/ * @param remotePath * @throws UploadFileException */ public void deleteFile(String remotePath) { try { // String filename = FilenameUtils.getName(remotePath); String path = FilenameUtils.getPath(remotePath); // changeWorkingDirectory(path); // boolean success = ftp.deleteFile(filename); if (LOGGER.isInfoEnabled()) { LOGGER.info("[FTPHelper] success=" + success + ", remotePath=" + remotePath); } } catch (IOException ex) { LogUtils.error(LOGGER, "FTP", ex); } finally { if (ftp.isConnected()) { try { ftp.disconnect(); } catch (IOException f) { LogUtils.error(LOGGER, "FTP", f); } } } }
From source file:org.opencastproject.workspace.impl.WorkspaceImpl.java
/** * Transforms a URI into a workspace File. If the file comes from the working file repository, the path in the * workspace mirrors that of the repository. If the file comes from another source, directories are created for each * segment of the URL. Sub-directories may be created as needed. * // w w w .j a va 2 s . c o m * @param uri * the uri * @param createDirectories * <code>true</code> to have subdirectories created * @return the local file representation */ protected File getWorkspaceFile(URI uri, boolean createDirectories) { String uriString = uri.toString(); String wfrPrefix = wfr.getBaseUri().toString(); String serverPath = FilenameUtils.getPath(uriString); if (uriString.startsWith(wfrPrefix)) { serverPath = serverPath.substring(wfrPrefix.length()); } else { serverPath = serverPath.replaceAll(":/*", "_"); } String wsDirectoryPath = PathSupport.concat(wsRoot, serverPath); File wsDirectory = new File(wsDirectoryPath); wsDirectory.mkdirs(); String safeFileName = PathSupport.toSafeName(FilenameUtils.getName(uriString)); return new File(wsDirectory, safeFileName); }
From source file:org.opencastproject.workspace.impl.WorkspaceImpl.java
/** * Returns the working file repository collection. * <p>/*from w w w. j ava 2s .c om*/ * * <pre> * http://localhost:8080/files/collection/<collection>/ -> <collection> * </pre> * * @param uri * the working file repository collection uri * @return the collection name */ private String getCollection(URI uri) { String path = uri.toString(); if (path.indexOf(WorkingFileRepository.COLLECTION_PATH_PREFIX) < 0) throw new IllegalArgumentException(uri + " must point to a working file repository collection"); String collection = FilenameUtils.getPath(path); if (collection.endsWith("/")) collection = collection.substring(0, collection.length() - 1); collection = collection.substring(collection.lastIndexOf("/")); collection = collection.substring(collection.lastIndexOf("/") + 1, collection.length()); return collection; }
From source file:org.openmainframe.ade.ext.main.helper.AdeInputStreamHandlerExt.java
/** * Process the Log Messages coming from a file. * /*from ww w . j a v a 2 s. c om*/ * @param file * @throws AdeException */ public final void incomingStreamFromFile(File file) throws AdeException { final InputStream is = AdeFileUtils.openLogFileAsInputStream(file); /* Create a AdeInputStream, note that properties is not used by * Anomaly Detection Engine */ final Properties props = new Properties(); /* Retrieve the name of the file. FilenameUtil is used here to extract a path without any prefix. * Note: Drive Letters show up on Windows System as prefix. getPath() will return the full path without the drive. */ final String filename = FilenameUtils.getPath(file.getAbsolutePath()) + file.getName(); final String parseReportFilename = getParseReportFilename(filename); a_adeInputStream = new AdeInputStreamExt(is, props, m_adeExtProperties, parseReportFilename); /* Indicate this is a new file, this will allow an interval broken into * to log files. */ incomingSeparator(new FileSeperator(file.getName())); /* Send the stream for further processing */ incomingObject(a_adeInputStream); }
From source file:org.openmicroscopy.shoola.env.Container.java
/** * Initializes the member fields. /*from w w w. j a v a 2s. c om*/ * <p>The absolute path to the installation directory is obtained from * <code>home</code>. If this parameter doesn't specify an absolute path, * then it'll be translated into an absolute path. Translation is system * dependent -- in many cases, the path is resolved against the user * directory (typically the directory in which the JVM was invoked).</p> * * @param home Path to the installation directory. If <code>null</code> or * empty, then the user directory is assumed. * @param configFile The configuration file. * @throws StartupException If <code>home</code> can't be resolved to a * valid and existing directory. */ private Container(String home, String configFile) throws StartupException { if (CommonsLangUtils.isBlank(configFile) || !FilenameUtils.isExtension(configFile, "xml")) configFile = CONFIG_FILE; this.configFile = configFile; if (CommonsLangUtils.isBlank(FilenameUtils.getPath(home))) home = System.getProperty("user.dir"); File f = new File(home); //Now make it absolute. If the original path wasn't absolute, then //translation is system dependent. f = f.getAbsoluteFile(); homeDir = f.getAbsolutePath(); //Make sure that what we've got is a directory. if (!f.exists() || !f.isDirectory()) throw new StartupException("Can't locate home dir: " + homeDir); agentsPool = new HashSet<Agent>(); registry = RegistryFactory.makeNew(); }
From source file:org.pentaho.platform.repository.RepositoryFilenameUtils.java
/** * Gets the path from a full filename, which excludes the prefix. * <p/>/*from w w w . j a va 2s. c om*/ * The method is entirely text based, and returns the text before and including the last forward or backslash. * * <pre> * a.txt --> "" * a/b/c --> a/b/ * a/b/c/ --> a/b/c/ * /a.txt --> "" * /a/b/c --> a/b/ * /a/b/c/ --> a/b/c/ * </pre> * <p/> * This method drops the prefix from the result. See {@link #getFullPath(String)} for the method that retains the * prefix. * * @param filename * the filename to query, null returns null * @return the path of the file, an empty string if none exists, null if invalid */ public static String getPath(final String filename) { return FilenameUtils.getPath(filename); }
From source file:org.polymap.p4.data.importer.archive.ArchiveReader.java
protected void handleZip(File dir, String name, InputStream in) throws Exception { log.info(" ZIP: " + name); try {//from ww w.j av a 2s. com ZipInputStream zip = new ZipInputStream(in, charset.get()); ZipEntry entry = null; File subdir = dir; while ((entry = zip.getNextEntry()) != null) { if (entry.isDirectory()) { subdir = new File(subdir, entry.getName()); subdir.mkdirs(); } else { String path = FilenameUtils.getPath(entry.getName()); File filedir = subdir; if (!StringUtils.isBlank(path)) { filedir = new File(subdir, path); filedir.mkdirs(); } handle(filedir, FilenameUtils.getName(entry.getName()), null, zip); } } } catch (Exception e) { if (e instanceof IllegalArgumentException || "MALFORMED".equals(e.getMessage())) { throw new IOException("Wrong charset: " + charset.get().displayName(), e); } else { throw e; } } }
From source file:org.sonatype.nexus.proxy.attributes.DefaultAttributeStorage.java
/** * Gets the file from base./*from w w w .j av a2s . co m*/ * * @param uid the uid * @param isCollection the is collection * @return the file from base */ protected File getFileFromBase(RepositoryItemUid uid) throws IOException { File repoBase = new File(getWorkingDirectory(), uid.getRepository().getId()); File result = null; String path = FilenameUtils.getPath(uid.getPath()); String name = FilenameUtils.getName(uid.getPath()); result = new File(repoBase, path + "/" + name); // to be foolproof // 2007.11.09. - Believe or not, Nexus deleted my whole USB rack! (cstamas) // ok, now you may laugh :) if (!result.getAbsolutePath().startsWith(getWorkingDirectory().getAbsolutePath())) { throw new IOException("FileFromBase evaluated directory wrongly! baseDir=" + getWorkingDirectory().getAbsolutePath() + ", target=" + result.getAbsolutePath()); } else { return result; } }