Example usage for org.apache.commons.io FilenameUtils getExtension

List of usage examples for org.apache.commons.io FilenameUtils getExtension

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils getExtension.

Prototype

public static String getExtension(String filename) 

Source Link

Document

Gets the extension of a filename.

Usage

From source file:com.opendoorlogistics.components.geocode.postcodes.impl.SummaryPanel.java

public void setFile(ODLApi api, String filename) {
    if (filename != null) {
        File file = PCConstants.resolvePostcodeFile(api, new File(filename));
        if (file.exists()) {
            if (file.isFile() && FilenameUtils.getExtension(filename).toLowerCase()
                    .equals(PCConstants.DBFILE_EXTENSION)) {
                text.setText("Currently parsing: " + System.lineSeparator() + filename);
                ParseFileWorker parseFileWorker = new ParseFileWorker(file);
                parseFileWorker.execute();
            } else {
                text.setText("File is not a postcode geocode file (." + PCConstants.DBFILE_EXTENSION + "): "
                        + System.lineSeparator() + filename);
            }/*from  w  w w. ja va 2  s .  com*/

        } else {
            text.setText("File does not exist: " + System.lineSeparator() + filename);
        }
    } else {
        text.setText("No file set");
    }
}

From source file:net.sf.jvifm.util.AutoCompleteUtil.java

public static void _initSysExeNameList() {
    sysExeNameList = new ArrayList<String>();

    String pathStr = System.getenv("PATH");
    String[] paths = pathStr.split(";");
    for (String path : paths) {
        File file = new File(path);
        if (!file.exists())
            continue;
        File[] subFiles = file.listFiles();
        if (subFiles == null)
            continue;
        for (File subFile : subFiles) {
            String ext = FilenameUtils.getExtension(subFile.getPath());
            if (isExecuteFile(ext)) {
                sysExeNameList.add(subFile.getAbsolutePath());
            }// w w w .  ja  v  a2s .  co m
        }
    }
}

From source file:net.orpiske.ssps.common.repository.search.RepositoryWalker.java

@Override
protected void handleFile(File file, int depth, Collection results) throws IOException

{
    String ext = FilenameUtils.getExtension(file.getName());

    if (("groovy").equals(ext)) {
        PackageInfo packageInfo;/* www  .  j  a  v a 2s . com*/

        try {
            packageInfo = PackageDataUtils.read(file, new PackageInfo());

            if (packageInfo != null) {
                packageInfo.setRepository(repositoryName);

                packageList.add(packageInfo);
            }
        } catch (Exception e) {
            logger.error("Unable to load metadata for package: " + file.getPath());
        }
    }
}

From source file:com.limegroup.gnutella.gui.search.AbstractUISearchResult.java

public AbstractUISearchResult(FileSearchResult sr, SearchEngine se, String query) {
    this.sr = sr;
    this.se = se;
    this.query = query;
    this.extension = FilenameUtils.getExtension(sr.getFilename());
}

From source file:de.yaio.services.metaextract.server.extractor.TesseractExtractor.java

@Override
public String extractText(final InputStream input, final String fileName, final String lang)
        throws IOException, ExtractorException {
    File tmpFile;/* www.ja  va2  s.c o  m*/
    tmpFile = File.createTempFile("metaextractor", "." + FilenameUtils.getExtension(fileName));
    tmpFile.deleteOnExit();
    Files.copy(input, tmpFile.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
    return this.extractText(tmpFile, lang);
}

From source file:de.sanandrew.mods.turretmod.registry.electrolytegen.ElectrolyteRegistry.java

private static boolean processJson(Path root, Path file) {
    if (!"json".equals(FilenameUtils.getExtension(file.toString()))
            || root.relativize(file).toString().startsWith("_")) {
        return true;
    }//from w  ww .  ja  v  a  2 s .co  m

    try (BufferedReader reader = Files.newBufferedReader(file)) {
        JsonObject json = JsonUtils.fromJson(reader, JsonObject.class);

        if (json == null || json.isJsonNull()) {
            throw new JsonSyntaxException("Json cannot be null");
        }

        NonNullList<ItemStack> inputItems = JsonUtils.getItemStacks(json.get("electrolytes"));
        float effectiveness = JsonUtils.getFloatVal(json.get("effectiveness"));
        int ticksProcessing = JsonUtils.getIntVal(json.get("timeProcessing"));
        ItemStack trash = ItemStackUtils.getEmpty();
        ItemStack treasure = ItemStackUtils.getEmpty();

        JsonElement elem = json.get("trash");
        if (elem != null && !elem.isJsonNull()) {
            trash = JsonUtils.getItemStack(elem);
        }
        elem = json.get("treasure");
        if (elem != null && !elem.isJsonNull()) {
            treasure = JsonUtils.getItemStack(elem);
        }

        registerFuels(inputItems, effectiveness, ticksProcessing, trash, treasure);
    } catch (JsonParseException e) {
        TmrConstants.LOG.log(Level.ERROR,
                String.format("Parsing error loading electrolyte generator recipe from %s", file), e);
        return false;
    } catch (IOException e) {
        TmrConstants.LOG.log(Level.ERROR, String.format("Couldn't read recipe from %s", file), e);
        return false;
    }

    return true;
}

From source file:com.themodernway.server.core.file.FileUtils.java

public static final String extn(String path) {
    if (null != (path = normalize(path))) {
        return StringOps.toTrimOrNull(FilenameUtils.getExtension(path));
    }//from  ww w .  j  a  v a  2  s .c  o  m
    return path;
}

From source file:cs544.videohouse.controller.VideoController.java

@RequestMapping(value = "/upload", method = RequestMethod.POST)
public String checkUploadVideo(@Validated Video video, BindingResult result,
        final RedirectAttributes redirectAttributes) {
    String view = "upload";
    String videoExt = FilenameUtils.getExtension(video.getFile().getOriginalFilename());
    System.out.println("extension : " + videoExt);
    video.setType(videoExt);/*from   w w w  . j  av  a 2 s.c o m*/
    String imageExt = FilenameUtils.getExtension(video.getImage().getOriginalFilename());
    System.out.println("extension : " + videoExt);
    video.setType(videoExt);
    video.setImageType(imageExt);
    video.setDate(Utility.getCurrentDate());
    System.out.println(result.toString());
    if (result.hasErrors()) {
        //  return new ModelAndView("upload", "command", video);
        return view;
    } else {
        videoService.uploadVideo(video);
        redirectAttributes.addFlashAttribute("successMessage",
                video.getTitle() + " video successfully uploaded.");
        // save file;
        System.out.println("save");
        view = "redirect:/upload" + "#" + video.getTitle() + "#" + video.getId();
        return view;
    }
}

From source file:com.flipkart.poseidon.api.APIManager.java

public static void scanAndAdd(Path dir, List<String> validConfigs) {
    try (DirectoryStream<Path> files = Files.newDirectoryStream(dir)) {
        for (Path entry : files) {
            File file = entry.toFile();
            if (file.isDirectory()) {
                scanAndAdd(entry, validConfigs);
                continue;
            }//  www.  j av  a 2  s  . c o  m
            if ("json".equals(FilenameUtils.getExtension(file.getName()))) {
                try {
                    String config = FileUtils.readFileToString(file);
                    if (validateConfig(config)) {
                        validConfigs.add(config);
                    }
                } catch (IOException e) {
                    logger.error(
                            "Unable to read one of the local config. Filename = [[" + file.getName() + "]]");
                }
            }
        }
    } catch (IOException e) {
        logger.error("Local override directory not found.");
    }

}

From source file:com.doplgangr.secrecy.filesystem.files.EncryptedFile.java

/**
 * Loads an existing encrypted file from the file system.
 *//*from   ww  w. j  a  va  2  s  .  c  o m*/
EncryptedFile(File file, Crypter crypter, EncryptedThumbnail encryptedThumbnail) throws FileNotFoundException {
    this.file = file;
    this.crypter = crypter;
    this.encryptedThumbnail = encryptedThumbnail;

    if (!file.exists()) {
        throw new FileNotFoundException();
    }
    try {
        decryptedFileName = crypter.getDecryptedFileName(file);
    } catch (Exception e) {
        //Ignored
    }

    fileExtension = FilenameUtils.getExtension(decryptedFileName);
    this.fileSize = humanReadableByteCount(file.length());
    timestamp = new Date(file.lastModified());
}