Example usage for org.apache.commons.io FilenameUtils isExtension

List of usage examples for org.apache.commons.io FilenameUtils isExtension

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils isExtension.

Prototype

public static boolean isExtension(String filename, Collection<String> extensions) 

Source Link

Document

Checks whether the extension of the filename is one of those specified.

Usage

From source file:de.peterspan.csv2db.ui.FileSelectionPanel.java

private JFileChooser getFileChooser() {
    JFileChooser fc = new JFileChooser();
    fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    fc.setAcceptAllFileFilterUsed(false);

    fc.addChoosableFileFilter(new FileFilter() {

        @Override/*from  w w w. j a v  a  2s.  c  o m*/
        public String getDescription() {
            return "CSV Files";
        }

        @Override
        public boolean accept(File file) {
            if (file.isDirectory()) {
                return true;
            }

            return FilenameUtils.isExtension(file.getName().toLowerCase(), "csv");
        }
    });

    return fc;
}

From source file:com.dattack.naming.loader.NamingLoader.java

/**
 * Scans a directory hierarchy looking for <code>*.properties</code> files. Creates a subcontext for each directory
 * in the hierarchy and binds a new resource for each <code>*.properties</code> file with a
 * <code>ResourceFactory</code> associated.
 *
 *
 * @param directory//  www.j a  v a 2  s .  com
 *            the directory to scan
 * @param ctxt
 *            the Context to populate
 * @param extraClasspath
 *            additional paths to include to the classpath
 * @throws NamingException
 *             if a naming exception is encountered
 * @throws IOException
 *             if an I/O error occurs
 */
public void loadDirectory(final File directory, final Context ctxt, final Collection<File> extraClasspath)
        throws NamingException, IOException {

    if (!directory.isDirectory()) {
        throw new IllegalArgumentException(String.format("'%s' isn't a directory", directory));
    }

    final File[] files = directory.listFiles();
    if (files == null) {
        return;
    }

    for (final File file : files) {
        if (file.isDirectory()) {
            final Context subcontext = ctxt.createSubcontext(file.getName());
            loadDirectory(file, subcontext, extraClasspath);
        } else {

            final String fileName = file.getName();
            if (FilenameUtils.isExtension(fileName, EXTENSIONS)) {
                final String baseName = FilenameUtils.getBaseName(fileName);
                try (FileInputStream fin = new FileInputStream(file)) {
                    final Properties properties = new Properties();
                    properties.load(fin);
                    createAndBind(properties, ctxt, baseName, extraClasspath);
                }
            }
        }
    }
}

From source file:com.mirth.connect.client.ui.components.ChannelTableTransferHandler.java

@Override
public boolean canImport(TransferSupport support) {
    try {//w w  w .j av a 2 s . c  om
        if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            List<File> fileList = (List<File>) support.getTransferable()
                    .getTransferData(DataFlavor.javaFileListFlavor);

            for (File file : fileList) {
                if (!FilenameUtils.isExtension(file.getName(), "xml")) {
                    return false;
                }
            }

            return true;
        } else if (support.isDataFlavorSupported(ChannelTableTransferable.CHANNEL_DATA_FLAVOR)) {
            List<Object> list = (List<Object>) support.getTransferable()
                    .getTransferData(ChannelTableTransferable.CHANNEL_DATA_FLAVOR);

            List<Channel> channels = new ArrayList<Channel>();
            for (Object obj : list) {
                if (obj instanceof Channel) {
                    channels.add((Channel) obj);
                } else {
                    return false;
                }
            }

            if (support.getDropLocation() instanceof JTable.DropLocation) {
                return canMoveChannels(channels, ((JTable.DropLocation) support.getDropLocation()).getRow());
            }
        }
    } catch (Exception e) {
        // Return true anyway until this bug is fixed:
        // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6759788
        return true;
    }

    return false;
}

From source file:net.grinder.AgentUpdateHandler.java

void decompressDownloadPackage() {
    File interDir = new File(agentConfig.getHome().getTempDirectory(), "update_package_unpacked");
    File toDir = new File(agentConfig.getCurrentDirectory(), "update_package");
    interDir.mkdirs();//from   w  w  w  . j a v  a 2 s. c  o m
    toDir.mkdirs();

    if (FilenameUtils.isExtension(download.getName(), "tar")) {
        File outFile = new File(toDir, "ngrinder-agent.tar");
        CompressionUtils.untar(download, interDir);
        FileUtils.deleteQuietly(outFile);
    } else {
        LOGGER.error("{} is not allowed to be unpacked.", download.getName());
    }

    try {
        FileUtils.deleteQuietly(toDir);
        FileUtils.moveDirectory(new File(interDir, "ngrinder-agent"), toDir);
    } catch (IOException e) {
        LOGGER.error("Error while moving a file ", e);
    }
    FileUtils.deleteQuietly(download);
    FileUtils.deleteQuietly(interDir);
}

From source file:com.nabla.wapp.report.server.ReportZipFile.java

public ZipArchiveEntry getReportDesign() {
    for (Enumeration<ZipArchiveEntry> iter = impl.getEntries(); iter.hasMoreElements();) {
        final ZipArchiveEntry entry = iter.nextElement();
        if (!entry.isDirectory() && impl.canReadEntryData(entry)
                && FilenameUtils.isExtension(entry.getName(), ReportManager.REPORT_FILE_EXTENSION))
            return entry;
    }/*from   w  ww.j a v a 2s  .c  o  m*/
    return null;
}

From source file:com.nabla.wapp.report.server.ReportZipFile.java

public Enumeration<ZipArchiveEntry> getEntries(final String fileExtension) {
    return new EnumerationZipEntry(impl, new IFileFilter() {

        @Override/*from w  w  w . j a v  a2s  .  c  om*/
        public boolean include(String fileName) {
            return FilenameUtils.isExtension(fileName, fileExtension);
        }

    });
}

From source file:net.przemkovv.sphinx.compiler.MSVCCompiler.java

private CompilationResult runCompiler(List<File> files, File output_file, List<String> args, File working_dir)
        throws InvalidCompilerException {
    try {//w w  w .j av  a  2 s  .c o  m

        if (output_file == null) {
            output_file = new File(working_dir, RandomStringUtils.randomAlphanumeric(8) + ".exe");
        }
        ArrayList<String> cmd = new ArrayList<>();
        if (prepare_env != null) {

            cmd.add(prepare_env.getAbsolutePath());
            cmd.add("&&");
        }
        cmd.add(msvc.getAbsolutePath());
        cmd.add("/Fe" + output_file.getAbsolutePath());
        if (args != null) {
            cmd.addAll(args);
        }
        if (files != null) {
            for (File file : files) {
                if (FilenameUtils.isExtension(file.getName(), "cpp")
                        || FilenameUtils.isExtension(file.getName(), "c")) {
                    cmd.add(file.getAbsolutePath());
                }

            }
        }

        logger.debug("Compiler command line: {}", cmd);
        final Process process = Runtime.getRuntime().exec(cmd.toArray(new String[cmd.size()]), null,
                output_file.getParentFile());

        Future<String> output_error_result = pool.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                return Utils.readAllFromInputStream(process.getErrorStream());
            }
        });
        Future<String> output_result = pool.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                return Utils.readAllFromInputStream(process.getInputStream());
            }
        });
        process.waitFor();
        CompilationResult result = new CompilationResult();
        result.output_errror = output_error_result.get();
        result.output = output_result.get();
        result.exit_value = process.exitValue();
        result.executable_file = output_file;
        result.prepare_env = prepare_env;
        return result;
    } catch (IOException | InterruptedException ex) {
        throw new InvalidCompilerException(ex);

    } catch (ExecutionException ex) {
        java.util.logging.Logger.getLogger(MSVCCompiler.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:com.esri.geoevent.test.performance.PerformanceCollectorBase.java

protected void loadEvents(File file) throws TestException {
    if (!events.isEmpty()) {
        events.clear();//from   w  w  w. j a  v a2s  .c  o  m
    }

    // parse out json files differently
    if (FilenameUtils.isExtension(file.getName(), "json")) {
        eventFileType = FileType.JSON;
        try {
            ObjectMapper mapper = new ObjectMapper();
            JsonNode node = mapper.readTree(file);
            addEventsToList(node);
        } catch (Exception error) {
            throw new TestException(error.getMessage());
        }
    } else {
        eventFileType = FileType.TEXT;
        try (BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(file)))) {
            String line = null;
            while ((line = input.readLine()) != null) {
                events.add(line + "\n");
            }
        } catch (Exception error) {
            throw new TestException(error.getMessage());
        }
    }
}

From source file:it.eng.spagobi.engines.worksheet.services.designer.UploadWorksheetImageAction.java

private boolean isImgFileExtension(String name) {
    logger.debug("IN");
    try {/*ww w .  jav  a 2s .  c o  m*/

        ArrayList extensions = new ArrayList<String>();
        extensions.add("bmp");
        extensions.add("dds");
        extensions.add("gif");
        extensions.add("jpg");
        extensions.add("png");
        extensions.add("psd");
        extensions.add("pspimage");
        extensions.add("tga");
        extensions.add("thm");
        extensions.add("tif");
        extensions.add("tiff");
        extensions.add("yuv");

        return FilenameUtils.isExtension(name.toLowerCase(), extensions);
    } finally {
        logger.debug("OUT");

    }
}

From source file:com.nabla.wapp.report.server.ReportZipFile.java

public Enumeration<ZipArchiveEntry> getEntries(final String[] fileExtensions) {
    return new EnumerationZipEntry(impl, new IFileFilter() {

        @Override//from   w w w . j  a va  2s  .  co m
        public boolean include(String fileName) {
            return FilenameUtils.isExtension(fileName, fileExtensions);
        }

    });
}