Search in sources :

Example 91 with FilenameFilter

use of java.io.FilenameFilter in project jdk8u_jdk by JetBrains.

the class RmiBootstrapTest method findConfigurationFilesKo.

/**
     * Get all "management*ko.properties" files in the directory
     * indicated by the "test.src" management property.
     **/
private static File[] findConfigurationFilesKo() {
    final String testSrc = System.getProperty("test.src");
    final File dir = new File(testSrc);
    final FilenameFilter filter = new ConfigFilenameFilter("management_test", "ko.properties");
    return dir.listFiles(filter);
}
Also used : FilenameFilter(java.io.FilenameFilter) File(java.io.File)

Example 92 with FilenameFilter

use of java.io.FilenameFilter in project jdk8u_jdk by JetBrains.

the class NulFile method test.

@SuppressWarnings("deprecation")
private static void test(File testFile, boolean derived) {
    boolean exceptionThrown = false;
    if (testFile == null) {
        throw new RuntimeException("test file should not be null.");
    }
    // getPath()
    if (testFile.getPath().indexOf(CHAR_NUL) < 0) {
        throw new RuntimeException("File path should contain Nul character");
    }
    // getAbsolutePath()
    if (testFile.getAbsolutePath().indexOf(CHAR_NUL) < 0) {
        throw new RuntimeException("File absolute path should contain Nul character");
    }
    // getAbsoluteFile()
    File derivedAbsFile = testFile.getAbsoluteFile();
    if (derived) {
        if (derivedAbsFile.getPath().indexOf(CHAR_NUL) < 0) {
            throw new RuntimeException("Derived file path should also contain Nul character");
        }
    } else {
        test(derivedAbsFile, true);
    }
    // getCanonicalPath()
    try {
        exceptionThrown = false;
        testFile.getCanonicalPath();
    } catch (IOException ex) {
        if (ExceptionMsg.equals(ex.getMessage()))
            exceptionThrown = true;
    }
    if (!exceptionThrown) {
        throw new RuntimeException("getCanonicalPath() should throw IOException with" + " message \"" + ExceptionMsg + "\"");
    }
    // getCanonicalFile()
    try {
        exceptionThrown = false;
        testFile.getCanonicalFile();
    } catch (IOException ex) {
        if (ExceptionMsg.equals(ex.getMessage()))
            exceptionThrown = true;
    }
    if (!exceptionThrown) {
        throw new RuntimeException("getCanonicalFile() should throw IOException with" + " message \"" + ExceptionMsg + "\"");
    }
    // toURL()
    try {
        exceptionThrown = false;
        testFile.toURL();
    } catch (MalformedURLException ex) {
        if (ExceptionMsg.equals(ex.getMessage()))
            exceptionThrown = true;
    }
    if (!exceptionThrown) {
        throw new RuntimeException("toURL() should throw IOException with" + " message \"" + ExceptionMsg + "\"");
    }
    // canRead()
    if (testFile.canRead())
        throw new RuntimeException("File should not be readable");
    // canWrite()
    if (testFile.canWrite())
        throw new RuntimeException("File should not be writable");
    // exists()
    if (testFile.exists())
        throw new RuntimeException("File should not be existed");
    // isDirectory()
    if (testFile.isDirectory())
        throw new RuntimeException("File should not be a directory");
    // isFile()
    if (testFile.isFile())
        throw new RuntimeException("File should not be a file");
    // isHidden()
    if (testFile.isHidden())
        throw new RuntimeException("File should not be hidden");
    // lastModified()
    if (testFile.lastModified() != 0L)
        throw new RuntimeException("File last modified time should be 0L");
    // length()
    if (testFile.length() != 0L)
        throw new RuntimeException("File length should be 0L");
    // createNewFile()
    try {
        exceptionThrown = false;
        testFile.createNewFile();
    } catch (IOException ex) {
        if (ExceptionMsg.equals(ex.getMessage()))
            exceptionThrown = true;
    }
    if (!exceptionThrown) {
        throw new RuntimeException("createNewFile() should throw IOException with" + " message \"" + ExceptionMsg + "\"");
    }
    // delete()
    if (testFile.delete())
        throw new RuntimeException("Delete operation should fail");
    // list()
    if (testFile.list() != null)
        throw new RuntimeException("File list() should return null");
    // list(FilenameFilter)
    FilenameFilter fnFilter = new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return false;
        }
    };
    if (testFile.list(fnFilter) != null) {
        throw new RuntimeException("File list(FilenameFilter) should" + " return null");
    }
    // listFiles()
    if (testFile.listFiles() != null)
        throw new RuntimeException("File listFiles() should return null");
    // listFiles(FilenameFilter)
    if (testFile.listFiles(fnFilter) != null) {
        throw new RuntimeException("File listFiles(FilenameFilter)" + " should return null");
    }
    // listFiles(FileFilter)
    FileFilter fFilter = new FileFilter() {

        @Override
        public boolean accept(File file) {
            return false;
        }
    };
    if (testFile.listFiles(fFilter) != null) {
        throw new RuntimeException("File listFiles(FileFilter)" + " should return null");
    }
    // mkdir()
    if (testFile.mkdir()) {
        throw new RuntimeException("File should not be able to" + " create directory");
    }
    // mkdirs()
    if (testFile.mkdirs()) {
        throw new RuntimeException("File should not be able to" + " create directories");
    }
    // renameTo(File)
    if (testFile.renameTo(new File("dest")))
        throw new RuntimeException("File rename should fail");
    if (new File("dest").renameTo(testFile))
        throw new RuntimeException("File rename should fail");
    try {
        exceptionThrown = false;
        testFile.renameTo(null);
    } catch (NullPointerException ex) {
        exceptionThrown = true;
    }
    if (!exceptionThrown) {
        throw new RuntimeException("File rename should thrown NPE");
    }
    // setLastModified(long)
    if (testFile.setLastModified(0L)) {
        throw new RuntimeException("File should fail to set" + " last modified time");
    }
    try {
        exceptionThrown = false;
        testFile.setLastModified(-1);
    } catch (IllegalArgumentException ex) {
        if ("Negative time".equals(ex.getMessage()))
            exceptionThrown = true;
    }
    if (!exceptionThrown) {
        throw new RuntimeException("File should fail to set" + " last modified time with message \"Negative time\"");
    }
    // setReadOnly()
    if (testFile.setReadOnly())
        throw new RuntimeException("File should fail to set read-only");
    // setWritable(boolean writable, boolean ownerOnly)
    if (testFile.setWritable(true, true))
        throw new RuntimeException("File should fail to set writable");
    if (testFile.setWritable(true, false))
        throw new RuntimeException("File should fail to set writable");
    if (testFile.setWritable(false, true))
        throw new RuntimeException("File should fail to set writable");
    if (testFile.setWritable(false, false))
        throw new RuntimeException("File should fail to set writable");
    // setWritable(boolean writable)
    if (testFile.setWritable(false))
        throw new RuntimeException("File should fail to set writable");
    if (testFile.setWritable(true))
        throw new RuntimeException("File should fail to set writable");
    // setReadable(boolean readable, boolean ownerOnly)
    if (testFile.setReadable(true, true))
        throw new RuntimeException("File should fail to set readable");
    if (testFile.setReadable(true, false))
        throw new RuntimeException("File should fail to set readable");
    if (testFile.setReadable(false, true))
        throw new RuntimeException("File should fail to set readable");
    if (testFile.setReadable(false, false))
        throw new RuntimeException("File should fail to set readable");
    // setReadable(boolean readable)
    if (testFile.setReadable(false))
        throw new RuntimeException("File should fail to set readable");
    if (testFile.setReadable(true))
        throw new RuntimeException("File should fail to set readable");
    // setExecutable(boolean executable, boolean ownerOnly)
    if (testFile.setExecutable(true, true))
        throw new RuntimeException("File should fail to set executable");
    if (testFile.setExecutable(true, false))
        throw new RuntimeException("File should fail to set executable");
    if (testFile.setExecutable(false, true))
        throw new RuntimeException("File should fail to set executable");
    if (testFile.setExecutable(false, false))
        throw new RuntimeException("File should fail to set executable");
    // setExecutable(boolean executable)
    if (testFile.setExecutable(false))
        throw new RuntimeException("File should fail to set executable");
    if (testFile.setExecutable(true))
        throw new RuntimeException("File should fail to set executable");
    // canExecute()
    if (testFile.canExecute())
        throw new RuntimeException("File should not be executable");
    // getTotalSpace()
    if (testFile.getTotalSpace() != 0L)
        throw new RuntimeException("The total space should be 0L");
    // getFreeSpace()
    if (testFile.getFreeSpace() != 0L)
        throw new RuntimeException("The free space should be 0L");
    // getUsableSpace()
    if (testFile.getUsableSpace() != 0L)
        throw new RuntimeException("The usable space should be 0L");
    // compareTo(File null)
    try {
        exceptionThrown = false;
        testFile.compareTo(null);
    } catch (NullPointerException ex) {
        exceptionThrown = true;
    }
    if (!exceptionThrown) {
        throw new RuntimeException("compareTo(null) should throw NPE");
    }
    // toString()
    if (testFile.toString().indexOf(CHAR_NUL) < 0) {
        throw new RuntimeException("File path should contain Nul character");
    }
    // toPath()
    try {
        exceptionThrown = false;
        testFile.toPath();
    } catch (InvalidPathException ex) {
        exceptionThrown = true;
    }
    if (!exceptionThrown) {
        throw new RuntimeException("toPath() should throw" + " InvalidPathException");
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileFilter(java.io.FileFilter) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) InvalidPathException(java.nio.file.InvalidPathException)

Example 93 with FilenameFilter

use of java.io.FilenameFilter in project azure-tools-for-java by Microsoft.

the class SDKJarsFilter method getClasspathEntriesOfAzureLibabries.

public IClasspathEntry[] getClasspathEntriesOfAzureLibabries(IPath containerPath) {
    String sdkID = "com.microsoft.azuretools.sdk";
    Bundle bundle = Platform.getBundle(sdkID);
    // Search the available SDKs
    Bundle[] bundles = Platform.getBundles(sdkID, null);
    List<IClasspathEntry> listEntries = new ArrayList<IClasspathEntry>();
    if (bundles != null) {
        for (Bundle bundle2 : bundles) {
            if (bundle2.getVersion().toString().startsWith(containerPath.segment(1))) {
                bundle = bundle2;
                break;
            }
        }
        // Get the SDK jar.
        URL sdkJar = FileLocator.find(bundle, new Path("azure-1.0.0.jar"), null);
        URL resSdkJar = null;
        IClasspathAttribute[] attr = null;
        try {
            if (sdkJar != null) {
                resSdkJar = FileLocator.resolve(sdkJar);
            // create classpath attribute for java doc, if present
            }
            if (resSdkJar == null) {
                /*
					 * if sdk jar is not present then create an place holder for
					 * sdk jar so that it would be shown as missing file
					 */
                URL bundleLoc = new URL(bundle.getLocation());
                StringBuffer strBfr = new StringBuffer(bundleLoc.getPath());
                strBfr.append(File.separator).append("azure-1.0.0.jar");
                URL jarLoc = new URL(strBfr.toString());
                IPath jarPath = new Path(FileLocator.resolve(jarLoc).getPath());
                File jarFile = jarPath.toFile();
                listEntries.add(JavaCore.newLibraryEntry(new Path(jarFile.getAbsolutePath()), null, null, null, attr, true));
            } else {
                File directory = new File(resSdkJar.getPath());
                // create the library entry for sdk jar
                listEntries.add(JavaCore.newLibraryEntry(new Path(directory.getAbsolutePath()), null, null, null, attr, true));
                FilenameFilter sdkJarsFilter = new SDKJarsFilter();
                File[] jars = new File(String.format("%s%s%s", directory.getParent(), File.separator, Messages.depLocation)).listFiles(sdkJarsFilter);
                for (int i = 0; i < jars.length; i++) {
                    listEntries.add(JavaCore.newLibraryEntry(new Path(jars[i].getAbsolutePath()), null, null, null, attr, true));
                }
            }
        } catch (Exception e) {
            listEntries = new ArrayList<IClasspathEntry>();
            Activator.getDefault().log(Messages.excp, e);
        }
    }
    IClasspathEntry[] entries = new IClasspathEntry[listEntries.size()];
    // Return the classpath entries.
    return listEntries.toArray(entries);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException) IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) FilenameFilter(java.io.FilenameFilter) File(java.io.File)

Example 94 with FilenameFilter

use of java.io.FilenameFilter in project wildfly by wildfly.

the class FailoverTestCase method listSharedStoreDir.

private void listSharedStoreDir() {
    final File SHARED_STORE_DIR = new File(System.getProperty("java.io.tmpdir"), "activemq");
    if (!SHARED_STORE_DIR.exists()) {
        return;
    }
    log.trace("@@@@@@@@@@@@@@@@@@@@@@@@@");
    log.trace("SHARED_STORE_DIR = " + SHARED_STORE_DIR);
    for (File file : SHARED_STORE_DIR.listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return true;
        }
    })) {
        log.trace(String.format("+ %s [r=%s,w=%s,x=%s]\n", file, file.canRead(), file.canWrite(), file.canExecute()));
        if (file.isDirectory()) {
            for (File f : file.listFiles()) {
                log.trace("    + " + f);
            }
        }
    }
    log.trace("@@@@@@@@@@@@@@@@@@@@@@@@@");
}
Also used : FilenameFilter(java.io.FilenameFilter) File(java.io.File)

Example 95 with FilenameFilter

use of java.io.FilenameFilter in project voldemort by voldemort.

the class BdbNativeBackup method determineLastFile.

private Long determineLastFile(File backupDir, final AsyncOperationStatus status) {
    status.setStatus("Determining the last backed up file...");
    System.out.println("Backup directory is \'" + backupDir.getPath() + "\'.");
    File[] backupFiles = backupDir.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            if (!name.endsWith(BDB_EXT)) {
                return false;
            }
            String part = name.substring(0, name.length() - BDB_EXT.length());
            try {
                Long.parseLong(part, 16);
            } catch (NumberFormatException nfe) {
                status.setStatus("Warning: " + BDB_EXT + " file whose name is not a number, ignoring: " + name);
                return false;
            }
            return true;
        }
    });
    if (backupFiles == null) {
        throw new VoldemortException("Failed to read backup directory. Please check" + "if the directory exists, or permission is granted.");
    }
    if (backupFiles.length == 0) {
        status.setStatus("No backup files found, assuming a full backup is required.");
        return null;
    }
    long largest = Long.MIN_VALUE;
    for (File file : backupFiles) {
        long value = fileNameToNumber(file.getName());
        if (value > largest) {
            largest = value;
        }
    }
    status.setStatus("Last backed up file was " + largest);
    return largest;
}
Also used : FilenameFilter(java.io.FilenameFilter) File(java.io.File) VoldemortException(voldemort.VoldemortException)

Aggregations

FilenameFilter (java.io.FilenameFilter)402 File (java.io.File)398 IOException (java.io.IOException)100 ArrayList (java.util.ArrayList)72 Test (org.junit.Test)60 URL (java.net.URL)22 List (java.util.List)22 RandomAccessFile (java.io.RandomAccessFile)19 HashSet (java.util.HashSet)17 FileOutputStream (java.io.FileOutputStream)14 JarFile (java.util.jar.JarFile)14 FileNotFoundException (java.io.FileNotFoundException)13 MalformedURLException (java.net.MalformedURLException)13 HashMap (java.util.HashMap)13 FileFilter (java.io.FileFilter)11 FileWriter (java.io.FileWriter)11 ZipFile (java.util.zip.ZipFile)11 TestClient (org.syncany.tests.util.TestClient)11 FileReader (java.io.FileReader)10 Pattern (java.util.regex.Pattern)10