/** * Returns the file extension of a given file * * @param path the path to the file * @return the file extension * @deprecated see {@link FileUtils#getExtension(String)} */ public static String getFileExtension(String path) { return FileUtils.getExtension(path); }
/** * Extracts the file extension from a file path. * * @param path the path to the file (relative or absolute) * @return the file extension (excluding the dot), or the empty string when * the file name does not contain dots */ public static String getExtension(final String path) { return getExtension(new File(path)); }
/** * Extracts the file extension from a file path. * * @param path the path to the file (relative or absolute) * @return the file extension (excluding the dot), or the empty string when * the file name does not contain dots */ public static String getExtension(final String path) { return getExtension(new File(path)); }
public boolean canHandleFile(final File file) { final String extension = FileUtils.getExtension(file); if ("".equals(extension)) return false; return byExtension.containsKey(extension); }
public boolean canHandleFile(final String fileName) { final String extension = FileUtils.getExtension(fileName); if ("".equals(extension)) return false; return byExtension.containsKey(extension); }
public boolean canHandleFile(final String fileName) { final String extension = FileUtils.getExtension(fileName); if ("".equals(extension)) return false; return byExtension.containsKey(extension); }
public boolean canHandleFile(final File file) { final String extension = FileUtils.getExtension(file); if ("".equals(extension)) return false; return byExtension.containsKey(extension); }
@Override default boolean supports(final File file) { for (final String ext : getExtensions()) { if (FileUtils.getExtension(file).equalsIgnoreCase(ext)) return true; } return false; }
@Override default boolean supports(final File file) { for (final String ext : getExtensions()) { if (FileUtils.getExtension(file).equalsIgnoreCase(ext)) return true; } return false; }
/** * Cache a file locally. * * @param url * the URL of the file to cache * @param evenLocal * force "caching" even local files, e.g. to transform the files * without destroying the original contents * @return the cached file, or the original file if nothing was cached * @throws IOException */ protected File cacheFile(final URL url, boolean evenLocal) throws IOException { if (!evenLocal && isLocal(url)) return new File(url.getPath()); String extension = FileUtils.getExtension(url.getFile()); if (extension.startsWith("jar-")) extension = "jar"; final File result = File.createTempFile("diff-", "".equals(extension) ? "" : "." + extension); result.deleteOnExit(); copy(util.openStream(url), new FileOutputStream(result), true, true); return result; }
/** Gets the scripting language of the script. */ public ScriptLanguage getLanguage() { if (scriptLanguage == null) { // infer the language from the script path's extension final String scriptPath = getPath(); if (scriptPath != null) { // use language associated with the script path extension final String extension = FileUtils.getExtension(scriptPath); scriptLanguage = scriptService.getLanguageByExtension(extension); } else { // use the highest priority language final List<ScriptLanguage> langs = scriptService.getLanguages(); if (langs != null && !langs.isEmpty()) scriptLanguage = langs.get(0); } } return scriptLanguage; }
/** Gets the scripting language of the script. */ public ScriptLanguage getLanguage() { if (scriptLanguage == null) { // infer the language from the script path's extension final String scriptPath = getPath(); if (scriptPath != null) { // use language associated with the script path extension final String extension = FileUtils.getExtension(scriptPath); scriptLanguage = scriptService.getLanguageByExtension(extension); } else { // use the highest priority language final List<ScriptLanguage> langs = scriptService.getLanguages(); if (langs != null && !langs.isEmpty()) scriptLanguage = langs.get(0); } } return scriptLanguage; }
@Test public void testGetExtension() { assertEquals("ext", FileUtils.getExtension("/path/to/file.ext")); assertEquals("", FileUtils.getExtension("/path/to/file")); assertEquals("a", FileUtils.getExtension("/etc/init.d/xyz/file.a")); assertEquals("", FileUtils.getExtension("/etc/init.d/xyz/file")); }