List of usage examples for org.apache.commons.io FilenameUtils getName
public static String getName(String filename)
From source file:com.abiquo.api.util.snapshot.SnapshotUtils.java
/** * Generates a snapshot filename of a certain {@link VirtualMachineTemplate}. * //from w w w .j a v a2s .c o m * @param template The {@link VirtualMachineTemplate} to consider * @return The snapshot filename */ public static String formatSnapshotFilename(final VirtualMachineTemplate template) { String name = FilenameUtils.getName(template.getPath()); if (!template.isMaster()) { name = FilenameUtils.getName(template.getMaster().getPath()); } return String.format("%s-snapshot-%s", UUID.randomUUID().toString(), name); }
From source file:com.logsniffer.model.file.RollingLogsSource.java
protected Log[] getPastLogs(final String liveLog) throws IOException { final File dir = new File(FilenameUtils.getFullPathNoEndSeparator(liveLog)); final String pastPattern = FilenameUtils.getName(liveLog) + getPastLogsSuffixPattern(); final FileFilter fileFilter = new WildcardFileFilter(pastPattern); final File[] files = dir.listFiles(fileFilter); final FileLog[] logs = new FileLog[files.length]; Arrays.sort(files, getPastLogsType().getPastComparator()); int i = 0;//from www .ja v a 2 s . c om for (final File file : files) { // TODO Decouple direct file log association logs[i++] = new FileLog(file); } logger.debug("Found {} past logs for {} with pattern {}", logs.length, liveLog, pastPattern); return logs; }
From source file:io.stallion.utils.ResourceHelpers.java
public static List<String> listFilesInDirectory(String plugin, String path) { String ending = ""; String starting = ""; if (path.contains("*")) { String[] parts = StringUtils.split(path, "*", 2); String base = parts[0];/*from w ww .j a v a 2 s. co m*/ if (!base.endsWith("/")) { path = new File(base).getParent(); starting = FilenameUtils.getName(base); } else { path = base; } ending = parts[1]; } Log.info("listFilesInDirectory Parsed Path {0} starting:{1} ending:{2}", path, starting, ending); URL url = PluginRegistry.instance().getJavaPluginByName().get(plugin).getClass().getResource(path); Log.info("URL: {0}", url); List<String> filenames = new ArrayList<>(); URL dirURL = getClassForPlugin(plugin).getResource(path); Log.info("Dir URL is {0}", dirURL); // Handle file based resource folder if (dirURL != null && dirURL.getProtocol().equals("file")) { String fullPath = dirURL.toString().substring(5); File dir = new File(fullPath); // In devMode, use the source resource folder, rather than the compiled version if (Settings.instance().getDevMode()) { String devPath = fullPath.replace("/target/classes/", "/src/main/resources/"); File devFolder = new File(devPath); if (devFolder.exists()) { dir = devFolder; } } Log.info("List files from folder {0}", dir.getAbsolutePath()); List<String> files = list(); for (String name : dir.list()) { if (!empty(ending) && !name.endsWith(ending)) { continue; } if (!empty(starting) && !name.endsWith("starting")) { continue; } // Skip special files, hidden files if (name.startsWith(".") || name.startsWith("~") || name.startsWith("#") || name.contains("_flymake.")) { continue; } filenames.add(path + name); } return filenames; } if (dirURL.getProtocol().equals("jar")) { /* A JAR path */ String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); //strip out only the JAR file JarFile jar = null; try { jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8")); } catch (IOException e) { throw new RuntimeException(e); } if (path.startsWith("/")) { path = path.substring(1); } Enumeration<JarEntry> entries = jar.entries(); //gives ALL entries in jar Set<String> result = new HashSet<String>(); //avoid duplicates in case it is a subdirectory while (entries.hasMoreElements()) { String name = entries.nextElement().getName(); Log.finer("Jar file entry: {0}", name); if (name.startsWith(path)) { //filter according to the path String entry = name.substring(path.length()); int checkSubdir = entry.indexOf("/"); if (checkSubdir >= 0) { // if it is a subdirectory, we just return the directory name entry = entry.substring(0, checkSubdir); } if (!empty(ending) && !name.endsWith(ending)) { continue; } if (!empty(starting) && !name.endsWith("starting")) { continue; } // Skip special files, hidden files if (name.startsWith(".") || name.startsWith("~") || name.startsWith("#") || name.contains("_flymake.")) { continue; } result.add(entry); } } return new ArrayList<>(result); } throw new UnsupportedOperationException("Cannot list files for URL " + dirURL); /* try { URL url1 = getClassForPlugin(plugin).getResource(path); Log.info("URL1 {0}", url1); if (url1 != null) { Log.info("From class folder contents {0}", IOUtils.toString(url1)); Log.info("From class folder contents as stream {0}", IOUtils.toString(getClassForPlugin(plugin).getResourceAsStream(path))); } URL url2 = getClassLoaderForPlugin(plugin).getResource(path); Log.info("URL1 {0}", url2); if (url2 != null) { Log.info("From classLoader folder contents {0}", IOUtils.toString(url2)); Log.info("From classLoader folder contents as stream {0}", IOUtils.toString(getClassLoaderForPlugin(plugin).getResourceAsStream(path))); } } catch (IOException e) { Log.exception(e, "error loading path " + path); } // Handle jar based resource folder try( InputStream in = getResourceAsStream(plugin, path); BufferedReader br = new BufferedReader( new InputStreamReader( in ) ) ) { String resource; while( (resource = br.readLine()) != null ) { Log.finer("checking resource for inclusion in directory scan: {0}", resource); if (!empty(ending) && !resource.endsWith(ending)) { continue; } if (!empty(starting) && !resource.endsWith("starting")) { continue; } // Skip special files, hidden files if (resource.startsWith(".") || resource.startsWith("~") || resource.startsWith("#") || resource.contains("_flymake.")) { continue; } Log.finer("added resource during directory scan: {0}", resource); filenames.add(path + resource); } } catch (IOException e) { throw new RuntimeException(e); } return filenames; */ }
From source file:com.adobe.cq.wcm.core.components.Utils.java
/** * Provided a test base folder ({@code testBase}) and a virtual resource path ({@code testResourcePath}), this method generates the * class path resource path for the JSON files that represent the expected exporter output for a component. The returned value is * generated using the following concatenation operation: * * <pre>//from ww w. ja va 2 s. c o m * testBase + '/exporter-' + fileName(testResourcePath) + '.json' * </pre> * * For example: * <pre> * testBase = '/form/button' * testResourcePath = '/content/buttons/button' * output = '/form/button/exporter-button.json' * </pre> * * @param testBase the test base folder (under the {@code src/test/resources} folder) * @param testResourcePath the test resource path in the virtual repository * @return the expected class path location of the JSON exporter file */ public static String getTestExporterJSONPath(String testBase, String testResourcePath) { return testBase + "/exporter-" + FilenameUtils.getName(testResourcePath) + ".json"; }
From source file:eu.esdihumboldt.hale.ui.service.project.RecentFilesMenu.java
/** * @see ContributionItem#fill(Menu, int) *///from ww w. j a va 2 s . co m @Override public void fill(final Menu menu, int index) { RecentFilesService rfs = (RecentFilesService) PlatformUI.getWorkbench() .getService(RecentFilesService.class); RecentFilesService.Entry[] entries = rfs.getRecentFiles(); if (entries == null || entries.length == 0) { return; } // add separator new MenuItem(menu, SWT.SEPARATOR, index); int i = entries.length; for (RecentFilesService.Entry entry : entries) { String file = entry.getFile(); MenuItem mi = new MenuItem(menu, SWT.PUSH, index); String filename = FilenameUtils.getName(file); String shortened = shorten(file, MAX_LENGTH, filename.length()); String nr = String.valueOf(i); if (i <= 9) { // add mnemonic for the first 9 items nr = "&" + nr; //$NON-NLS-1$ } mi.setText(nr + " " + shortened); //$NON-NLS-1$ mi.setData(file); mi.addSelectionListener(new MenuItemSelectionListener(new File(file))); --i; } }
From source file:alluxio.util.io.PathUtils.java
/** * Gets the parent of the file at a path. * * @param path The path//from ww w .java2s .co m * @return the parent path of the file; this is "/" if the given path is the root * @throws InvalidPathException if the path is invalid */ public static String getParent(String path) throws InvalidPathException { String cleanedPath = cleanPath(path); String name = FilenameUtils.getName(cleanedPath); String parent = cleanedPath.substring(0, cleanedPath.length() - name.length() - 1); if (parent.isEmpty()) { // The parent is the root path return AlluxioURI.SEPARATOR; } return parent; }
From source file:fr.paris.lutece.portal.web.upload.NormalizeFileItem.java
/** * {@inheritDoc} */ @Override public String getName() { return UploadUtil.cleanFileName(FilenameUtils.getName(_item.getName())); }
From source file:fr.avianey.androidsvgdrawable.QualifiedResource.java
public String toString() { return FilenameUtils.getName(getAbsolutePath()); }
From source file:com.fluidops.iwb.cms.util.IWBCmsUtil.java
public static File uploadedFileFor(String filename) { try {/* w ww . j a v a2s .c o m*/ return Factory.getUpload().getFile(makeValidFilename(FilenameUtils.getName(filename))); } catch (IOException e) { throw new IllegalStateException("Cannot get uploaded file for: " + filename, e); } }
From source file:it.attocchi.utils.HttpClientUtils.java
public static String getFileNameFromUrl(String url, String paramName) { String res = null;//w w w.j ava 2s .c o m String baseName = ""; String extension = ""; if (paramName == null || paramName.isEmpty()) { baseName = FilenameUtils.getBaseName(url); extension = FilenameUtils.getExtension(url); res = FilenameUtils.getName(url); } else { String fileNameOnParam = null; List<NameValuePair> params = URLEncodedUtils.parse(url, Charset.defaultCharset()); if (params != null) for (NameValuePair p : params) { if (p.getName().contains(paramName)) { fileNameOnParam = p.getValue(); break; } } baseName = FilenameUtils.getBaseName(fileNameOnParam); extension = FilenameUtils.getExtension(fileNameOnParam); res = FilenameUtils.getName(fileNameOnParam); } return res; }