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:edu.si.services.sidora.rest.batch.ObjDsLableExtensionTest.java

@Test
public void setExtension() {
    File path = new File("src/test/resources/test-data/mimetype-test-files");

    File[] files = path.listFiles();

    for (int i = 0; i < files.length; i++) {
        if (files[i].isFile()) { //this line weeds out other directories/folders
            String objDsLabelExtension = FilenameUtils.getExtension(files[i].getPath());
            LOG.info("Found Extension: {}", objDsLabelExtension);
            assertTrue(files[i].getName().endsWith(objDsLabelExtension));
        }/*from  w w  w. j  a  v  a 2 s .com*/
    }

    String fileHttpPath = "http://sidora0c.myquotient.net/~jbirkhimer/test.jpg";
    String objDsLabelExtension = FilenameUtils.getExtension(fileHttpPath);
    LOG.info("Found Extension: {}", objDsLabelExtension);
    assertEquals("jpg", objDsLabelExtension);
}

From source file:com.sonicle.webtop.core.app.servlet.ServletHelper.java

public static String guessMediaType(String filename, String defaultMediaType) {
    String ext = FilenameUtils.getExtension(filename);
    if (!StringUtils.isBlank(ext)) {
        String mtype = WT.getOverriddenMediaType(ext);
        if (mtype != null)
            return mtype;
        mtype = ServletUtils.guessMediaType(filename);
        if (mtype != null)
            return mtype;
    }/*from  w  ww. j a  v a2s  .c om*/
    return defaultMediaType;
}

From source file:FeatureExtraction.FeatureExtractorOOXMLStructuralPathsInputStream.java

private void ExtractStructuralFeaturesInMemory(InputStream fileInputStream,
        Map<String, Integer> structuralPaths) {
    String path;/* ww w .  j av a2 s .com*/
    String directoryPath;
    String fileExtension;
    try {
        File file = new File(fileInputStream.hashCode() + "");
        try (FileOutputStream fos = new FileOutputStream(file)) {
            IOUtils.copy(fileInputStream, fos);
        }

        ZipFile zipFile = new ZipFile(file);

        for (Enumeration e = zipFile.entries(); e.hasMoreElements();) {
            ZipEntry entry = (ZipEntry) e.nextElement();
            path = entry.getName();
            directoryPath = FilenameUtils.getFullPath(path);
            fileExtension = FilenameUtils.getExtension(path);

            AddStructuralPath(directoryPath, structuralPaths);
            AddStructuralPath(path, structuralPaths);

            if (fileExtension.equals("rels") || fileExtension.equals("xml")) {
                AddXMLStructuralPaths(zipFile.getInputStream(entry), path, structuralPaths);
            }
        }
    } catch (IOException ex) {
        Console.PrintException(String.format("Error extracting OOXML structural features from file in memory"),
                ex);
    }
}

From source file:au.edu.uws.eresearch.cr8it.TransformationHandler.java

/**
 * Actual Spring Integration transformation handler.
 *
 * @param inputMessage Spring Integration input message
 * @return New Spring Integration message with updated headers
 *//*from   ww  w.jav  a 2  s  .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);

    //populate this with json-ld data
    final String inputAsString;
    String finalString = "";

    if ("zip".equals(fileExtension)) {
        inputAsString = getJsonData(inputFile, FilenameUtils.getName(filename));

        try {
            finalString = getJsonMapping(inputAsString);
        } catch (IOException | ParseException e) {
            e.printStackTrace();
        }

        if (finalString.length() > 0) {
            final Message<String> message = MessageBuilder.withPayload(finalString)
                    .setHeader(FileHeaders.FILENAME, FilenameUtils.getBaseName(filename) + ".json")
                    .setHeader(FileHeaders.ORIGINAL_FILE, inputFile)
                    .setHeader("file_size", finalString.length()).setHeader("file_extension", "json").build();

            return message;
        } else {
            System.out.println("Empty json string.");
            return null;
        }
    } else {
        System.out.println("Invalid file format");
        return null;
    }
}

From source file:com.orange.ocara.model.export.docx.AuditObjectPresenter.java

public String getIconName() {
    String extension = FilenameUtils.getExtension(value.getObjectDescription().getIcon().getPath());

    return notNull(String.format("%s.%s", value.getObjectDescriptionId(), extension));
}

From source file:fr.putnami.pwt.plugin.spring.file.server.support.DefaultFileTransfertStore.java

@Override
public OutputStream write(String fileId, String fileName, String contentType) {
    try {//from  www  . j  a v  a 2  s  .co  m
        FileDto fileDto = new FileDto();
        fileDto.setToken(fileId);
        fileDto.setName(fileName);
        fileDto.setMime(contentType);
        fileDto.setExtension(FilenameUtils.getExtension(fileName));

        this.files.put(fileId, fileDto);

        File target = new File(this.tempdir, fileId);
        Files.createParentDirs(target);
        return new FileOutputStream(target);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:de.thischwa.pmcms.view.renderer.resource.VirtualImage.java

@Override
public void analyse(File imgFile) {
    if (!InitializationManager.isImageExtention(FilenameUtils.getExtension(imgFile.getName())))
        throw new IllegalArgumentException("Image TYPE isn't supported! [" + imgFile.getPath() + "]");

    File cacheDir = PoPathInfo.getSiteImageCacheDirectory(site);
    if (FileTool.isInside(cacheDir, imgFile)) {
        String cachedPath = imgFile.getAbsolutePath().substring(cacheDir.getAbsolutePath().length());

        Matcher matcher = cachedPattern.matcher(cachedPath);
        if (matcher.matches()) {
            imageDimension = new Dimension(Integer.parseInt(matcher.group(2)),
                    Integer.parseInt(matcher.group(3)));
            File resourceDirectory = new File(PoPathInfo.getSiteDirectory(site), resourceFolder);
            baseFile = new File(resourceDirectory, Utils.join(matcher.group(1), ".", matcher.group(4)));
        } else/*from   w  w w.  ja  v  a 2 s .c om*/
            throw new FatalException("Can't analyse the cache file name!");
    } else {
        baseFile = imgFile;
    }
}

From source file:com.aliyun.odps.mapred.bridge.MockMetaExplorer.java

@Override
public String addFileResourceWithRetry(String filePath, Type type, String padding, boolean isTempResource)
        throws OdpsException {
    return FilenameUtils.getBaseName(filePath) + padding + FilenameUtils.getExtension(filePath);
}

From source file:edu.ur.ir.index.DefaultExcelTextExtractor.java

/**
 * Returns true if this can extract text from from the file. 
 * /*from   w w  w .  j a v  a 2 s.  c o  m*/
 * Simply delegates to <code>canCreateDocument(String extension)</code>
 * 
 * @see edu.ur.ir.index.FileTextExtractor#canExtractText(java.io.File)
 */
public boolean canExtractText(File f) {
    return canExtractText(FilenameUtils.getExtension(f.getName())) && !isFileTooLarge(f);
}

From source file:io.ecarf.core.compress.NTripleGzipProcessor.java

/**
 * @param inputFile// ww  w .  j a va2 s.  c  om
 * @param outputFile
 */
public NTripleGzipProcessor(String inputFile) {
    super();
    this.inputFile = inputFile;
    // get the file name before the ext
    String ext = FilenameUtils.getExtension(inputFile);
    // construct an output file in the format inputfile_out.ext
    this.outputFile = StringUtils.removeEnd(inputFile, "." + ext);
    this.outputFile = outputFile + Constants.OUT_FILE_SUFFIX + ext;
}