List of usage examples for org.apache.commons.io FilenameUtils isExtension
public static boolean isExtension(String filename, Collection<String> extensions)
From source file:com.moki.touch.util.UrlUtil.java
/** * This method determines if the url passed in is the location of a image that we can download * @param url a valid url to a image/*from w w w . ja v a 2s.c o m*/ * @return true for valid image urls or false */ public static boolean isContentImage(String url) { return FilenameUtils.isExtension(url, imageExtentions); }
From source file:com.google.mr4c.content.ContentTypes.java
public static Collection<String> filterByContentType(Collection<String> fileNames, final String contentType, final boolean canonicalOnly) { return CollectionUtils.predicatedCollection(fileNames, new Predicate() { public boolean evaluate(Object obj) { String name = (String) obj; if (canonicalOnly) { String suffix = ContentTypes.getSuffix(contentType); return FilenameUtils.isExtension(name, suffix); } else { Collection<String> suffixes = ContentTypes.getSuffixes(contentType); return FilenameUtils.isExtension(name, suffixes); }//from w ww . j a v a2 s. c om } }); }
From source file:com.iyonger.apm.web.handler.ScriptHandler.java
/** * Check if the given fileEntry can be handled by this handler. * * @param fileEntry fileEntry to be checked * @return true if the given fileEntry can be handled *//*ww w . j a va 2 s. c o m*/ public boolean canHandle(FileEntry fileEntry) { return FilenameUtils.isExtension(fileEntry.getPath(), getExtension()); }
From source file:com.mirth.connect.client.ui.components.MirthTableTransferHandler.java
@Override public boolean canImport(TransferSupport support) { if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { try {// w ww.ja va 2 s .c o m List<File> fileList = (List<File>) support.getTransferable() .getTransferData(DataFlavor.javaFileListFlavor); for (File file : fileList) { if (!FilenameUtils.isExtension(file.getName(), "xml")) { return false; } } return true; } catch (Exception e) { // Return true anyway until this bug is fixed: // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6759788 return true; } } return false; }
From source file:ch.ifocusit.livingdoc.plugin.baseMojo.AbstractAsciidoctorMojo.java
protected File getOutput(String filename, AbstractDocsGeneratorMojo.Format desiredExtension) { filename = FilenameUtils.isExtension(filename, desiredExtension.name()) ? filename : filename + "." + desiredExtension; return new File(generatedDocsDirectory, filename); }
From source file:com.dp2345.service.impl.FileServiceImpl.java
public boolean isValid(FileType fileType, MultipartFile multipartFile) { if (multipartFile == null) { return false; }//from w ww . j av a 2 s .c o m Setting setting = SettingUtils.get(); if (setting.getUploadMaxSize() != null && setting.getUploadMaxSize() != 0 && multipartFile.getSize() > setting.getUploadMaxSize() * 1024L * 1024L) { return false; } String[] uploadExtensions; if (fileType == FileType.flash) { uploadExtensions = setting.getUploadFlashExtensions(); } else if (fileType == FileType.media) { uploadExtensions = setting.getUploadMediaExtensions(); } else if (fileType == FileType.file) { uploadExtensions = setting.getUploadFileExtensions(); } else { uploadExtensions = setting.getUploadImageExtensions(); } if (ArrayUtils.isNotEmpty(uploadExtensions)) { return FilenameUtils.isExtension(multipartFile.getOriginalFilename(), uploadExtensions); } return false; }
From source file:com.sammyun.service.impl.FileServiceImpl.java
public boolean isValid(FileType fileType, MultipartFile multipartFile) { if (multipartFile == null) { return false; }/*from ww w .j a v a 2 s . co m*/ Setting setting = SettingUtils.get(); if (setting.getUploadMaxSize() != null && setting.getUploadMaxSize() != 0 && multipartFile.getSize() > setting.getUploadMaxSize() * 1024L * 1024L) { return false; } String[] uploadExtensions; if (fileType == FileType.flash) { uploadExtensions = setting.getUploadFlashExtensions(); } else if (fileType == FileType.media) { uploadExtensions = setting.getUploadMediaExtensions(); } else if (fileType == FileType.file) { uploadExtensions = setting.getUploadFileExtensions(); } else { uploadExtensions = setting.getUploadImageExtensions(); } if (ArrayUtils.isNotEmpty(uploadExtensions)) { String originalFilename = multipartFile.getOriginalFilename(); return FilenameUtils.isExtension(originalFilename.toLowerCase(), uploadExtensions); } return false; }
From source file:com.frostwire.android.gui.util.FileUtils.java
/** Given a folder path it'll return all the files contained within it and it's subfolders * as a flat set of Files.// w w w . j a va 2s . c o m * * Non-recursive implementation, up to 20% faster in tests than recursive implementation. :) * * @author gubatron * @param folder * @param extensions If you only need certain files filtered by their extensions, use this string array (without the "."). or set to null if you want all files. e.g. ["txt","jpg"] if you only want text files and jpegs. * * @return The set of files. */ public static Collection<File> getAllFolderFiles(File folder, String[] extensions) { Set<File> results = new HashSet<File>(); Stack<File> subFolders = new Stack<File>(); File currentFolder = folder; while (currentFolder != null && currentFolder.isDirectory() && currentFolder.canRead()) { File[] fs = null; try { fs = currentFolder.listFiles(); } catch (SecurityException e) { } if (fs != null && fs.length > 0) { for (File f : fs) { if (!f.isDirectory()) { if (extensions == null || FilenameUtils.isExtension(f.getName(), extensions)) { results.add(f); } } else { subFolders.push(f); } } } if (!subFolders.isEmpty()) { currentFolder = subFolders.pop(); } else { currentFolder = null; } } return results; }
From source file:gobblin.compaction.mapreduce.avro.AvroKeyCompactorOutputCommitter.java
/** * Commits the task, moving files to their final committed location by delegating to * {@link FileOutputCommitter} to perform the actual moving. First, renames the * files to include the count of records contained within the file and a timestamp, * in the form {recordCount}.{timestamp}.avro. Then, the files are moved to their * committed location.//from w w w . jav a 2s .com */ @Override public void commitTask(TaskAttemptContext context) throws IOException { Path workPath = getWorkPath(); FileSystem fs = workPath.getFileSystem(context.getConfiguration()); if (fs.exists(workPath)) { long recordCount = getRecordCountFromCounter(context, AvroKeyDedupReducer.EVENT_COUNTER.RECORD_COUNT); String fileNamePrefix; if (recordCount == 0) { // recordCount == 0 indicates that it is a map-only, non-dedup job, and thus record count should // be obtained from mapper counter. fileNamePrefix = CompactionRecordCountProvider.M_OUTPUT_FILE_PREFIX; recordCount = getRecordCountFromCounter(context, AvroKeyMapper.EVENT_COUNTER.RECORD_COUNT); } else { fileNamePrefix = CompactionRecordCountProvider.MR_OUTPUT_FILE_PREFIX; } String fileName = CompactionRecordCountProvider.constructFileName(fileNamePrefix, recordCount); for (FileStatus status : fs.listStatus(workPath, new PathFilter() { @Override public boolean accept(Path path) { return FilenameUtils.isExtension(path.getName(), "avro"); } })) { Path newPath = new Path(status.getPath().getParent(), fileName); LOG.info(String.format("Renaming %s to %s", status.getPath(), newPath)); fs.rename(status.getPath(), newPath); } } super.commitTask(context); }
From source file:de.mgd.simplesoundboard.dao.FileSystemSoundResourceDao.java
private boolean isMediaFile(final File file) { return file.isFile() && FilenameUtils.isExtension(StringUtils.lowerCase(file.getName()), FILE_TYPES); }