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:ie.peternagy.jcrypto.module.crypto.FileCrypto.java

public FileCrypto(String filePath) {
    curve = new EllipticCurveWrapper();
    aesWrapper = new AesWrapper(curve);
    inputFile = FileAccessUtil.getFileByName(filePath);
    inputFileString = filePath;/*from   ww w  . j  a  v a  2  s .c  om*/
    if ("enc".equals(FilenameUtils.getExtension(filePath))) {
        isEncrypt = false;
        aesWrapper.initCipher(false);
    } else {
        isEncrypt = true;
        aesWrapper.initCipher(true);
    }
}

From source file:com.sisrni.managedbean.EditorImages.java

public void uploadListener(FileUploadEvent event) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();

    String fileName = FilenameUtils.getName(event.getFile().getFileName());
    String fileNamePrefix = FilenameUtils.getBaseName(fileName) + "_";
    String fileNameSuffix = "." + FilenameUtils.getExtension(fileName);

    File uploadFolder = new File("/var/webapp/uploads");

    try {/* w  w  w  .j  a v a2s  . com*/
        File result = File.createTempFile(fileNamePrefix, fileNameSuffix, uploadFolder);

        FileOutputStream fileOutputStream = new FileOutputStream(result);
        byte[] buffer = new byte[1024];
        int bulk;

        InputStream inputStream = event.getFile().getInputstream();
        while (true) {
            bulk = inputStream.read(buffer);
            if (bulk < 0) {
                break;
            }

            fileOutputStream.write(buffer, 0, bulk);
            fileOutputStream.flush();
        }

        fileOutputStream.close();
        inputStream.close();

        String value = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
                .get("editor_input");
        setText(value + "<img src=\"/rais/uploads/" + result.getName() + "\" />");

        RequestContext.getCurrentInstance().update("editor_input");

        FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
        FacesContext.getCurrentInstance().addMessage(null, msg);

    } catch (IOException e) {
        e.printStackTrace();
        FacesMessage error = new FacesMessage("The files were not uploaded!");
        FacesContext.getCurrentInstance().addMessage(null, error);
    }

}

From source file:com.xyphos.vmtgen.FileFilterVTF.java

@Override
public boolean accept(File file) {
    if (file.isDirectory()) {
        return true;
    }/* w  w  w . j a  v a2 s.c  o  m*/
    return FilenameUtils.getExtension(file.getName()).equalsIgnoreCase("vtf");
}

From source file:egovframework.com.utl.wed.filter.DirectoryPathManager.java

public static File getUniqueFile(final File file) {
    if (!file.exists())
        return file;

    File tmpFile = new File(file.getAbsolutePath());
    File parentDir = tmpFile.getParentFile();
    int count = 1;
    String extension = FilenameUtils.getExtension(tmpFile.getName());
    String baseName = FilenameUtils.getBaseName(tmpFile.getName());
    do {/*from w  w w  .  j a  v  a  2s . com*/
        tmpFile = new File(parentDir, baseName + "_" + count++ + "_." + extension);
    } while (tmpFile.exists());
    return tmpFile;
}

From source file:io.fabric8.maven.core.util.ResourceFileType.java

public static ResourceFileType fromFile(File file) {
    String ext = FilenameUtils.getExtension(file.getPath());
    if (StringUtils.isNotBlank(ext)) {
        return fromExtension(ext);
    } else {//w ww.ja va  2  s.c om
        throw new IllegalArgumentException(
                String.format("Unsupported extension '%s' for file %s. Must be one of %s", ext, file,
                        Arrays.asList(values())));
    }
}

From source file:com.ucb.stylometer.parser.StylemeterParser.java

public String parse() {
    String fileExtension, sample = null;

    try {//from  www  .jav  a 2  s  . c o  m
        fileExtension = FilenameUtils.getExtension(filePath);
        switch (fileExtension) {
        case "txt":
            sample = new TXTParser().parse(filePath);
            break;
        default:
            throw new UnsupportedOperationException("There is no parser for this type of file.");
        }
    } catch (UnsupportedOperationException ex) {
        Logger.getLogger(StylemeterParser.class.getName()).log(Level.SEVERE, "File parsing failed.", ex);
    }

    return sample;
}

From source file:de.uni_siegen.wineme.come_in.thumbnailer.util.mime.ScratchFileIdentifier.java

@Override
public String identify(String mimeType, byte[] bytes, File file) {
    if (mimeType == null && SCRATCH_EXTENSION.equals(FilenameUtils.getExtension(file.getName())))
        return SCRATCH_MIME_TYPE;

    if (startWith(bytes, MAGIC_SCRATCH_HEADER))
        return SCRATCH_MIME_TYPE;

    return mimeType;
}

From source file:Main.StaticTools.java

public static Boolean supportedVideoFileType(String name) {
    String ext = FilenameUtils.getExtension(name.toLowerCase());
    for (String extSupported : videoFiles) {
        if (ext.equals(extSupported))
            return true;
    }/*w  ww  . j  a  va  2  s .co  m*/
    return false;
}

From source file:controllers.PdfGenerator.java

public void addTemporaryFonts(List<String> fontsToLoad) {
    if (defaultFonts == null)
        defaultFonts = new ArrayList<String>();
    for (String font : fontsToLoad) {
        try {/*from  w  ww .  jav  a 2s.  co  m*/
            InputStream fin = Play.application().resourceAsStream(font);
            final File tempFile = File.createTempFile("tmp_" + FilenameUtils.getBaseName(font),
                    "." + FilenameUtils.getExtension(font));
            tempFile.deleteOnExit();
            FileOutputStream out = new FileOutputStream(tempFile);
            IOUtils.copy(fin, out);
            defaultFonts.add(tempFile.getAbsolutePath());
        } catch (Exception e) {
            Logger.error("Loading fonts", e);
        }
    }
}

From source file:com.astamuse.asta4d.web.WebApplicatoinConfigurationInitializer.java

public void initConfigurationFromFile(ServletConfig sc, WebApplicationConfiguration conf) throws Exception {
    String[] fileNames = retrievePossibleConfigurationFileNames();
    InputStream input = null;//from   w w  w. ja  v  a  2  s. co  m
    String fileType = null;

    // find file from classpath
    ClassLoader clsLoder = WebApplicatoinConfigurationInitializer.class.getClassLoader();
    for (String name : fileNames) {
        input = clsLoder.getResourceAsStream(name);
        if (input != null) {
            fileType = FilenameUtils.getExtension(name);
            break;
        }
    }

    // find from file system
    // I can do goto by while loop :)
    while (input == null) {

        // find key
        String fileKey = retrieveConfigurationFileNameKey();
        if (fileKey == null) {
            break;
        }

        // get path
        String filePath = retrieveConfigurationFileName(sc, fileKey);
        if (filePath == null) {
            break;
        }

        // load file
        File f = new File(filePath);
        input = new FileInputStream(f);
        fileType = FilenameUtils.getExtension(filePath);
        break;
    }

    if (input != null) {
        try {
            Initializer initializer = retrieveInitializer(fileType);
            initializer.initliaze(input, conf);
        } finally {
            input.close();
        }
    }
}