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.search.WebSearchPerformer.java

public static final boolean isStreamable(String filename) {
    String ext = FilenameUtils.getExtension(filename);
    for (String s : STREAMABLE_EXTENSIONS) {
        if (s.equals(ext)) {
            return true; // fast return
        }/*  ww w . j  a  va  2  s  .  c  om*/
    }

    return false;
}

From source file:com.book.identification.task.BookSearch.java

@Override
public void run() {

    List<Volume> volumes = DAOFactory.getInstance().getVolumeDAO().findAll();

    for (Volume volume : volumes) {
        indexedFiles.add(new File(volume.getPath()));
    }/*from www.ja va  2  s .co  m*/
    Collection<File> entries = FileUtils.listFiles(root, new SuffixFileFilter(new String[] { ".pdf", ".chm" }),
            TrueFileFilter.INSTANCE);
    for (File fileToProcces : entries) {

        String fileSHA1 = null;
        try {
            fileSHA1 = DigestUtils.shaHex(FileUtils.openInputStream(fileToProcces));
        } catch (IOException e1) {
            continue;
        }
        logger.info("Accepted file -> " + fileToProcces.getName() + " Hash -> " + fileSHA1);
        FileType fileType = FileType
                .valueOf(StringUtils.upperCase(FilenameUtils.getExtension(fileToProcces.getName())));
        try {
            fileQueue.put(new BookFile(fileToProcces, fileSHA1, fileType));
        } catch (InterruptedException e) {
            logger.info(e);
        }
    }
    nextWorker.notifyEndProducers();
}

From source file:com.daphne.es.maintain.staticresource.web.controller.utils.YuiCompressorUtils.java

public static String getCompressFileName(String fileName) {
    if (hasCompress(fileName)) {
        return fileName;
    }/*w  ww .j  a  v a  2s .  c om*/
    String compressFileName = null;
    final String extension = FilenameUtils.getExtension(fileName);
    if ("js".equalsIgnoreCase(extension)) {
        compressFileName = fileName.substring(0, fileName.length() - 3) + ".min.js";
    } else if ("css".equals(extension)) {
        compressFileName = fileName.substring(0, fileName.length() - 4) + ".min.css";
    }
    return compressFileName;
}

From source file:com.ibm.watson.WatsonVRTraining.util.images.PhotoCaptureFrame.java

PhotoCaptureFrame() {
    jp = new JPanel();
    jp.setLayout(new BoxLayout(jp, BoxLayout.Y_AXIS));

    JScrollPane scrollPane = new JScrollPane(jp);
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    scrollPane.setPreferredSize(new Dimension(dim.width / 2 - 40, dim.height - 117));

    JButton btn = new JButton("Upload Image");

    btn.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JFileChooser fc = new JFileChooser(System.getenv("user.home"));
            fc.setFileFilter(new JPEGImageFileFilter());
            int res = fc.showOpenDialog(null);
            // We have an image!
            try {
                if (res == JFileChooser.APPROVE_OPTION) {
                    File file = fc.getSelectedFile();
                    //SharedResources.sharedCache.getCapturedImageList().add(file);
                    File tmpf_name = File.createTempFile("tmp",
                            "." + FilenameUtils.getExtension(file.getName()));
                    System.out.println("cp " + file.getPath() + " " + AppConstants.vr_process_img_dir_path
                            + File.separator + tmpf_name.getName());
                    new CommandsUtils().executeCommand("bash", "-c", "cp " + file.getPath() + " "
                            + AppConstants.vr_process_img_dir_path + File.separator + tmpf_name.getName());
                }//from  www . j av a  2  s  .co m
            } catch (Exception iOException) {
            }

        }
    });

    ImageRemainingProcessingLabel = new JLabel("REMAINIG IMAGES:0");
    ImageRemainingProcessingLabel.setHorizontalAlignment(SwingConstants.LEFT);
    ImageRemainingProcessingLabel.setFont(new Font("Arial", Font.BOLD, 13));

    ImagebeingProcessedLabel = new JLabel(" PROCESSING IMAGES:0");
    ImagebeingProcessedLabel.setHorizontalAlignment(SwingConstants.LEFT);
    ImagebeingProcessedLabel.setFont(new Font("Arial", Font.BOLD, 13));

    appIDLabel = new JLabel("APP-ID:" + AppConstants.unique_app_id);
    appIDLabel.setHorizontalAlignment(SwingConstants.LEFT);
    appIDLabel.setFont(new Font("Arial", Font.BOLD, 13));

    headerPanel = new JPanel(new FlowLayout());
    headerPanel.add(ImageRemainingProcessingLabel);
    headerPanel.add(ImagebeingProcessedLabel);
    headerPanel.add(btn);
    headerPanel.add(appIDLabel);
    headerPanel.setSize(new Dimension(getWidth(), 10));

    JPanel contentPane = new JPanel();
    contentPane.add(headerPanel);
    contentPane.add(scrollPane);
    f = new JFrame("IBM Watson Visual Prediction Window");
    f.setContentPane(contentPane);
    f.setSize(dim.width / 2 - 30, dim.height - 40);
    f.setLocation(dim.width / 2, 0);
    f.setResizable(false);
    f.setPreferredSize(new Dimension(dim.width / 2 - 30, dim.height - 60));
    f.setVisible(true);
}

From source file:edu.si.services.camel.extractor.ExtractorProducer.java

@Override
public void process(Exchange exchange) throws Exception {
    Message in = exchange.getIn();/*  ww w.j  ava2  s.com*/
    File archiveFile = in.getBody(File.class);
    LOG.debug("Archive file to extract: {}", archiveFile.getName());

    String archiveFileBaseName = FilenameUtils.getBaseName(archiveFile.getName());
    String archiveFileExt = FilenameUtils.getExtension(archiveFile.getName());
    LOG.debug("Found archive file baseName={}, ext= {}", archiveFileBaseName, archiveFileExt);

    if (archiveFileExt == null || archiveFileExt.isEmpty()) {
        errorMsg = new StringBuilder();
        errorMsg.append("Improperly formatted file. No, file extension found for " + archiveFile.getName());
        LOG.error(errorMsg.toString());
        throw new ExtractorException(errorMsg.toString());
    }

    //Set location to extract to
    File cameraTrapDataOutputDir = new File(this.endpoint.getLocation(), archiveFileBaseName);

    //The ArchiveFactory can detect archive types based on file extensions and hand you the correct Archiver.
    Archiver archiver = ArchiverFactory.createArchiver(archiveFile);
    LOG.debug("Archive type: {}", archiver.getFilenameExtension());

    //Stream the archive rather then extracting directly to the file system.
    ArchiveStream archiveStream = archiver.stream(archiveFile);
    ArchiveEntry entry;

    //Extract each archive entry and check for the existence of a compressed folder otherwise create one
    while ((entry = archiveStream.getNextEntry()) != null) {
        LOG.debug("ArchiveStream Current Entry Name = {}, isDirectory = {}", entry.getName(),
                entry.isDirectory());

        //Check for a compressed folder
        if (entry.isDirectory()) {
            errorMsg = new StringBuilder();
            errorMsg.append("Extracting archive '" + archiveFile.getName() + "' failed! ");
            errorMsg.append("Directory '" + entry.getName() + "' found in archive!");

            log.error(errorMsg.toString());
            throw new ExtractorException(errorMsg.toString());
        } else {
            entry.extract(cameraTrapDataOutputDir); //extract the file
        }
    }

    archiveStream.close();

    LOG.debug("File path to be returned on exchange body: {}", cameraTrapDataOutputDir);

    String parent = null;

    if (cameraTrapDataOutputDir.getParentFile() != null) {
        parent = cameraTrapDataOutputDir.getParentFile().getName();
        LOG.debug("CamelFileParent: {}", cameraTrapDataOutputDir.getParentFile());
    }

    Map<String, Object> headers = in.getHeaders();

    headers.put("CamelFileLength", cameraTrapDataOutputDir.length());
    headers.put("CamelFileLastModified", cameraTrapDataOutputDir.lastModified());
    headers.put("CamelFileNameOnly", cameraTrapDataOutputDir.getName());
    headers.put("CamelFileNameConsumed", cameraTrapDataOutputDir.getName());
    headers.put("CamelFileName", cameraTrapDataOutputDir.getName());
    headers.put("CamelFileRelativePath", cameraTrapDataOutputDir.getPath());
    headers.put("CamelFilePath", cameraTrapDataOutputDir.getPath());
    headers.put("CamelFileAbsolutePath", cameraTrapDataOutputDir.getAbsolutePath());
    headers.put("CamelFileAbsolute", false);
    headers.put("CamelFileParent", parent);

    LOG.debug("Headers: {}", headers);

    exchange.getOut().setBody(cameraTrapDataOutputDir, File.class);

    exchange.getOut().setHeaders(headers);
}

From source file:com.github.rwhogg.git_vcr.BetterFileTypeDetector.java

/**
 * Provide a better implementation of probeContentType than we get on other platforms
 * @param path path to the file to determine the type of
 * @return The file's MIME type//from w  ww  . j  av a 2 s  . com
 */
@Override
public String probeContentType(Path path) throws IOException {
    return typeMap.get(FilenameUtils.getExtension(path.getFileName().toString()));
}

From source file:ca.on.oicr.pde.workflows.GATKHaplotypeCallerWorkflow.java

@Override
public Map<String, SqwFile> setupFiles() {

    List<String> inputFilesList = Arrays.asList(StringUtils.split(getProperty("input_files"), ","));
    Set<String> inputFilesSet = new HashSet<>(inputFilesList);

    if (inputFilesList.size() != inputFilesSet.size()) {
        throw new RuntimeException("Duplicate files detected in input_files");
    }//from  w  w  w . ja v a 2  s . c o m

    if ((inputFilesSet.size() % 2) != 0) {
        throw new RuntimeException("Each bam should have a corresponding index");
    }

    Map<String, String> bams = new HashMap<>();
    Map<String, String> bais = new HashMap<>();
    for (String f : inputFilesSet) {
        String fileExtension = FilenameUtils.getExtension(f);
        String fileKey = FilenameUtils.removeExtension(f);
        if (null != fileExtension) {
            switch (fileExtension) {
            case "bam":
                bams.put(fileKey, f);
                break;
            case "bai":
                if (fileKey.endsWith(".bam")) {
                    fileKey = FilenameUtils.removeExtension(fileKey);
                }
                bais.put(fileKey, f);
                break;
            default:
                throw new RuntimeException("Unsupported input file type");
            }
        }
    }

    int id = 0;
    for (Entry<String, String> e : bams.entrySet()) {
        String key = e.getKey();
        String bamFilePath = e.getValue();

        String baiFilePath = bais.get(key);
        if (baiFilePath == null) {
            throw new RuntimeException("Missing index for " + FilenameUtils.getName(bamFilePath));
        }

        SqwFile bam = this.createFile("file_in_" + id++);
        bam.setSourcePath(bamFilePath);
        bam.setType("application/bam");
        bam.setIsInput(true);

        SqwFile bai = this.createFile("file_in_" + id++);
        bai.setSourcePath(baiFilePath);
        bai.setType("application/bam-index");
        bai.setIsInput(true);

        //FIXME: this seems to work for now, it would be better to be able to set the provisionedPath as
        //bai.getProvisionedPath != bai.getOutputPath ...
        //at least with seqware 1.1.0, setting output path changes where the output file will be stored,
        //but the commonly used get provisioned path will return the incorrect path to the file
        bai.setOutputPath(FilenameUtils.getPath(bam.getProvisionedPath()));

        inputBamFiles.add(bam.getProvisionedPath());
    }

    return this.getFiles();
}

From source file:de.uzk.hki.da.format.CLIConversionStrategy.java

/**
 * Convert file.//from w  w  w.jav  a2s  . com
 *
 * @param ci the ci
 * @return the list
 * @throws FileNotFoundException the file not found exception
 */
@Override
public List<Event> convertFile(ConversionInstruction ci) throws FileNotFoundException {
    if (pkg == null)
        throw new IllegalStateException("Package not set");
    Path.make(object.getDataPath(), object.getPath("newest").getLastElement(), ci.getTarget_folder()).toFile()
            .mkdirs();

    String[] commandAsArray = assemble(ci, object.getPath("newest").getLastElement());
    if (!cliConnector.execute(commandAsArray))
        throw new RuntimeException("convert did not succeed");

    String targetSuffix = ci.getConversion_routine().getTarget_suffix();
    if (targetSuffix.equals("*"))
        targetSuffix = FilenameUtils.getExtension(ci.getSource_file().toRegularFile().getAbsolutePath());
    DAFile result = new DAFile(pkg, object.getPath("newest").getLastElement(),
            ci.getTarget_folder() + "/"
                    + FilenameUtils.removeExtension(Matcher.quoteReplacement(
                            FilenameUtils.getName(ci.getSource_file().toRegularFile().getAbsolutePath())))
                    + "." + targetSuffix);

    Event e = new Event();
    e.setType("CONVERT");
    e.setDetail(Utilities.createString(commandAsArray));
    e.setSource_file(ci.getSource_file());
    e.setTarget_file(result);
    e.setDate(new Date());

    List<Event> results = new ArrayList<Event>();
    results.add(e);
    return results;
}

From source file:com.github.fi3te.iliasdownloader.model.adapter.SimpleFileRecyclerAdapter.java

@Override
public void onBindViewHolder(ViewHolder holder, int i) {
    File file = allFiles.get(i);/*  ww  w  .  j av  a 2  s.  c  o  m*/

    String type = file.isDirectory() ? "" : FilenameUtils.getExtension(file.getPath());
    int typeLength = type.length();
    while (type.length() < 4)
        type = type + " ";
    holder.typeText.setText(type);

    if (file.isDirectory()) {
        holder.typeText.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.ic_folder2));
    } else {
        holder.typeText.setBackgroundDrawable(null);
    }

    String name = file.getName();
    name = name.substring(0, name.length() - ((typeLength == 0) ? 0 : (typeLength + 1)));
    holder.nameText.setText(name);

    if (!file.getName().equals(".."))
        holder.dateText.setText(new DateTime(file.lastModified()).toString("dd.MM.yyyy"));
    else
        holder.dateText.setText("");
}

From source file:com.lovejoy777sarootool.rootool.preview.IconPreview.java

private static void loadFromRes(final File file, final ImageView icon) {
    Drawable mimeIcon = null;//w ww  .  java  2s.c  o  m

    if (file != null && file.isDirectory()) {
        String[] files = file.list();
        if (file.canRead() && files != null && files.length > 0)
            mimeIcon = mResources.getDrawable(R.drawable.type_folder);
        else
            mimeIcon = mResources.getDrawable(R.drawable.type_folder_empty);
    } else if (file != null && file.isFile()) {
        final String fileExt = FilenameUtils.getExtension(file.getName());
        mimeIcon = mMimeTypeIconCache.get(fileExt);

        if (mimeIcon == null) {
            final int mimeIconId = MimeTypes.getIconForExt(fileExt);
            if (mimeIconId != 0) {
                mimeIcon = mResources.getDrawable(mimeIconId);
                mMimeTypeIconCache.put(fileExt, mimeIcon);
            }
        }
    }

    if (mimeIcon != null) {
        icon.setImageDrawable(mimeIcon);
    } else {
        // default icon
        icon.setImageResource(R.drawable.type_unknown);
    }
}