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.frostwire.gui.UniversalScanner.java

private void scanPictures(String filePath, boolean shared) {
    File file = new File(filePath);

    ContentValues values = new ContentValues();

    String mime = "image/" + FilenameUtils.getExtension(filePath);
    fillCommonValues(values, Constants.FILE_TYPE_PICTURES, filePath, file, mime, shared);

    try {/*from   w  ww . ja v a  2  s  . c  o m*/
        Metadata metadata = ImageMetadataReader.readMetadata(file);

        ExifIFD0Directory dir = metadata.getDirectory(ExifIFD0Directory.class);
        ExifIFD0Descriptor desc = new ExifIFD0Descriptor(dir);

        String title = desc.getWindowsTitleDescription();
        if (StringUtils.isNullOrEmpty(title, true)) {
            title = FilenameUtils.getBaseName(file.getName());
        }

        String artist = desc.getWindowsAuthorDescription();
        if (StringUtils.isNullOrEmpty(artist, true)) {
            artist = dir.getString(ExifIFD0Directory.TAG_ARTIST, "UTF-8");
        }
        if (StringUtils.isNullOrEmpty(artist, true)) {
            artist = "";
        }

        String album = "";
        String year = dir.getString(ExifIFD0Directory.TAG_DATETIME);
        if (StringUtils.isNullOrEmpty(year, true)) {
            year = "";
        }

        values.put(Columns.TITLE, title);
        values.put(Columns.ARTIST, artist);
        values.put(Columns.ALBUM, album);
        values.put(Columns.YEAR, year);
    } catch (Throwable e) {
        String displayName = FilenameUtils.getBaseName(file.getName());

        values.put(Columns.TITLE, displayName);
        values.put(Columns.ARTIST, "");
        values.put(Columns.ALBUM, "");
        values.put(Columns.YEAR, "");
    }

    ShareFilesDB db = ShareFilesDB.intance();

    db.insert(values);
}

From source file:net.doubledoordev.backend.server.FileManager.java

public String getExtension(File file) {
    return FilenameUtils.getExtension(file.getName().toLowerCase());
}

From source file:de.monticore.io.paths.ModelCoordinateImpl.java

@Override
public String getExtension() {
    if (hasLocation()) {
        return FilenameUtils.getExtension(location.toString());
    } else {/*w  ww  .  j  a  va 2s . c om*/
        return FilenameUtils.getExtension(qualifiedPath.toString());
    }
}

From source file:eu.openanalytics.rsb.message.MultiFilesJob.java

private void addJobFile(final String name, final InputStream is) throws FileNotFoundException, IOException {
    final File jobFile = new File(temporaryDirectory, name);

    if (StringUtils.equalsIgnoreCase(FilenameUtils.getExtension(name), Constants.R_SCRIPT_FILE_EXTENSION)) {
        if (rScriptFile != null) {
            throw new IllegalArgumentException("Only one R script is allowed per job");
        }//from  www.j  a  va2 s .  c om
        rScriptFile = jobFile;
    }

    final FileOutputStream fos = new FileOutputStream(jobFile);
    IOUtils.copy(is, fos);
    IOUtils.closeQuietly(fos);
}

From source file:edu.sabanciuniv.sentilab.sare.controllers.base.documentStore.NonDerivedStoreFactory.java

protected NonDerivedStoreFactory<T> addZipPacket(T store, InputStream input) throws IOException {

    Validate.notNull(store, CannedMessages.NULL_ARGUMENT, "store");
    Validate.notNull(input, CannedMessages.NULL_ARGUMENT, "input");

    ZipInputStream zipStream = new ZipInputStream(input);
    ZipEntry zipEntry;//from w  ww  .  j  av a  2  s. com
    while ((zipEntry = zipStream.getNextEntry()) != null) {
        if (!zipEntry.isDirectory()) {
            // we create a byte stream so that the input stream is not closed by the underlying methods.
            this.createSpecific(store, new ByteArrayInputStream(IOUtils.toByteArray(zipStream)),
                    FilenameUtils.getExtension(zipEntry.getName()));
        }
    }

    return this;
}

From source file:gda.device.detector.mythen.tasks.RCPPlotLastPointTask.java

@Override
public void run(String filename, MythenProcessedDataset processedData) {
    if (isUsePlotServer()) {
        double[] angles = processedData.getAngleArray();
        double[] counts = processedData.getCountArray();

        IDataset channelsDataset = DatasetFactory.createFromObject(angles);
        channelsDataset.setName("angle");
        IDataset countsDataset = DatasetFactory.createFromObject(counts);
        countsDataset.setName(filename);

        try {/*  w  w w. ja va2  s  .  c  o m*/
            SDAPlotter.plot(panelName, channelsDataset, countsDataset);
        } catch (Exception e) {
            logger.error("Exception throwed on RCPPlotter.plot to panel " + panelName, e);
        }
    } else {
        if (FilenameUtils.getExtension(filename) == "") {
            filename = filename + ".dat";
        }

        String fullPathName = Paths.get(PathConstructor.createFromDefaultProperty(), filename).toString();
        ((ScriptControllerBase) getEventAdmin()).update(this, new PlotDataFileEvent(fullPathName, true));
    }

}

From source file:aurelienribon.gdxsetupui.Helper.java

public static String getSource(List<String> files, String file) {
    String path = FilenameUtils.getFullPath(file);
    String name = FilenameUtils.getBaseName(file);
    String ext = FilenameUtils.getExtension(file);

    if (files.contains(path + name + "-source." + ext))
        return path + name + "-source." + ext;
    if (files.contains(path + name + "-sources." + ext))
        return path + name + "-sources." + ext;
    if (files.contains(path + name + "-src." + ext))
        return path + name + "-src." + ext;
    return null;//  w ww .  jav a  2 s . com
}

From source file:cz.lbenda.rcp.IconFactory.java

private String iconName(String base, IconSize iconSize) {
    if (iconSize != null) {
        String ext = FilenameUtils.getExtension(base);
        return FilenameUtils.removeExtension(base) + iconSize.size()
                + (StringUtils.isBlank(ext) ? "" : "." + ext);
    }/*from w  ww . j  av  a  2s. co  m*/
    return base;
}

From source file:com.haulmont.cuba.web.filestorage.WebExportDisplay.java

/**
 * Show/Download resource at client side
 *
 * @param dataProvider ExportDataProvider
 * @param resourceName ResourceName for client side
 * @param exportFormat ExportFormat/*from   w  w  w. j  a v  a2s . co m*/
 * @see com.haulmont.cuba.gui.export.FileDataProvider
 * @see com.haulmont.cuba.gui.export.ByteArrayDataProvider
 */
@Override
public void show(ExportDataProvider dataProvider, String resourceName, final ExportFormat exportFormat) {
    backgroundWorker.checkUIAccess();

    boolean showNewWindow = this.newWindow;

    if (useViewList) {
        String fileExt;

        if (exportFormat != null) {
            fileExt = exportFormat.getFileExt();
        } else {
            fileExt = FilenameUtils.getExtension(resourceName);
        }

        WebConfig webConfig = configuration.getConfig(WebConfig.class);
        showNewWindow = webConfig.getViewFileExtensions().contains(StringUtils.lowerCase(fileExt));
    }

    if (exportFormat != null) {
        if (StringUtils.isEmpty(FilenameUtils.getExtension(resourceName))) {
            resourceName += "." + exportFormat.getFileExt();
        }
    }

    CubaFileDownloader fileDownloader = AppUI.getCurrent().getFileDownloader();

    StreamResource resource = new StreamResource(dataProvider::provide, resourceName);

    if (exportFormat != null && StringUtils.isNotEmpty(exportFormat.getContentType())) {
        resource.setMIMEType(exportFormat.getContentType());
    } else {
        resource.setMIMEType(FileTypesHelper.getMIMEType(resourceName));
    }

    if (showNewWindow) {
        fileDownloader.viewDocument(resource);
    } else {
        fileDownloader.downloadFile(resource);
    }
}

From source file:abfab3d.io.input.X3DFileLoader.java

/**
 * Load the specified file X3D file.//from  w ww .  j av a  2 s.c  o m
 */
public void loadFile(File input) throws IOException, IllegalArgumentException {
    int export_major_version = DEFAULT_OUPUT_MAJOR_VERSION;
    int export_minor_version = DEFAULT_OUPUT_MINOR_VERSION;

    InputSource is = new InputSource(input);

    Exporter writer = new NullExporter(export_major_version, export_minor_version, console);

    BaseReader reader;

    if (FilenameUtils.getExtension(input.getAbsolutePath()).equalsIgnoreCase("wrl")) {
        reader = new VRML97Reader();
    } else {
        reader = new X3DReader();
    }

    AbstractFilter filter = this;

    reader.setContentHandler(filter);
    reader.setRouteHandler(filter);
    reader.setScriptHandler(filter);
    reader.setProtoHandler(filter);
    reader.setErrorReporter(console);

    filter.setContentHandler(writer);
    filter.setRouteHandler(writer);
    filter.setScriptHandler(writer);
    filter.setProtoHandler(writer);

    reader.parse(is);

    try {
        // clean up...
        is.close();
    } catch (IOException ioe) {
        // ignore
    }

    // Convert all supported geometry to ITS
    List<CommonEncodable> nodes = parsedScene.getRootNodes();

    // Assume the scenegraph is flat via visual_mesh_conversion.sh

    int len = nodes.size();
    for (int i = 0; i < len; i++) {
        CommonEncodable enc = nodes.get(i);
        if (enc.getNodeName().equals("Shape")) {
            processShape(enc);
            shapes.add(enc);
        }
    }

    Iterator<CommonEncodable> itr2 = shapes.iterator();
    while (itr2.hasNext()) {
        CommonEncodable n = itr2.next();
        parsedScene.removeRootNode(n);
    }
}