List of usage examples for org.apache.commons.io FilenameUtils getExtension
public static String getExtension(String filename)
From source file:com.frostwire.gui.UniversalScanner.java
public void scan(String filePath) { try {/*from www .jav a2 s . c om*/ MediaType mt = MediaType.getMediaTypeForExtension(FilenameUtils.getExtension(filePath)); if (mt == null) { scanDocument(filePath, true); } else if (mt.equals(MediaType.getAudioMediaType())) { scanAudio(filePath, true); } else if (mt.equals(MediaType.getImageMediaType())) { scanPictures(filePath, true); } else if (mt.equals(MediaType.getVideoMediaType())) { scanVideo(filePath, true); // until we integrate mplayer for video and research metadata extraction } else { scanDocument(filePath, true); } } catch (Throwable e) { scanDocument(filePath, true); LOG.log(Level.WARNING, "Error scanning file, scanned as document: " + filePath, e); } }
From source file:Main.StaticTools.java
public static Boolean supportedRAWFileType(String name) { String ext = FilenameUtils.getExtension(name.toLowerCase()); for (String extSupported : RAWFiles) { if (ext.equals(extSupported)) return true; }//from ww w. j av a 2 s . c o m return false; }
From source file:audiomanagershell.commands.InfoCommand.java
@Override public void execute() throws CommandException { String OS = System.getProperty("os.name").toLowerCase(); Path file;/*from ww w. j a v a 2 s. c o m*/ if (OS.equals("windows")) file = Paths.get(this.pathRef.toString() + "\\" + this.arg); else file = Paths.get(this.pathRef.toString() + "/" + this.arg); String fileName = file.getFileName().toString(); List<String> acceptedExtensions = Arrays.asList("wav", "mp3", "flac"); List<String> infoWanted = Arrays.asList("title", "xmpDM:artist", "xmpDM:genre", "xmpDM:album", "xmpDM:releaseDate"); if (!Files.exists(file)) throw new FileNotFoundException(file.getFileName().toString()); if (Files.isRegularFile(file)) { //Get the extension of the file String extension = FilenameUtils.getExtension(fileName); if (acceptedExtensions.contains(extension)) { try { FileInputStream input = new FileInputStream(file.toFile()); Metadata metadata = new Metadata(); BodyContentHandler handler = new BodyContentHandler(); ParseContext pcontext = new ParseContext(); //MP3 Parser Mp3Parser AudioParser = new Mp3Parser(); AudioParser.parse(input, handler, metadata, pcontext); for (String name : infoWanted) { String[] metadataName = name.split(":"); if (metadata.get(name) != null) if (name.equals("title")) System.out.println("TITLE:" + metadata.get(name)); else System.out.println(metadataName[1].toUpperCase() + ":" + metadata.get(name)); } input.close(); } catch (IOException | TikaException | SAXException e) { e.printStackTrace(); } } else { throw new NotAudioFileException(fileName); } } else throw new NotAFileException(file.getFileName().toString()); }
From source file:com.igormaznitsa.zxpspritecorrector.files.AbstractFilePlugin.java
protected static String addNumberToFileName(final String name, final int number) { String base = FilenameUtils.getBaseName(name); final String ext = FilenameUtils.getExtension(name); return base + Integer.toString(number) + '.' + ext; }
From source file:ijfx.core.batch.item.SaveToFileWrapper.java
public SaveToFileWrapper(Context context, BatchSingleInput input, File saveFile, String suffix) { this(context, input); String baseName;//from w w w . j av a 2 s. c o m if (input.getDefaultSaveName() != null) { baseName = input.getDefaultSaveName(); } else { baseName = FilenameUtils.getBaseName(saveFile.getName()); } String ext = FilenameUtils.getExtension(saveFile.getName()); String finalName; if (suffix != null) { finalName = new StringBuilder().append(baseName).append("_").append(suffix).append(".").append(ext) .toString(); } else { finalName = new StringBuilder().append(baseName).append(".").append(ext).toString(); } saveTo = new File(saveFile.getParentFile(), finalName); }
From source file:net.rpproject.dl.download.java
/** * This method is for downloading a file from a URL. * @param fileurl The URL that the download needs to occur * @throws IOException //from w ww. j ava 2s .c o m */ private static void fileDownloader(String fileurl) throws IOException { URL url = null; OutputStream fos = null; InputStream fis = null; File file; ProgressMonitor monitor = new ProgressMonitor(); try { if (!window.getModText().equals("")) { url = new URL(fileurl); String fileName = FilenameUtils.getBaseName(fileurl); fileName = java.net.URLDecoder.decode(fileName, "UTF-8"); String extension = FilenameUtils.getExtension(fileurl); String check = fileName + "." + extension; if (!check.equals("mods.xml")) { file = new File(window.getModText()); fos = new FileOutputStream(file + "\\" + fileName + "." + extension); } else { file = new File(launcher.dataFolder + "\\RPP\\"); fos = new FileOutputStream(file + fileName + "." + extension); } fis = url.openStream(); DownloadWatcher watcher = new DownloadWatcher(fos); watcher.setListener(monitor); filesize = Double.parseDouble(url.openConnection().getHeaderField("Content-Length")); filename = fileName; IOUtils.copy(fis, watcher); } } catch (IOException | NumberFormatException e) { String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date()); Logger.getLogger("RPP").log(Level.INFO, "{0} Error Downloading file: {1}", new Object[] { timeStamp, fileurl }); Logger.getLogger("RPP").log(Level.INFO, (Supplier<String>) e); } finally { if (fos != null) { fos.close(); } if (fis != null) { fis.close(); } } }
From source file:com.blackducksoftware.ohcount4j.SourceFile.java
public String getExtension() { return FilenameUtils.getExtension(path); }
From source file:bogdanrechi.lansator.updater.App.java
/** * Set item image file//from w ww.j a v a2 s . c o m * * @param imagesPath * Images path * @param newImageFile * Newly selected image file * @param item * Item to set the image for */ public static void setItemImageFile(String imagesPath, String newImageFile, Item item) throws StringException { String imageFileNewName = Text.newGuid() + "." + FilenameUtils.getExtension(newImageFile); if (!Files.exists(imagesPath)) { Files.createFolder(imagesPath); } Files.copyFileToFolder(newImageFile, imagesPath, imageFileNewName); item.imageFile = imageFileNewName; }
From source file:com.siberhus.tdfl.DefaultDataFileHandler.java
@Override public boolean accept(String filename) { String extension = FilenameUtils.getExtension(filename); if (ignoreCase) { return extensions.contains(extension.toUpperCase()); } else {/* w w w . j av a2s . co m*/ return extensions.contains(extension); } }
From source file:cz.zcu.pia.social.network.frontend.components.profile.profile.ImageUploader.java
@Override public OutputStream receiveUpload(String filename, String mimeType) { if (filename == null) { return null; }/*from www . j a v a 2s. c om*/ // Create upload stream FileOutputStream fos; // Stream to write to try { fileService.createBasicFolders(); file = fileService.createFile(Constants.BASE_PATH + securityHelper.getLogedInUser().getId() + "-" + Math.abs((int) (Math.random() * 10000000)) + "." + FilenameUtils.getExtension(filename)); if (file == null) { Notification.show(msgs.getMessage("error.file.exists"), Notification.Type.ERROR_MESSAGE); return null; } fos = new FileOutputStream(file); } catch (final java.io.FileNotFoundException e) { logger.error(e.getMessage(), e); return null; } catch (SecurityException e) { logger.error(e.getMessage(), e); return null; } return fos; // Return the output stream to write to }