List of usage examples for org.apache.commons.io FilenameUtils getExtension
public static String getExtension(String filename)
From source file:audiomanagershell.commands.FavCommand.java
@Override public void execute() throws CommandException { Path file = Paths.get(this.pathRef.toString(), this.arg); if (!Files.exists(file)) throw new FileNotFoundException(file.getFileName().toString()); if (!Files.isRegularFile(file)) throw new NotAFileException(file.getFileName().toString()); List<String> validExtensions = Arrays.asList("wav", "mp3", "flac", "mp4"); if (!validExtensions.contains(FilenameUtils.getExtension(file.toString()))) throw new NotAudioFileException(file.toString()); try (PrintWriter output = new PrintWriter(new FileWriter(favFile.toFile(), true)); Scanner input = new Scanner(new FileReader(favFile.toString()))) { while (input.hasNextLine()) { if (input.nextLine().equals(file.toString())) { System.out.printf("File \"%s\" is already added to favorite List!%n", file); return; }/* w ww. j a va 2 s. co m*/ } System.out.printf("Added: \"%s\"%n", file); output.println(file); } catch (IOException ex) { throw new CommandException("Error related from I/O to file:" + favFile.toString()); } }
From source file:io.stallion.dataAccess.db.SqlMigration.java
public boolean isJavascript() { return FilenameUtils.getExtension(filename).equals("js"); }
From source file:com.kamike.misc.FsNameUtils.java
public static String getAttributeName(String prefix, String disk, String name, String readableName, String fid, String uid, Date date) { String extension = FilenameUtils.getExtension(name); //?/* w w w.ja v a2 s .co m*/ return getAttributeName(prefix, disk, getShortDate(date), name, readableName, fid, uid, extension); }
From source file:com.github.dozermapper.core.config.resolvers.LegacyPropertiesSettingsResolver.java
private Properties processFile() { Properties properties = new Properties(); String extension = FilenameUtils.getExtension(configFile); if (!extension.equalsIgnoreCase("properties")) { LOG.info("Ignoring, as file extension is not correct for: {}", configFile); } else {//from w w w . j a v a2 s.com LOG.info("Trying to find Dozer configuration file: {}", configFile); URL url = classLoader.loadResource(configFile); if (url == null) { LOG.info("Failed to find {} via {}.", configFile, getClass().getName()); } else { LOG.info("Using URL [{}] for Dozer settings", url); try (InputStream inputStream = url.openStream()) { properties.load(inputStream); } catch (IOException ex) { LOG.error("Failed to load: {} because: {}", configFile, ex.getMessage()); LOG.debug("Exception: ", ex); } } } return properties; }
From source file:com.telecel.controllers.UploadBean.java
public String getExtension(File file) { String ext; ext = FilenameUtils.getExtension(file.getAbsolutePath()); return ext; }
From source file:codes.thischwa.c5c.util.StringUtils.java
public static String getUniqueName(Set<String> existingNames, String name) { if (!existingNames.contains(name)) return name; int count = 1; String ext = FilenameUtils.getExtension(name); String baseName = FilenameUtils.getBaseName(name); String tmpName;/*from w w w .j a va 2 s .c o m*/ do { tmpName = String.format("%s_%d", baseName, count); if (!_isNullOrEmpty(ext)) tmpName = String.format("%s.%s", tmpName, ext); count++; } while (existingNames.contains(tmpName)); return tmpName; }
From source file:com.twosigma.beaker.core.module.elfinder.impl.commands.DuplicateCommand.java
@Override public void execute(FsService fsService, HttpServletRequest request, ServletContext servletContext, JSONObject json) throws Exception { String[] targets = request.getParameterValues("targets[]"); List<FsItemEx> added = new ArrayList<FsItemEx>(); for (String target : targets) { FsItemEx fsi = super.findItem(fsService, target); String name = fsi.getName(); String baseName = FilenameUtils.getBaseName(name); String extension = FilenameUtils.getExtension(name); int i = 1; FsItemEx newFile = null;/*from w w w.j a v a 2 s. c om*/ baseName = baseName.replaceAll("\\(\\d+\\)$", ""); while (true) { String newName = String.format("%s(%d)%s", baseName, i, (extension == null || extension.isEmpty() ? "" : "." + extension)); newFile = new FsItemEx(fsi.getParent(), newName); if (!newFile.exists()) { break; } i++; } createAndCopy(fsi, newFile); added.add(newFile); } json.put("added", files2JsonArray(request, added)); }
From source file:com.anrisoftware.prefdialog.miscswing.filechoosers.FileFilterExtension.java
/** * Tests if the specified file have the extension of the file filter. * * @param file/*w w w . j a va 2 s. c o m*/ * the {@link File}. * * @return {@code true} if the specified file have the extension of the file * filter. */ public boolean fileHaveExtension(File file) { return FilenameUtils.getExtension(file.getName()).equals(getExtension()); }
From source file:ijfx.service.batch.input.SaveToFileWrapper.java
public SaveToFileWrapper(Context context, BatchSingleInput input, File saveFile, String suffix) { this(context, input); String baseName = FilenameUtils.getBaseName(saveFile.getName()); String ext = FilenameUtils.getExtension(saveFile.getName()); String finalName = new StringBuilder().append(baseName).append(suffix).append(".").append(ext).toString(); System.out.println(finalName); saveTo = new File(saveFile.getParentFile(), finalName); }
From source file:com.foo.bar.si.file.demo.starter.TransformationHandler.java
/** * Actual Spring Integration transformation handler. * * @param inputMessage Spring Integration input message * @return New Spring Integration message with updated headers *///from w ww .jav a 2s .c o m @Transformer public Message<String> handleFile(final Message<File> inputMessage) { final File inputFile = inputMessage.getPayload(); final String filename = inputFile.getName(); final String fileExtension = FilenameUtils.getExtension(filename); final String inputAsString; try { inputAsString = FileUtils.readFileToString(inputFile); } catch (IOException e) { throw new IllegalStateException(e); } final Message<String> message = MessageBuilder.withPayload(inputAsString.toUpperCase(Locale.ENGLISH)) .setHeader(FileHeaders.FILENAME, filename).setHeader(FileHeaders.ORIGINAL_FILE, inputFile) .setHeader("file_size", inputFile.length()).setHeader("file_extension", fileExtension).build(); return message; }