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.streamsets.pipeline.lib.el.FileEL.java

@ElFunction(prefix = "file", name = "fileExtension", description = "Returns file extension from given path (e.g. 'txt' from /path/file.txt).")
public static String fileExtension(@ElParam("filePath") String filePath) {
    if (isEmpty(filePath)) {
        return null;
    }/*from ww w .  j av a 2  s. c om*/

    return FilenameUtils.getExtension(filePath);
}

From source file:com.hs.mail.util.FileUtils.java

public static boolean isCompressed(File file, boolean checkMagic) {
    return (checkMagic) ? startsWith(file, GZIP_MAGIC_BYTES)
            : GZIP_EXTENSION.equalsIgnoreCase(FilenameUtils.getExtension(file.getName()));
}

From source file:com.nuvolect.deepdive.probe.ApkZipUtil.java

/**
 * Unzip while excluding XML files into the target directory.
 * The added structure is updated to reflect any new files and directories created.
 * Overwrite files when requested.//from   w w w.j  a v  a2 s . co m
 * @param zipOmni
 * @param targetDir
 * @param progressStream
 * @return
 */
public static boolean unzipAllExceptXML(OmniFile zipOmni, OmniFile targetDir, ProgressStream progressStream) {

    String volumeId = zipOmni.getVolumeId();
    String rootFolderPath = targetDir.getPath();
    boolean DEBUG = true;

    ZipInputStream zis = new ZipInputStream(zipOmni.getFileInputStream());
    ZipEntry entry = null;
    try {
        while ((entry = zis.getNextEntry()) != null) {

            if (entry.isDirectory()) {

                OmniFile dir = new OmniFile(volumeId, entry.getName());
                if (dir.mkdir()) {

                    if (DEBUG)
                        LogUtil.log(LogUtil.LogType.OMNI_ZIP, "dir created: " + dir.getPath());
                }
            } else {

                String path = rootFolderPath + "/" + entry.getName();
                OmniFile file = new OmniFile(volumeId, path);

                if (!FilenameUtils.getExtension(file.getName()).contentEquals("xml")) {

                    // Create any necessary directories
                    file.getParentFile().mkdirs();

                    OutputStream out = file.getOutputStream();

                    OmniFiles.copyFileLeaveInOpen(zis, out);
                    if (DEBUG)
                        LogUtil.log(LogUtil.LogType.OMNI_ZIP, "file created: " + file.getPath());

                    progressStream.putStream("Unpacked: " + entry.getName());
                }
            }
        }
        zis.close();

    } catch (IOException e) {
        LogUtil.logException(LogUtil.LogType.OMNI_ZIP, e);
        return false;
    }

    return true;
}

From source file:net.chris54721.infinitycubed.Updater.java

private static void downloadUpdate(String version) {
    try {// w w w  .  ja  va2s. c o  m
        // TODO Trigger splashscreen progressbar (run downloadable w/custom ProgressListener)
        File executable = new File(URLDecoder.decode(
                (Launcher.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()),
                "UTF-8"));
        String extension = FilenameUtils.getExtension(executable.getName());
        File updateTemp = new File(Reference.DEFAULT_FOLDER, "update." + extension);
        Downloadable update = new Downloadable(
                new URL(Reference.UPDATE_URL + extension + "/infinitycubed-" + version + "." + extension),
                updateTemp);
        if (update.download()) {
            executable.delete();
            FileUtils.moveFile(updateTemp, executable);
            Utils.restart();
        } else
            LogHelper.warn("Failed downloading launcher update: file size not matching.");
    } catch (Exception e) {
        LogHelper.error("Failed downloading launcher update", e);
    }
}

From source file:cs544.videohouse.validator.VideoConstraintValidator.java

@Override
public boolean isValid(MultipartFile video, ConstraintValidatorContext context) {
    System.out.println("inside video validation method");
    boolean valid = true;
    if (video.isEmpty()) {
        valid = false;/*from   w ww . j ava 2  s . c  om*/
    } else {
        String videoExt = FilenameUtils.getExtension(video.getOriginalFilename());
        if (!"mp4".equals(videoExt) && !"ogg".equals(videoExt) && !"ogv".equals(videoExt)
                && !"webM".equals(videoExt)) {
            valid = false;
        }
        long bytes = video.getSize();
        if (bytes > 20000000) {
            valid = false;
        }
        System.out.println("size : " + bytes);
    }
    return valid;
}

From source file:androidassetsgenerator.AssetGenerator.java

public void scaleThumbnailator(File input, String fileName, int baseIndex, String outputDir)
        throws IOException {
    asset = ImageIO.read(input);/*from  ww  w .j  a  v  a2  s .  c  o m*/

    String file = FilenameUtils.removeExtension(fileName);
    String fileExtension = FilenameUtils.getExtension(fileName);

    System.out.println(baseIndex);

    BufferedImage outputLdpi, outputMdpi, outputHdpi, outputXhdpi, outputXxhdpi, outputXxxhdpi;

    switch (baseIndex) {
    // Write from ldpi to ldpi -> kind of useless
    case 0:
        writeOutput(asset, path(fileName, outputDir, Constants.DRAWABLE_LDPI));
        break;
    // Write from mdpi to ldpi
    case 1:
        writeOutput(scale34(asset), path(fileName, outputDir, Constants.DRAWABLE_LDPI));
        break;
    // Write from hdpi to mdpi, ldpi
    case 2:
        outputMdpi = scale23(asset);
        // Write to mdpi
        writeOutput(outputMdpi, path(fileName, outputDir, Constants.DRAWABLE_MDPI));
        // Write to ldpi
        writeOutput(scale34(outputMdpi), path(fileName, outputDir, Constants.DRAWABLE_LDPI));
        break;
    // Write from xhdpi to hdpi, mdpi, ldpi
    case 3:
        outputHdpi = scale34(asset);
        outputMdpi = scale23(outputHdpi);
        // Write to hdpi
        writeOutput(outputHdpi, path(fileName, outputDir, Constants.DRAWABLE_HDPI));
        // Write to mdpi
        writeOutput(outputMdpi, path(fileName, outputDir, Constants.DRAWABLE_MDPI));
        // Write to ldpi
        writeOutput(scale34(outputMdpi), path(fileName, outputDir, Constants.DRAWABLE_LDPI));
        break;
    // Write from xxhdpi to xhdpi, hdpi, mdpi, ldpi
    case 4:
        outputXhdpi = scale23(asset);
        outputHdpi = scale34(outputXhdpi);
        outputMdpi = scale23(outputHdpi);
        // Write to xhdpi
        writeOutput(outputXhdpi, path(fileName, outputDir, Constants.DRAWABLE_XHDPI));
        // Write to hdpi
        writeOutput(outputHdpi, path(fileName, outputDir, Constants.DRAWABLE_HDPI));
        // Write to mdpi
        writeOutput(outputMdpi, path(fileName, outputDir, Constants.DRAWABLE_MDPI));
        // Write to ldpi
        writeOutput(scale34(outputMdpi), path(fileName, outputDir, Constants.DRAWABLE_LDPI));
        break;
    // Write from xxxhdpi to xxhdpi, xhdpi, hdpi, mdpi, ldpi
    case 5:
        outputXxhdpi = scale34(asset);
        outputXhdpi = scale23(outputXxhdpi);
        outputHdpi = scale34(outputXhdpi);
        outputMdpi = scale23(outputHdpi);
        // Write to xxhdpi
        writeOutput(outputXxhdpi, path(fileName, outputDir, Constants.DRAWABLE_XXHDPI));
        // Write to xhdpi
        writeOutput(outputXhdpi, path(fileName, outputDir, Constants.DRAWABLE_XHDPI));
        // Write to hdpi
        writeOutput(outputHdpi, path(fileName, outputDir, Constants.DRAWABLE_HDPI));
        // Write to mdpi
        writeOutput(outputMdpi, path(fileName, outputDir, Constants.DRAWABLE_MDPI));
        // Write to ldpi
        writeOutput(scale34(outputMdpi), path(fileName, outputDir, Constants.DRAWABLE_LDPI));
        break;
    }

}

From source file:com.taunova.app.libview.DefaultCommandRegistry.java

protected String getExtension(File file) {
    return (file.isFile()) ? FilenameUtils.getExtension(file.getName()) : "folder";
}

From source file:net.orpiske.sdm.lib.Unpack.java

/**
 * Unpacks a file//from   w  w w  . j av a  2  s  . co  m
 * @param artifact the file to unpack
 * @param destination the destination folder to unpack the file to
 */
public static void unpack(final String artifact, final String destination) {
    Archive archive;

    String extension = FilenameUtils.getExtension(artifact);

    if (extension.equals("tbz2") || extension.equals("bz2")) {
        archive = new TbzArchive();
    } else {
        if (extension.equals("tgz") || extension.equals("gz")) {
            archive = new TgzArchive();
        } else {
            if (extension.equals("zip")) {
                archive = new ZipArchive();
            } else {
                throw new UnsupportedFormat("Unsupported format: " + extension);
            }
        }
    }

    try {
        String source = artifact;

        archive.unpack(source, destination);
    } catch (SspsArchiveException e) {
        cleanup(artifact, destination);

        throw new UnpackException(e.getMessage(), e);

    }
}

From source file:controllers.base.Application.java

public static String minifyInProd(String file, Boolean neverMinify) {
    if (Play.isProd() && !ObjectUtils.defaultIfNull(neverMinify, false)) {
        String path = FilenameUtils.getFullPath(file);
        String name = FilenameUtils.getBaseName(file);
        String ext = FilenameUtils.getExtension(file);

        if (!name.toLowerCase().endsWith(".min")) {
            return String.format("%s%s.min.%s", path, name, ext);
        }// w  ww .  jav  a2 s . com
    }

    return file;
}

From source file:eu.mrbussy.pdfsplitter.Splitter.java

/**
 * Split the given PDF file into multiple files using pages.
 * /*from  ww w  .  java 2s.  c  om*/
 * @param filename
 *            - Name of the PDF to split
 * @param useSubFolder
 *            - Use a separate folder to place the files in.
 */
public static void Run(File file, boolean useSubFolder) {
    PdfReader reader = null;
    String format = null;

    if (useSubFolder) {
        format = "%1$s%2$s%4$s"; // Directory format
        try {
            FileUtils.forceMkdir(
                    new File(String.format(format, FilenameUtils.getFullPath(file.getAbsolutePath()),
                            FilenameUtils.getBaseName(file.getAbsolutePath()),
                            FilenameUtils.getExtension(file.getAbsolutePath()), IOUtils.DIR_SEPARATOR)));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        format = "%1$s%2$s%4$s%2$s_%%03d.%3$s"; // Directory format + filename
    } else
        format = "%1$s%2$s_%%03d.%3$s";

    String splitFile = String.format(format, FilenameUtils.getFullPath(file.getAbsolutePath()),
            FilenameUtils.getBaseName(file.getAbsolutePath()),
            FilenameUtils.getExtension(file.getAbsolutePath()), IOUtils.DIR_SEPARATOR);

    try {
        reader = new PdfReader(new FileInputStream(file));

        if (reader.getNumberOfPages() > 0) {
            for (int pageNum = 1; pageNum <= reader.getNumberOfPages(); pageNum++) {
                System.out.println(String.format(splitFile, pageNum));
                String filename = String.format(splitFile, pageNum);
                Document document = new Document(reader.getPageSizeWithRotation(1));
                PdfCopy writer = new PdfCopy(document, new FileOutputStream(filename));
                document.open();
                // Copy the page from the original
                PdfImportedPage page = writer.getImportedPage(reader, pageNum);
                writer.addPage(page);
                document.close();
                writer.close();
            }
        }
    } catch (Exception ex) {
        // TODO Implement exception handling
        ex.printStackTrace(System.err);
    } finally {
        if (reader != null)
            // Always close the stream
            reader.close();
    }
}