Example usage for java.io FileFilter FileFilter

List of usage examples for java.io FileFilter FileFilter

Introduction

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

Prototype

FileFilter

Source Link

Usage

From source file:com.amalto.core.jobox.component.JobAware.java

public List<JobInfo> findJobsInBox() {
    File[] entities = new File(workDir).listFiles(new FileFilter() {

        public boolean accept(File pathName) {
            return !(pathName.isFile() || JOBOX_RESERVED_FOLDER_NAME.equalsIgnoreCase(pathName.getName()));
        }/*from  w w  w. ja  va 2  s.  co  m*/
    });
    List<JobInfo> jobList = new ArrayList<JobInfo>();
    for (File entity : entities) {
        boolean isTISEntry = recognizeTISJob(entity);
        if (isTISEntry) {
            // parse name and version
            String jobVersion = ""; //$NON-NLS-1$
            String jobName = ""; //$NON-NLS-1$
            Matcher m = jobVersionNamePattern.matcher(entity.getName());
            while (m.find()) {
                jobName = m.group(1);
                jobVersion = m.group(m.groupCount());
            }
            JobInfo jobInfo = new JobInfo(jobName, jobVersion);
            setClassPath4TISJob(entity, jobInfo);
            // get main class from command line
            guessMainClassFromCommandLine(entity, jobInfo);
            //not found then found it in context properties folder
            if (jobInfo.getMainClass() == null) {
                String propFilePath = analyzeJobParams(entity, jobInfo);
                guessMainClass(propFilePath, jobInfo);
            }
            jobList.add(jobInfo);
        }
    }
    return jobList;
}

From source file:net.tourbook.photo.ImageUtils.java

public static FileFilter createImageFileFilter() {

    return new FileFilter() {
        @Override//w  ww.j a v a2  s .  c  o  m
        public boolean accept(final File pathname) {

            if (pathname.isDirectory()) {
                return false;
            }

            if (pathname.isHidden()) {
                return false;
            }

            final String name = pathname.getName();
            if (name == null || name.length() == 0) {
                return false;
            }

            if (name.startsWith(".")) { //$NON-NLS-1$
                return false;
            }

            if (Imaging.hasImageFileExtension(pathname)) {
                return true;
            }

            return false;
        }
    };
}

From source file:com.cloudera.gertrude.file.FileExperimentSpaceLoader.java

private FileAlterationMonitor getMonitor(long pollIntervalMillis) {
    FileAlterationObserver observer = new FileAlterationObserver(dataFile.getParentFile(), new FileFilter() {
        @Override/*  www  . ja va2s  . c  o m*/
        public boolean accept(File file) {
            return dataFile.equals(file);
        }
    });

    observer.addListener(new FileAlterationListenerAdaptor() {
        @Override
        public void onFileChange(File file) {
            file.setLastModified(System.currentTimeMillis());
            reload(false);
        }
    });
    FileAlterationMonitor m = new FileAlterationMonitor(pollIntervalMillis);
    m.addObserver(observer);
    return m;
}

From source file:au.org.ala.bhl.command.PaginateDocCacheCommand.java

public void execute(ItemsService service, final IndexerOptions options) throws Exception {

    File dir = new File(options.getDocCachePath());

    if (dir.exists() && dir.isDirectory()) {

        dir.listFiles(new FileFilter() {

            public boolean accept(File candidate) {
                if (candidate.length() > 0 && candidate.getName().toLowerCase().endsWith(".xml")) {
                    paginateFile(candidate, options);
                }//from  w w  w  .ja v  a 2  s  .c om
                return false;
            }
        });

    }

}

From source file:com.aliyun.odps.ship.upload.BlockInfoBuilder.java

public long getFileSize(File file) throws IOException, TunnelException, ParseException {
    long totalBytes = 0;
    if (file.isDirectory()) {
        File[] fileList = file.listFiles(new FileFilter() {
            @Override//from   www. j  a  v  a2 s . c o  m
            public boolean accept(File pathname) {
                return pathname.isFile();
            }
        });
        fileList = Util.sortFiles(fileList);

        for (File f : fileList) {
            totalBytes += getFileSize(f);
        }
    } else {
        long fileLength = file.length();
        totalBytes += fileLength;
    }
    return totalBytes;
}

From source file:offstage.licensor.MakeLauncher.java

/**
 * /*ww  w  .j a  va 2s. c o m*/
 * @param version
 * @param configDir
 * @param outJar
 * @param spassword
 * @throws java.lang.Exception
 */
public static void makeLauncher(String version, File configDir, File outJar, String spassword)
        throws Exception {
    File oaDir = ClassPathUtils.getMavenProjectRoot();
    File oalaunchDir = new File(oaDir, "../oalaunch");
    File oasslDir = new File(oaDir, "../oassl");
    File keyDir = new File(oasslDir, "keys/client");
    File tmpDir = new File(".", "tmp");
    FileUtils.deleteDirectory(tmpDir);
    tmpDir.mkdirs();

    // Find the oalaunch JAR file
    File oalaunchJar = null;
    File[] files = new File(oalaunchDir, "target").listFiles();
    for (File f : files) {
        if (f.getName().startsWith("oalaunch") && f.getName().endsWith(".jar")) {
            oalaunchJar = f;
            break;
        }
    }

    // Unjar the oalaunch.jar file into the temporary directory
    exec(tmpDir, "jar", "xvf", oalaunchJar.getAbsolutePath());

    File tmpOalaunchDir = new File(tmpDir, "oalaunch");
    File tmpConfigDir = new File(tmpOalaunchDir, "config");

    // Read app.properties
    Properties props = new Properties();
    InputStream in = new FileInputStream(new File(configDir, "app.properties"));
    props.load(in);
    in.close();

    // Re-do the config dir
    FileUtils.deleteDirectory(tmpConfigDir);
    FileFilter ff = new FileFilter() {
        public boolean accept(File f) {
            if (f.getName().startsWith("."))
                return false;
            if (f.getName().endsWith("~"))
                return false;
            return true;
        }
    };
    FileUtils.copyDirectory(configDir, tmpConfigDir, ff);

    // Set up to encrypt
    char[] password = null;
    PBECrypt pbe = new PBECrypt();
    if (spassword != null)
        password = spassword.toCharArray();

    // Encrypt .properties files if needed
    if (password != null) {
        for (File fin : configDir.listFiles()) {
            if (fin.getName().endsWith(".properties") || fin.getName().endsWith(".jks")) {
                File fout = new File(tmpConfigDir, fin.getName());
                pbe.encrypt(fin, fout, password);
            }
        }
    }

    // Copy the appropriate key and certificate files
    String dbUserName = props.getProperty("db.user", null);
    File[] jksFiles = new File[] { new File(keyDir, dbUserName + "-store.jks"),
            new File(keyDir, dbUserName + "-trust.jks") };
    for (File fin : jksFiles) {
        if (!fin.exists()) {
            System.out.println("Missing jks file: " + fin.getName());
            continue;
        }
        File fout = new File(tmpConfigDir, fin.getName());
        if (password != null) {
            System.out.println("Encrypting " + fin.getName());
            pbe.encrypt(fin, fout, password);
        } else {
            System.out.println("Copying " + fin.getName());
            FileUtils.copyFile(fin, fout);
        }
    }

    // Use a downloaded JNLP file, not a static one.
    new File(tmpOalaunchDir, "offstagearts.jnlp").delete();

    // Open properties file, which we will write to...
    File oalaunchProperties = new File(tmpDir, "oalaunch/oalaunch.properties");
    Writer propertiesOut = new FileWriter(oalaunchProperties);
    propertiesOut.write(
            "jnlp.template.url = " + "http://offstagearts.org/releases/offstagearts/offstagearts_oalaunch-"
                    + version + ".jnlp.template\n");
    String configName = outJar.getName();
    int dot = configName.lastIndexOf(".jar");
    if (dot >= 0)
        configName = configName.substring(0, dot);
    propertiesOut.write("config.name = " + configName + "\n");
    propertiesOut.close();

    // Jar it back up
    exec(tmpDir, "jar", "cvfm", outJar.getAbsolutePath(), "META-INF/MANIFEST.MF", ".");

    // Sign it
    exec(null, "jarsigner", "-storepass", "keyst0re", outJar.getAbsolutePath(), "offstagearts");

    // Remove the tmp directory
    FileUtils.deleteDirectory(tmpDir);
}

From source file:citibob.licensor.MakeLauncher.java

/**
 * /*from  ww w  .ja  v  a2s  . c  o  m*/
 * @param version
 * @param configDir
 * @param outJar
 * @param spassword
 * @throws java.lang.Exception
 */
public static void makeLauncher(String version, File configDir, File outJar, String spassword)
        throws Exception {
    File oaDir = ClassPathUtils.getMavenProjectRoot();
    File oalaunchDir = new File(oaDir, "../oalaunch");
    File oasslDir = new File(oaDir, "../oassl");
    File keyDir = new File(oasslDir, "keys/client");
    File tmpDir = new File(".", "tmp");
    FileUtils.deleteDirectory(tmpDir);
    tmpDir.mkdirs();

    // Find the oalaunch JAR file
    File oalaunchJar = null;
    File[] files = new File(oalaunchDir, "target").listFiles();
    for (File f : files) {
        if (f.getName().startsWith("oalaunch") && f.getName().endsWith(".jar")) {
            oalaunchJar = f;
            break;
        }
    }

    // Unjar the oalaunch.jar file into the temporary directory
    exec(tmpDir, "jar", "xvf", oalaunchJar.getAbsolutePath());

    File tmpOalaunchDir = new File(tmpDir, "oalaunch");
    File tmpConfigDir = new File(tmpOalaunchDir, "config");

    // Read app.properties
    Properties props = new Properties();
    InputStream in = new FileInputStream(new File(configDir, "app.properties"));
    props.load(in);
    in.close();

    // Re-do the config dir
    FileUtils.deleteDirectory(tmpConfigDir);
    FileFilter ff = new FileFilter() {
        public boolean accept(File f) {
            if (f.getName().startsWith("."))
                return false;
            if (f.getName().endsWith("~"))
                return false;
            return true;
        }
    };
    FileUtils.copyDirectory(configDir, tmpConfigDir, ff);

    // Set up to encrypt
    char[] password = null;
    PBECrypt pbe = new PBECrypt();
    if (spassword != null)
        password = spassword.toCharArray();

    // Encrypt .properties files if needed
    if (password != null) {
        for (File fin : configDir.listFiles()) {
            if (fin.getName().endsWith(".properties") || fin.getName().endsWith(".jks")) {
                File fout = new File(tmpConfigDir, fin.getName());
                pbe.encrypt(fin, fout, password);
            }
        }
    }

    // Copy the appropriate key and certificate files
    String dbUserName = props.getProperty("db.user", null);
    File[] jksFiles = new File[] { new File(keyDir, dbUserName + "-store.jks"),
            new File(keyDir, dbUserName + "-trust.jks") };
    for (File fin : jksFiles) {
        if (!fin.exists()) {
            System.out.println("Missing jks file: " + fin.getName());
            continue;
        }
        File fout = new File(tmpConfigDir, fin.getName());
        if (password != null) {
            System.out.println("Encrypting " + fin.getName());
            pbe.encrypt(fin, fout, password);
        } else {
            System.out.println("Copying " + fin.getName());
            FileUtils.copyFile(fin, fout);
        }
    }

    // Use a downloaded JNLP file, not a static one.
    new File(tmpOalaunchDir, "offstagearts.jnlp").delete();

    // Open properties file, which we will write to...
    File oalaunchProperties = new File(tmpDir, "oalaunch/oalaunch.properties");
    Writer propertiesOut = new FileWriter(oalaunchProperties);
    propertiesOut.write(
            "jnlp.template.url = " + "http://offstagearts.org/releases/offstagearts/offstagearts_oalaunch-"
                    + version + ".jnlp.template\n");
    String configName = outJar.getName();
    int dot = configName.lastIndexOf(".jar");
    if (dot >= 0)
        configName = configName.substring(0, dot);
    propertiesOut.write("config.name = " + configName + "\n");
    propertiesOut.close();

    // Jar it back up
    exec(tmpDir, "jar", "cvfm", outJar.getAbsolutePath(), "META-INF/MANIFEST.MF", ".");

    //   // Sign it
    //   exec(null, "jarsigner", "-storepass", "keyst0re", outJar.getAbsolutePath(),
    //         "offstagearts");

    // Remove the tmp directory
    FileUtils.deleteDirectory(tmpDir);
}

From source file:eu.mhutti1.utils.storage.StorageDeviceUtils.java

public static ArrayList<StorageDevice> getStorageDevices(Context context, boolean writable) {
    mStorageDevices = new ArrayList<>();

    // Add as many possible mount points as we know about

    // Only add this device if its very likely that we have missed a users sd card
    if (Environment.isExternalStorageEmulated()) {
        // This is our internal storage directory
        mStorageDevices.add(new StorageDevice(
                generalisePath(Environment.getExternalStorageDirectory().getPath(), writable), true));
    } else {//  w ww.j a v  a  2 s . c  om
        // This is the internal directory of our app that only we can write to
        mStorageDevices.add(new StorageDevice(context.getFilesDir().getPath(), true));
        // This is an external storage directory
        mStorageDevices.add(new StorageDevice(
                generalisePath(Environment.getExternalStorageDirectory().getPath(), writable), false));
    }

    // These are possible manufacturer sdcard mount points

    String[] paths = ExternalPaths.getPossiblePaths();

    for (String path : paths) {
        if (path.endsWith("*")) {
            File root = new File(path.substring(0, path.length() - 1));
            File[] directories = root.listFiles(new FileFilter() {
                @Override
                public boolean accept(File file) {
                    return file.isDirectory();
                }
            });
            if (directories != null) {
                for (File dir : directories) {
                    mStorageDevices.add(new StorageDevice(dir, false));
                }
            }
        } else {
            mStorageDevices.add(new StorageDevice(path, false));
        }
    }

    // Iterate through any sdcards manufacturers may have specified in Kitkat+ and add them
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        for (File file : context.getExternalFilesDirs("")) {
            if (file != null) {
                mStorageDevices.add(new StorageDevice(generalisePath(file.getPath(), writable), false));
            }
        }
    }

    // Check all devices exist, we can write to them if required and they are not duplicates
    return checkStorageValid(writable);
}

From source file:org.ado.minesync.minecraft.MinecraftData.java

public List<MinecraftWorld> getWorlds() {
    List<MinecraftWorld> minecraftWorldList = new ArrayList<MinecraftWorld>();
    File[] worlds = MINECRAFT_WORLDS.listFiles(new FileFilter() {
        @Override//from   w  ww  .  j a v a  2  s .  co  m
        public boolean accept(File pathname) {
            return pathname.isDirectory() && !pathname.getName().startsWith(UNDERSCORE_CHAR)
                    && !pathname.getName().startsWith(DOT);
        }
    });
    if (worlds != null) {
        for (File worldDirectory : worlds) {
            minecraftWorldList.add(getWorld(worldDirectory));
        }
    } else {
        ALog.i(TAG, "No world found under \"%s\".", MINECRAFT_WORLDS.getAbsolutePath());
    }
    Collections.sort(minecraftWorldList, new Comparator<MinecraftWorld>() {
        @Override
        public int compare(MinecraftWorld lhs, MinecraftWorld rhs) {
            return lhs.getName().compareTo(rhs.getName());
        }
    });
    return minecraftWorldList;
}

From source file:air.AirRuntimeGenerator.java

protected void processFlashRuntime(File sdkSourceDirectory, File sdkTargetDirectory) throws Exception {
    final File runtimeDirectory = new File(sdkSourceDirectory, "runtimes");
    final File flashPlayerDirectory = new File(runtimeDirectory, "player");

    File[] versions = flashPlayerDirectory.listFiles(new FileFilter() {
        public boolean accept(File pathname) {
            return pathname.isDirectory() && !"win".equalsIgnoreCase(pathname.getName())
                    && !"lnx".equalsIgnoreCase(pathname.getName())
                    && !"mac".equalsIgnoreCase(pathname.getName());
        }/*  w  ww.j  ava2s . co m*/
    });
    // The flash-player 9 is installed directly in the player directory.
    if (new File(flashPlayerDirectory, "win").exists()) {
        final File[] extendedVersions = new File[versions.length + 1];
        System.arraycopy(versions, 0, extendedVersions, 0, versions.length);
        extendedVersions[versions.length] = flashPlayerDirectory;
        versions = extendedVersions;
    }

    if (versions != null) {
        for (final File versionDir : versions) {
            // If the versionDir is called "player", then this is the home of the flash-player version 9.
            final String playerVersionString = "player".equalsIgnoreCase(versionDir.getName()) ? "9.0"
                    : versionDir.getName();
            final double playerVersion = Double.valueOf(playerVersionString);
            final NumberFormat doubleFormat = NumberFormat.getInstance(Locale.US);
            doubleFormat.setMinimumFractionDigits(1);
            doubleFormat.setMaximumFractionDigits(1);
            final String version = doubleFormat.format(playerVersion);

            final File targetDir = new File(sdkTargetDirectory, "com/adobe/flash/runtime/" + version);

            // Deploy Windows binaries.
            final File windowsDirectory = new File(versionDir, "win");
            if (windowsDirectory.exists()) {
                // Find out if a flash-player binary exists.
                File flashPlayerBinary = null;
                if (new File(windowsDirectory, "FlashPlayerDebugger.exe").exists()) {
                    flashPlayerBinary = new File(windowsDirectory, "FlashPlayerDebugger.exe");
                } else if (new File(windowsDirectory, "FlashPlayer.exe").exists()) {
                    flashPlayerBinary = new File(windowsDirectory, "FlashPlayer.exe");
                }

                // If a binary exists, copy it to the target and create a pom for it.
                if (flashPlayerBinary != null) {
                    if (!targetDir.exists()) {
                        if (!targetDir.mkdirs()) {
                            throw new RuntimeException(
                                    "Could not create directory: " + targetDir.getAbsolutePath());
                        }
                    }
                    final File targetFile = new File(targetDir, "/runtime-" + version + "-win.exe");
                    copyFile(flashPlayerBinary, targetFile);
                }
            }

            // Deploy Mac binaries.
            final File macDirectory = new File(versionDir, "mac");
            if (macDirectory.exists()) {
                // Find out if a flash-player binary exists.
                File flashPlayerBinary = null;
                if (new File(macDirectory, "Flash Player.app.zip").exists()) {
                    flashPlayerBinary = new File(macDirectory, "Flash Player.app.zip");
                } else if (new File(macDirectory, "Flash Player Debugger.app.zip").exists()) {
                    flashPlayerBinary = new File(macDirectory, "Flash Player Debugger.app.zip");
                }

                // If a binary exists, copy it to the target and create a pom for it.
                if (flashPlayerBinary != null) {
                    if (!targetDir.exists()) {
                        if (!targetDir.mkdirs()) {
                            throw new RuntimeException(
                                    "Could not create directory: " + targetDir.getAbsolutePath());
                        }
                    }
                    final File targetFile = new File(targetDir, "/runtime-" + version + "-mac.zip");
                    copyFile(flashPlayerBinary, targetFile);
                }
            }

            // Deploy Linux binaries.
            final File lnxDirectory = new File(versionDir, "lnx");
            if (lnxDirectory.exists()) {
                // Find out if a flash-player binary exists.
                File flashPlayerBinary = null;
                if (new File(lnxDirectory, "flashplayer.tar.gz").exists()) {
                    flashPlayerBinary = new File(lnxDirectory, "flashplayer.tar.gz");
                } else if (new File(lnxDirectory, "flashplayerdebugger.tar.gz").exists()) {
                    flashPlayerBinary = new File(lnxDirectory, "flashplayerdebugger.tar.gz");
                }

                // Decompress the archive.
                // First unzip it.
                final FileInputStream fin = new FileInputStream(flashPlayerBinary);
                final BufferedInputStream in = new BufferedInputStream(fin);
                final File tempTarFile = File.createTempFile("flex-sdk-linux-flashplayer-binary-" + version,
                        ".tar");
                final FileOutputStream out = new FileOutputStream(tempTarFile);
                final GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in);
                final byte[] buffer = new byte[1024];
                int n;
                while (-1 != (n = gzIn.read(buffer))) {
                    out.write(buffer, 0, n);
                }
                out.close();
                gzIn.close();

                // Then untar it.
                File uncompressedBinary = null;
                final FileInputStream tarFileInputStream = new FileInputStream(tempTarFile);
                final TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(
                        tarFileInputStream);
                ArchiveEntry entry;
                while ((entry = tarArchiveInputStream.getNextEntry()) != null) {
                    if ("flashplayer".equals(entry.getName())) {
                        uncompressedBinary = File.createTempFile("flex-sdk-linux-flashplayer-binary-" + version,
                                ".uexe");
                        final FileOutputStream uncompressedBinaryOutputStream = new FileOutputStream(
                                uncompressedBinary);
                        while (-1 != (n = tarArchiveInputStream.read(buffer))) {
                            uncompressedBinaryOutputStream.write(buffer, 0, n);
                        }
                        uncompressedBinaryOutputStream.close();
                    } else if ("flashplayerdebugger".equals(entry.getName())) {
                        uncompressedBinary = File.createTempFile("flex-sdk-linux-flashplayer-binary-" + version,
                                ".uexe");
                        final FileOutputStream uncompressedBinaryOutputStream = new FileOutputStream(
                                uncompressedBinary);
                        while (-1 != (n = tarArchiveInputStream.read(buffer))) {
                            uncompressedBinaryOutputStream.write(buffer, 0, n);
                        }
                        uncompressedBinaryOutputStream.close();
                    }
                }
                tarFileInputStream.close();

                // If a binary exists, copy it to the target and create a pom for it.
                if (uncompressedBinary != null) {
                    if (!targetDir.exists()) {
                        if (!targetDir.mkdirs()) {
                            throw new RuntimeException(
                                    "Could not create directory: " + targetDir.getAbsolutePath());
                        }
                    }
                    final File targetFile = new File(targetDir, "/runtime-" + version + "-linux.uexe");
                    copyFile(uncompressedBinary, targetFile);

                    // Clean up in the temp directory.
                    if (!uncompressedBinary.delete()) {
                        System.out.println("Could not delete: " + uncompressedBinary.getAbsolutePath());
                    }
                }

                // Clean up in the temp directory.
                if (!tempTarFile.delete()) {
                    System.out.println("Could not delete: " + tempTarFile.getAbsolutePath());
                }
            }

            final MavenMetadata playerArtifact = new MavenMetadata();
            playerArtifact.setGroupId("com.adobe.flash");
            playerArtifact.setArtifactId("runtime");
            playerArtifact.setVersion(version);
            playerArtifact.setPackaging("exe");

            writeDocument(createPomDocument(playerArtifact),
                    new File(targetDir, "runtime-" + version + ".pom"));
        }
    }
}