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:org.geowebcache.storage.blobstore.file.FileBlobStore.java

/**
 * @throws StorageException/*from w  w  w .java  2s  .  c o m*/
 * @see org.geowebcache.storage.BlobStore#deleteByGridsetId(java.lang.String, java.lang.String)
 */
public boolean deleteByGridsetId(final String layerName, final String gridSetId) throws StorageException {

    final File layerPath = getLayerPath(layerName);
    if (!layerPath.exists() || !layerPath.canWrite()) {
        log.info(layerPath + " does not exist or is not writable");
        return false;
    }
    final String filteredGridSetId = filteredGridSetId(gridSetId);

    File[] gridSubsetCaches = layerPath.listFiles(new FileFilter() {
        public boolean accept(File pathname) {
            if (!pathname.isDirectory()) {
                return false;
            }
            String dirName = pathname.getName();
            return dirName.startsWith(filteredGridSetId);
        }
    });

    for (File gridSubsetCache : gridSubsetCaches) {
        String target = filteredLayerName(layerName) + "_" + gridSubsetCache.getName();
        stageDelete(gridSubsetCache, target);
    }

    listeners.sendGridSubsetDeleted(layerName, gridSetId);

    return true;
}

From source file:io.cloudslang.worker.management.services.WorkerManager.java

protected static String resolveDotNetVersion() {
    File dotNetHome = new File(DOTNET_PATH);
    if (dotNetHome.isDirectory()) {
        File[] versionFolders = dotNetHome.listFiles(new FileFilter() {

            @Override// ww w . j a v a  2  s. c  o  m
            public boolean accept(File file) {
                return file.isDirectory() && file.getName().startsWith("v");
            }
        });
        if (!ArrayUtils.isEmpty(versionFolders)) {
            String maxVersion = max(versionFolders, on(File.class).getName()).substring(1);
            return maxVersion.substring(0, 1) + ".x";
        }
    }
    return "N/A";
}

From source file:adalid.commons.util.FilUtils.java

public static FileFilter nameContainsFilter(final String string) {
    return new FileFilter() {

        @Override/* w ww .j  a  va 2s  .c om*/
        public boolean accept(File file) {
            return isVisibleFile(file) && StringUtils.containsIgnoreCase(file.getName(), string);
        }

    };
}

From source file:com.hoccer.tools.TestHelper.java

public static File[] getFiles(String dirName, final String pFileEnding) throws Exception {
    File dataDir = new File(dirName);
    Assert.assertTrue("dir should exists", dataDir.exists());
    Assert.assertTrue(dirName + " should be a directory", dataDir.isDirectory());
    Assert.assertTrue("dir should be readable", dataDir.canRead());

    FileFilter filter = new FileFilter() {
        public boolean accept(File f) {
            return f.getName().toLowerCase().endsWith(pFileEnding);
        }//w  w w. j av  a2 s  .c  o  m
    };

    return dataDir.listFiles(filter);
}

From source file:org.openmeetings.servlet.outputhandler.ScreenRequestHandler.java

@Override
public Template handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
        Context ctx) {//from   www.  j a va  2s.c o  m

    try {
        if (getSessionManagement() == null) {
            return getVelocityView().getVelocityEngine().getTemplate("booting.vm");
        }

        String sid = httpServletRequest.getParameter("sid");
        if (sid == null) {
            sid = "default";
        }
        log.debug("sid: " + sid);

        Long users_id = getSessionManagement().checkSession(sid);
        if (users_id == 0) {
            //checkSession will return 0 in case of invalid session
            throw new Exception("Request from invalid user " + users_id);
        }
        String publicSID = httpServletRequest.getParameter("publicSID");
        if (publicSID == null) {
            throw new Exception("publicSID is empty: " + publicSID);
        }

        String room = httpServletRequest.getParameter("room");
        if (room == null)
            room = "default";

        String domain = httpServletRequest.getParameter("domain");
        if (domain == null) {
            throw new Exception("domain is empty: " + domain);
        }

        String languageAsString = httpServletRequest.getParameter("languageAsString");
        if (languageAsString == null) {
            throw new Exception("languageAsString is empty: " + domain);
        }
        Long language_id = Long.parseLong(languageAsString);

        String rtmphostlocal = httpServletRequest.getParameter("rtmphostlocal");
        if (rtmphostlocal == null) {
            throw new Exception("rtmphostlocal is empty: " + rtmphostlocal);
        }

        String red5httpport = httpServletRequest.getParameter("red5httpport");
        if (red5httpport == null) {
            throw new Exception("red5httpport is empty: " + red5httpport);
        }

        String record = httpServletRequest.getParameter("record");
        if (record == null) {
            throw new Exception("recorder is empty: ");
        }

        String httpRootKey = httpServletRequest.getParameter("httpRootKey");
        if (httpRootKey == null) {
            throw new Exception("httpRootKey is empty could not start sharer");
        }

        String baseURL = httpServletRequest.getScheme() + "://" + rtmphostlocal + ":" + red5httpport
                + httpRootKey;

        // make a complete name out of domain(organisation) + roomname
        String roomName = domain + "_" + room;
        // trim whitespaces cause it is a directory name
        roomName = StringUtils.deleteWhitespace(roomName);

        ctx.put("rtmphostlocal", rtmphostlocal); // rtmphostlocal
        ctx.put("red5httpport", red5httpport); // red5httpport

        log.debug("httpRootKey " + httpRootKey);

        String codebase = baseURL + "screen";

        ctx.put("codebase", codebase);

        String httpSharerURL = baseURL + "ScreenServlet";

        ctx.put("webAppRootKey", httpRootKey);
        ctx.put("httpSharerURL", httpSharerURL);

        ctx.put("APP_NAME", getCfgManagement().getAppName());
        ctx.put("SID", sid);
        ctx.put("ROOM", room);
        ctx.put("DOMAIN", domain);
        ctx.put("PUBLIC_SID", publicSID);
        ctx.put("RECORDER", record);

        String requestedFile = roomName + ".jnlp";
        httpServletResponse.setContentType("application/x-java-jnlp-file");
        httpServletResponse.setHeader("Content-Disposition", "Inline; filename=\"" + requestedFile + "\"");

        log.debug("language_id :: " + language_id);
        String label_viewer = "Viewer";
        String label_sharer = "Sharer";

        try {
            label_viewer = getLabels(language_id, 728, 729, 736, 742);

            label_sharer = getLabels(language_id, 730, 731, 732, 733, 734, 735, 737, 738, 739, 740, 741, 742,
                    844, 869, 870, 871, 872, 878, 1089, 1090, 1091, 1092, 1093, 1465, 1466, 1467, 1468, 1469,
                    1470, 1471, 1472, 1473, 1474, 1475, 1476, 1477);
        } catch (Exception e) {
            log.error("Error resolving Language labels : ", e);
        }

        ctx.put("LABELVIEWER", label_viewer);
        ctx.put("LABELSHARER", label_sharer);

        log.debug("Creating JNLP Template for TCP solution");

        try {
            final String screenShareDirName = "screensharing";
            //libs
            StringBuilder libs = new StringBuilder();
            File screenShareDir = new File(ScopeApplicationAdapter.webAppPath, screenShareDirName);
            for (File jar : screenShareDir.listFiles(new FileFilter() {
                public boolean accept(File pathname) {
                    return pathname.getName().endsWith(".jar");
                }
            })) {
                libs.append("\t\t<jar href=\"").append(jar.getName()).append("\"/>\n");
            }
            addKeystore(ctx);
            ctx.put("LIBRARIES", libs);
            log.debug("RTMP Sharer labels :: " + label_sharer);

            codebase = baseURL + screenShareDirName;

            ConnectionType conType = ConnectionType.valueOf(httpServletRequest.getParameter("connectionType"));

            String startUpClass;
            switch (conType) {
            case rtmp:
                startUpClass = "org.openmeetings.screen.webstart.RTMPScreenShare";
                break;
            case rtmps:
                startUpClass = "org.openmeetings.screen.webstart.RTMPSScreenShare";
                break;
            case rtmpt:
                startUpClass = "org.openmeetings.screen.webstart.RTMPTScreenShare";
                break;
            default:
                throw new Exception("Unknown connection type");
            }

            String orgIdAsString = httpServletRequest.getParameter("organization_id");
            if (orgIdAsString == null) {
                throw new Exception("orgIdAsString is empty could not start sharer");
            }

            ctx.put("organization_id", orgIdAsString);

            ctx.put("startUpClass", startUpClass);
            ctx.put("codebase", codebase);
            ctx.put("red5-host", rtmphostlocal);
            ctx.put("red5-app", OpenmeetingsVariables.webAppRootKey + "/" + room);

            Configuration configuration = getCfgManagement().getConfKey(3L, "default.quality.screensharing");
            String default_quality_screensharing = "1";
            if (configuration != null) {
                default_quality_screensharing = configuration.getConf_value();
            }

            ctx.put("default_quality_screensharing", default_quality_screensharing);

            //invited guest does not have valid user_id (have user_id == -1)
            ctx.put("user_id", users_id);

            String port = httpServletRequest.getParameter("port");
            if (port == null) {
                throw new Exception("port is empty: ");
            }
            ctx.put("port", port);

            String allowRecording = httpServletRequest.getParameter("allowRecording");
            if (allowRecording == null) {
                throw new Exception("allowRecording is empty: ");
            }
            ctx.put("allowRecording", allowRecording);

        } catch (Exception e) {
            log.error("invalid configuration value for key screen_viewer!");
        }

        String template = "screenshare.vm";

        return getVelocityView().getVelocityEngine().getTemplate(template);

    } catch (Exception er) {
        log.error("[ScreenRequestHandler]", er);
        System.out.println("Error downloading: " + er);
    }
    return null;
}

From source file:org.doctester.rendermachine.RenderMachineImpl.java

private File[] collectAllDoctestsToCreateIndexFile(String baseDirectoryForCollectingDoctesterHtmlFiles) {

    File[] files = new File(baseDirectoryForCollectingDoctesterHtmlFiles).listFiles(new FileFilter() {

        @Override//from  w w  w .  j a va2 s.c om
        public boolean accept(File pathname) {

            if (!pathname.getName().endsWith(".html")) {
                return false;
            } else if (pathname.getName().equals(INDEX_FILE_WITHOUT_SUFFIX + ".html")) {
                return false;
            } else {
                return true;
            }

        }
    });

    return files;

}

From source file:org.cloudifysource.usm.launcher.DefaultProcessLauncher.java

private File[] getJarFilesFromDir(final File dir) {
    final File[] jars = dir.listFiles(new FileFilter() {

        @Override//from  w  w w  . ja  v a 2s  . c o  m
        public boolean accept(final File pathname) {
            return pathname.getName().endsWith(".jar") && pathname.isFile();
        }
    });
    return jars;
}

From source file:hudson.model.Job.java

@Override
public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOException {
    super.onLoad(parent, name);

    File buildDir = getBuildDir();
    runIdMigrator = new RunIdMigrator();
    runIdMigrator.migrate(buildDir, Jenkins.getInstance().getRootDir());

    TextFile f = getNextBuildNumberFile();
    if (f.exists()) {
        // starting 1.28, we store nextBuildNumber in a separate file.
        // but old Hudson didn't do it, so if the file doesn't exist,
        // assume that nextBuildNumber was read from config.xml
        try {/* w w w.  jav a2 s. c o  m*/
            synchronized (this) {
                this.nextBuildNumber = Integer.parseInt(f.readTrim());
            }
        } catch (NumberFormatException e) {
            // try to infer the value of the next build number from the existing build records. See JENKINS-11563
            File[] folders = buildDir.listFiles(new FileFilter() {
                public boolean accept(File file) {
                    return file.isDirectory() && file.getName().matches("[0-9]+");
                }
            });

            if (folders == null || folders.length == 0) {
                this.nextBuildNumber = 1;
            } else {
                Collection<Integer> foldersInt = Collections2.transform(Arrays.asList(folders),
                        new Function<File, Integer>() {
                            public Integer apply(File file) {
                                return Integer.parseInt(file.getName());
                            }
                        });
                this.nextBuildNumber = Collections.max(foldersInt) + 1;
            }
            saveNextBuildNumber();
        }
    } else {
        // From the old Hudson, or doCreateItem. Create this file now.
        saveNextBuildNumber();
    }

    if (properties == null) // didn't exist < 1.72
        properties = new CopyOnWriteList<JobProperty<? super JobT>>();

    for (JobProperty p : properties)
        p.setOwner(this);
}

From source file:com.github.thorqin.webapi.FileManager.java

public List<FileInfo> listFiles() throws IOException {
    File dir = new File(uploadDir);
    File[] array = dir.listFiles(new FileFilter() {
        @Override//ww  w  .j  a  v  a2 s.  c  o  m
        public boolean accept(File pathname) {
            return pathname.getName().matches(".+\\.json$");
        }
    });
    List<FileInfo> list = new LinkedList<>();
    for (File f : array) {
        FileInfo info = Serializer.loadJsonFile(f, FileInfo.class);
        list.add(info);
    }
    return list;
}

From source file:com.freedomotic.environment.impl.EnvironmentRepositoryImpl.java

/**
 * Loads all objects file filesystem folder and adds the objects to the
 * list.//from  w  w w  . ja v a 2 s  .co  m
 *
 * @param folder
 * @param makeUnique
 * @return
 * @throws com.freedomotic.exceptions.RepositoryException
 * @deprecated
 */
@Deprecated
private boolean loadEnvironmentsFromDir(File folder, boolean makeUnique) throws RepositoryException {
    if (folder == null) {
        throw new RepositoryException("Cannot load environments from a null folder");
    }
    environments.clear();

    // This filter only returns env files
    FileFilter envFileFilter = new FileFilter() {
        @Override
        public boolean accept(File file) {
            return file.isFile() && file.getName().endsWith(ENVIRONMENT_FILE_EXTENSION);
        }
    };

    File[] files = folder.listFiles(envFileFilter);

    for (File file : files) {
        try {
            EnvironmentLogic envLogic = loadEnvironmentFromFile(file);
            if (envLogic != null) {
                add(envLogic, false);
            }
        } catch (RepositoryException re) {
            LOG.error("Cannot add environment from file \"{}\"", file.getAbsolutePath(),
                    Freedomotic.getStackTraceInfo(re));
        }
    }

    // Load all objects in this environment
    thingsRepository.loadAll(EnvironmentRepositoryImpl.getEnvironments().get(0).getObjectFolder());

    // TODO: this return value makes no sense
    return true;
}