Example usage for java.io FilenameFilter FilenameFilter

List of usage examples for java.io FilenameFilter FilenameFilter

Introduction

In this page you can find the example usage for java.io FilenameFilter FilenameFilter.

Prototype

FilenameFilter

Source Link

Usage

From source file:com.att.aro.core.fileio.impl.FileManagerImpl.java

@Override
public String[] findFilesByExtention(String localVidsFolder, final String extention) {
    String[] files = list(localVidsFolder, new FilenameFilter() {

        @Override/*from  w w w . j  a v a 2  s.  c  o  m*/
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(extention);
        }
    });
    return files;
}

From source file:com.flexive.core.storage.binary.FxBinaryUtils.java

/**
 * Get an existing transit file for the given division and handle
 *
 * @param divisionId division//ww  w  .  ja  va2s  .  co  m
 * @param handle     binary handle
 * @return the transit file or <code>null</code> if not found
 */
public static File getTransitFile(int divisionId, final String handle) {
    File dir = new File(
            getTransitDirectory() + File.separatorChar + String.valueOf(divisionId) + File.separatorChar);
    File[] result = dir.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith(handle + "__");
        }
    });
    if (result != null && result.length > 0)
        return result[0];
    return null;
}

From source file:net.scran24.admin.server.services.SurveyManagementServiceImpl.java

@Override
public List<String> listSurveys() {
    File dir = new File(getServletContext().getRealPath("/surveys"));
    return Arrays.asList(dir.list(new FilenameFilter() {
        @Override//from  w  ww  .  j  ava 2s  . c  o  m
        public boolean accept(File f, String n) {
            return f.isDirectory();
        }
    }));
}

From source file:de.sub.goobi.persistence.apache.FolderInformation.java

/**
 * Get images orig directory./*  w  ww .j a  v a  2  s .  c o  m*/
 *
 * @param useFallBack
 *            boolean
 * @return String
 */
public String getImagesOrigDirectory(boolean useFallBack) {
    if (ConfigCore.getBooleanParameter("useOrigFolder", true)) {
        SafeFile dir = new SafeFile(getImagesDirectory());
        DIRECTORY_SUFFIX = ConfigCore.getParameter("DIRECTORY_SUFFIX", "tif");
        DIRECTORY_PREFIX = ConfigCore.getParameter("DIRECTORY_PREFIX", "orig");
        /* nur die _tif-Ordner anzeigen, die mit orig_ anfangen */
        FilenameFilter filterVerz = new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                return (name.endsWith("_" + DIRECTORY_SUFFIX) && name.startsWith(DIRECTORY_PREFIX + "_"));
            }
        };

        String origOrdner = "";
        String[] verzeichnisse = dir.list(filterVerz);
        for (int i = 0; i < verzeichnisse.length; i++) {
            origOrdner = verzeichnisse[i];
        }

        if (origOrdner.equals("") && useFallBack) {
            String suffix = ConfigCore.getParameter("MetsEditorDefaultSuffix", "");
            if (!suffix.equals("")) {
                String[] folderList = dir.list();
                for (String folder : folderList) {
                    if (folder.endsWith(suffix)) {
                        origOrdner = folder;
                        break;
                    }
                }
            }
        }
        if (!origOrdner.equals("") && useFallBack) {
            String suffix = ConfigCore.getParameter("MetsEditorDefaultSuffix", "");
            if (!suffix.equals("")) {
                SafeFile tif = new SafeFile(origOrdner);
                String[] files = tif.list();
                if (files == null || files.length == 0) {
                    String[] folderList = dir.list();
                    for (String folder : folderList) {
                        if (folder.endsWith(suffix)) {
                            origOrdner = folder;
                            break;
                        }
                    }
                }
            }
        }

        if (origOrdner.equals("")) {
            origOrdner = DIRECTORY_PREFIX + "_" + this.title + "_" + DIRECTORY_SUFFIX;
        }

        String rueckgabe = getImagesDirectory() + origOrdner + File.separator;

        return rueckgabe;
    } else {
        return getImagesTifDirectory(useFallBack);
    }
}

From source file:org.obiba.onyx.jade.instrument.gemac800.CardiosoftInstrumentRunner.java

/**
 * Replace the instrument configuration file if needed Delete the result database and files
 *
 * @throws Exception/*  w w w .j  a va2  s .  c om*/
 */
protected void deleteDeviceData() {

    // Overwrite the CardioSoft configuration file
    // overwriteIniFile(getSettingsFileName());
    // overwriteIniFile(getWinSettingsFileName());

    // Initialize the CardioSoft database
    FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return (name.endsWith(".BTR"));
        }
    };

    try {
        File backupDir = new File(getCardioPath(), getInitPath());
        if (backupDir.exists() == false) {
            if (backupDir.mkdir() == false) {
                log.error("Unable to create backup directory {}", backupDir.getAbsolutePath());
                throw new RuntimeException("unable to create backup directory " + backupDir.getAbsolutePath());
            }
        }
        File[] backupDatabaseFiles = new File(getCardioPath(), getInitPath()).listFiles(filter);
        if (backupDatabaseFiles.length > 0) {
            for (int i = 0; i < backupDatabaseFiles.length; i++) {
                FileUtil.copyFile(backupDatabaseFiles[i],
                        new File(getCardioPath() + "/" + getDatabasePath(), backupDatabaseFiles[i].getName()));
            }
        } else {
            File[] databaseFiles = new File(getCardioPath(), getDatabasePath()).listFiles(filter);
            if (databaseFiles != null) {
                for (int i = 0; i < databaseFiles.length; i++) {
                    FileUtil.copyFile(databaseFiles[i],
                            new File(getCardioPath() + "/" + getInitPath(), databaseFiles[i].getName()));
                }
            }
        }

    } catch (Exception couldNotInitDbs) {
        throw new RuntimeException("Error initializing ECG database files", couldNotInitDbs);
    }

    File reportFile = new File(getExportPath(), getXmlFileName());
    if (reportFile.exists() && !reportFile.delete()) {
        log.warn("Could not delete Cardiosoft XML output file!");
    }

}

From source file:com.bigdata.dastor.db.commitlog.CommitLog.java

public static void recover() throws IOException {
    String directory = DatabaseDescriptor.getLogFileLocation();
    File file = new File(directory);
    File[] files = file.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.matches("CommitLog-\\d+.log");
        }/* ww w . j a  v a  2 s  . c  om*/
    });
    if (files.length == 0)
        return;

    Arrays.sort(files, new FileUtils.FileComparator());
    logger.info("Replaying " + StringUtils.join(files, ", "));
    recover(files);
    FileUtils.delete(files);
    logger.info("Log replay complete");
}

From source file:ch.cern.dss.teamcity.agent.MockCallable.java

/**
 * Run the actual mock build.// w w  w  .  j a v  a  2s . co  m
 *
 * @throws RunBuildException
 */
private void rebuild() throws RunBuildException {
    String[] command = { MockConstants.MOCK_EXECUTABLE, "--rebuild", "-r", context.getChrootName(),
            "--configdir=" + context.getMockConfigDirectory(), StringUtil.join(context.getSrpms(), " ") };

    // Append RPM macros if we have any
    if (context.getRpmMacros() != null) {
        command = Util.concatArrays(command, processRpmMacros(context.getRpmMacros()));
    }

    SystemCommandResult result;
    logger.message("Running mock: " + Arrays.toString(command));

    try {
        result = Util.runSystemCommand(command);
    } catch (Exception e) {
        throw new RunBuildException("Error running mock", e);
    }

    if (result.getReturnCode() != 0) {
        logger.warning("Mock exited with nozero code (" + result.getReturnCode() + "): " + result.getOutput());
    }

    // Check if rpms were created
    File rpmDirectory = new File(MockConstants.MOCK_CHROOT_DIR, context.getChrootName() + "/result");
    File[] files = rpmDirectory.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File directory, String name) {
            return name.endsWith(".rpm");
        }
    });

    if (files.length <= 0)
        throw new RunBuildException("Error running mock: RPMs not created");
}

From source file:org.ktunaxa.referral.shapereader.ShapeReaderServiceImpl.java

/**
 * <p>//  w ww  .j a  va2 s .  c om
 * Retrieve a list of available shape files to chose from. The idea is that
 * in some location a list of shape files can be retrieved, of which we want
 * to upload one.
 * </p>
 * <p>
 * This implementation uses a "base path" (system folder) to look for shape
 * files.
 * </p>
 * 
 * @param subDirectory extra path element to indicate sub-package/directory
 * @return Returns the full list of available shape files available on the
 *         configured base path.
 * @throws IOException
 *             Thrown if something goes wrong while retrieving available
 *             shape files.
 */
public File[] getAllFiles(String subDirectory) throws IOException {
    if (basePath.startsWith("classpath:")) {
        String fullPath = basePath.substring(10);
        if (subDirectory != null && subDirectory.trim().length() > 0) {
            fullPath = fullPath + "/" + subDirectory;
        }
        PathMatchingResourcePatternResolver pmrpr = new PathMatchingResourcePatternResolver();
        Resource[] resources = pmrpr.getResources(fullPath + File.separator + "*.shp");
        int length = resources.length;
        File[] files = new File[length];
        for (int i = 0; i < length; i++) {
            files[i] = resources[i].getFile();
        }
        return files;
    } else {
        String fullPath = basePath;
        if (subDirectory != null && subDirectory.trim().length() > 0) {
            fullPath = fullPath + File.separator + subDirectory;
        }
        File folder = new File(fullPath); // We don't have to check for folder==null.
        if (!folder.isDirectory()) {
            throw new IOException(
                    "Configured base path is not a directory: " + basePath + " translated to " + fullPath);
        }
        return folder.listFiles(new FilenameFilter() {

            public boolean accept(File dir, String name) {
                return name.endsWith(".shp");
            }
        });
    }

}

From source file:de.xirp.ui.widgets.dialogs.RobotLookupDialog.java

/**
 * Opens the dialog. The flag <code>multi</code> indicates the
 * selection mode. <code>true</code>: multi select allowed.
 * //from   ww w .j  ava2  s .c  o  m
 * @param multi
 *            <code>true</code>: multi select allowed.<br>
 *            <code>false</code>: single select allowed.
 * @return The selection result robot-file file names.
 */
private List<String> open(boolean multi) {
    dialogShell = new XShell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

    dialogShell.addShellListener(new ShellAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
         */
        @Override
        public void shellClosed(ShellEvent e) {
            SWTUtil.secureDispose(dialogShell);
        }
    });

    dialogShell.setSize(WIDTH, HEIGHT);
    if (multi) {
        dialogShell.setTextForLocaleKey("RobotLookupDialog.gui.title.multi"); //$NON-NLS-1$
    } else {
        dialogShell.setTextForLocaleKey("RobotLookupDialog.gui.title.single"); //$NON-NLS-1$
    }
    Image image = ImageManager.getSystemImage(SystemImage.QUESTION);// /$NON-NLS-1$
    dialogShell.setImage(image);

    SWTUtil.setGridLayout(dialogShell, 2, true);

    if (multi) {
        list = new XList(dialogShell, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    } else {
        list = new XList(dialogShell, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL);
    }
    SWTUtil.setGridData(list, true, true, SWT.FILL, SWT.FILL, 2, 1);

    File dir = new File(Constants.CONF_ROBOTS_DIR);
    File[] robotFiles = dir.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.endsWith(Constants.ROBOT_POSTFIX);
        }

    });

    for (File f : robotFiles) {
        Vector<String> itm = new Vector<String>();
        CollectionUtils.addAll(itm, list.getItems());
        if (!itm.contains(f.getName())) {
            list.add(f.getName());
        }
    }
    list.addSelectionListener(new SelectionAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (list.getSelectionCount() > 0) {
                ok.setEnabled(true);
            } else {
                ok.setEnabled(false);
            }
        }
    });

    ok = new XButton(dialogShell, XButtonType.OK);
    ok.setEnabled(false);
    SWTUtil.setGridData(ok, true, false, SWT.FILL, SWT.CENTER, 1, 1);
    ok.addSelectionListener(new SelectionAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            robotFileNames = Arrays.asList(list.getSelection());
            dialogShell.close();
        }
    });

    cancel = new XButton(dialogShell, XButtonType.CANCEL);
    SWTUtil.setGridData(cancel, true, false, SWT.FILL, SWT.CENTER, 1, 1);
    cancel.addSelectionListener(new SelectionAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            robotFileNames.clear();
            dialogShell.close();
        }
    });

    dialogShell.setDefaultButton(ok);
    list.setSelectionWithEvent(0);

    dialogShell.layout();
    SWTUtil.centerDialog(dialogShell);
    dialogShell.open();

    SWTUtil.blockDialogFromReturning(dialogShell);

    return Collections.unmodifiableList(robotFileNames);
}

From source file:de.xirp.ui.widgets.dialogs.CommSpecsLookupDialog.java

/**
 * Opens the dialog. The flag <code>multi</code> indicates the
 * selection mode. <code>true</code>: multi select allowed.
 * /*from  ww w  . j a v  a  2 s  . com*/
 * @param multi
 *            <code>true</code>: multi select allowed.<br>
 *            <code>false</code>: single select allowed.
 * @return The selection result comm-spec-file file names.
 */
private List<String> open(boolean multi) {
    dialogShell = new XShell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

    dialogShell.addShellListener(new ShellAdapter() {

        /**
         * @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
         */
        @Override
        public void shellClosed(ShellEvent e) {
            SWTUtil.secureDispose(dialogShell);
        }
    });

    dialogShell.setSize(WIDTH, HEIGHT);
    if (multi) {
        dialogShell.setTextForLocaleKey("CommSpecsLookupDialog.gui.title.multi"); //$NON-NLS-1$
    } else {
        dialogShell.setTextForLocaleKey("CommSpecsLookupDialog.gui.title.single"); //$NON-NLS-1$
    }
    Image image = ImageManager.getSystemImage(SystemImage.QUESTION);
    dialogShell.setImage(image);

    SWTUtil.setGridLayout(dialogShell, 2, true);

    if (multi) {
        list = new XList(dialogShell, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    } else {
        list = new XList(dialogShell, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL);
    }
    SWTUtil.setGridData(list, true, true, SWT.FILL, SWT.FILL, 2, 1);

    File dir = new File(Constants.CONF_COMMSPECS_DIR);
    File[] cmsFiles = dir.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.endsWith(Constants.COMM_SPEC_POSTFIX);
        }

    });

    for (File f : cmsFiles) {
        Vector<String> itm = new Vector<String>();
        CollectionUtils.addAll(itm, list.getItems());
        if (!itm.contains(f.getName())) {
            list.add(f.getName());
        }
    }
    list.addSelectionListener(new SelectionAdapter() {

        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (list.getSelectionCount() > 0) {
                ok.setEnabled(true);
            } else {
                ok.setEnabled(false);
            }
        }
    });

    ok = new XButton(dialogShell, XButtonType.OK);
    ok.setEnabled(false);
    SWTUtil.setGridData(ok, true, false, SWT.FILL, SWT.CENTER, 1, 1);
    ok.addSelectionListener(new SelectionAdapter() {

        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            commspecFileNames = Arrays.asList(list.getSelection());
            dialogShell.close();
        }
    });

    cancel = new XButton(dialogShell, XButtonType.CANCEL);
    SWTUtil.setGridData(cancel, true, false, SWT.FILL, SWT.CENTER, 1, 1);
    cancel.addSelectionListener(new SelectionAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            commspecFileNames.clear();
            dialogShell.close();
        }
    });

    dialogShell.setDefaultButton(ok);
    list.setSelectionWithEvent(0);

    dialogShell.layout();
    SWTUtil.centerDialog(dialogShell);
    dialogShell.open();

    SWTUtil.blockDialogFromReturning(dialogShell);

    return Collections.unmodifiableList(commspecFileNames);
}