List of usage examples for java.io FilenameFilter FilenameFilter
FilenameFilter
From source file:com.modwiz.sponge.statue.utils.skins.SkinResolverService.java
public SkinResolverService(final File cacheDir) { checkNotNull(cacheDir);/*ww w.j av a 2 s .c o m*/ if (!cacheDir.exists()) { cacheDir.mkdirs(); } else { File[] cachedSkins = cacheDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".json"); } }); JsonParser parser = new JsonParser(); for (File file : cachedSkins) { try { JsonObject element = parser.parse(new FileReader(file)).getAsJsonObject(); long now = new Date().getTime(); long timestamp = element.get("timestamp").getAsLong(); if (new Date(now - timestamp).getMinutes() <= 45) { // Less than 45 minutes old UUID uuid = UUID.fromString(element.get("uuid").getAsString()); BufferedImage texture = ImageIO.read(new File(String.format("%s.png", uuid.toString()))); MinecraftSkin.Type skinType = MinecraftSkin.Type.valueOf(element.get("type").getAsString()); MinecraftSkin skin = new MinecraftSkin(skinType, uuid, texture, timestamp); skinCache.put(uuid, skin); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } this.cacheDir = cacheDir; skinCache = new HashMap<UUID, MinecraftSkin>(100); skinLoader = new SkinLoader(); }
From source file:com.egreen.tesla.server.api.component.ComponentManager.java
/** * * @param componentPath/*from w w w .j a va 2 s . c o m*/ * @param context * @return * @throws FileNotFoundException * @throws IOException * @throws NoSuchMethodException * @throws IllegalAccessException * @throws IllegalArgumentException * @throws InvocationTargetException * @throws ClassNotFoundException * @throws java.net.MalformedURLException * @throws org.apache.commons.configuration.ConfigurationException */ public Map<String, Component> loadComponents(String componentPath, final ServletContext context) throws FileNotFoundException, IOException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, MalformedURLException, ConfigurationException, InstantiationException, NotFoundException, CannotCompileException { LOGGER.info(context); File componentsLocation = new File(componentPath); File locations[] = componentsLocation.listFiles(new FilenameFilter() { @Override public boolean accept(File directory, String fileName) { LOGGER.info(fileName); return fileName.endsWith(".jar"); } }); for (File file : locations) { Component component = new Component(file, context); entities.addAll(component.getEntities()); COMPONENT_MAP.put(component.getComponentBasePath(), component); } return COMPONENT_MAP; }
From source file:com.catify.processengine.management.ProcessManagementServiceImpl.java
@Override public void startAllDeployedProcesses(String clientId) throws FileNotFoundException, JAXBException { // get a file list of all processes in the 'deployed' folder File deployDir = new File(ProcessImportServiceImpl.DEPLOYDIR); if (!deployDir.exists()) { LOG.warn("The folder " + ProcessImportServiceImpl.DEPLOYDIR + " does not exist. There are no processes to deploy."); } else {//www . j a v a 2 s .co m String[] fileList = deployDir.list(new FilenameFilter() { public boolean accept(File d, String name) { return name.toLowerCase().endsWith(".bpmn"); } }); // transform the xml's to jaxb and init them XmlJaxbTransformer xmlJaxbTransformer = new XmlJaxbTransformer(); ProcessInitializer processInitializer = new ProcessInitializer(); for (String processDefinition : fileList) { this.logProcessDefinitionStart(processDefinition); String processDefinitionPath = deployDir + File.separator + processDefinition; processInitializer.initializeProcessDefinition(clientId, xmlJaxbTransformer.getTDefinitionsFromBpmnXml(processDefinitionPath)); } } }
From source file:com.ogaclejapan.dotapk.manager.ApkFileManager.java
@Override public File[] getList() throws WebApiException { if (!apkDir.exists()) { throw WebApiException.asInternalServerError("does not exist: " + apkDir.getAbsolutePath()); }/*from w w w . j a v a 2 s . co m*/ return apkDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.matches(".+\\.apk"); } }); }
From source file:com.wikonos.fingerprint.activities.MainActivity.java
/** * Create dialog list of logs/*from w w w . j a v a 2 s. co m*/ * * @return */ public AlertDialog getDialogReviewLogs() { /** * List of logs */ File folder = new File(LogWriter.APPEND_PATH); final String[] files = folder.list(new FilenameFilter() { public boolean accept(File dir, String filename) { if (filename.contains(".log") && !filename.equals(LogWriter.DEFAULT_NAME) && !filename.equals(LogWriterSensors.DEFAULT_NAME) && !filename.equals(ErrorLog.DEFAULT_NAME)) return true; else return false; } }); Arrays.sort(files); ArrayUtils.reverse(files); String[] files_with_status = new String[files.length]; String[] sent_mode = { "", "(s) ", "(e) ", "(s+e) " }; for (int i = 0; i < files.length; ++i) { //0 -- not sent //1 -- server //2 -- email files_with_status[i] = sent_mode[getSentFlags(files[i], this)] + files[i]; } if (files != null && files.length > 0) { final boolean[] selected = new boolean[files.length]; final AlertDialog ald = new AlertDialog.Builder(MainActivity.this) .setMultiChoiceItems(files_with_status, selected, new DialogInterface.OnMultiChoiceClickListener() { public void onClick(DialogInterface dialog, int which, boolean isChecked) { selected[which] = isChecked; } }) .setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { // removeDialog(DIALOG_ID_REVIEW); } }) /** * Delete log */ .setNegativeButton("Delete", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //Show delete confirm standardConfirmDialog("Delete Logs", "Are you sure you want to delete selected logs?", new OnClickListener() { //Confrim Delete @Override public void onClick(DialogInterface dialog, int which) { int deleteCount = 0; boolean flagSelected = false; for (int i = 0; i < selected.length; i++) { if (selected[i]) { flagSelected = true; LogWriter.delete(files[i]); LogWriter.delete(files[i].replace(".log", ".dev")); deleteCount++; } } reviewLogsCheckItems(flagSelected); removeDialog(DIALOG_ID_REVIEW); Toast.makeText(getApplicationContext(), deleteCount + " logs deleted.", Toast.LENGTH_SHORT).show(); } }, new OnClickListener() { //Cancel Delete @Override public void onClick(DialogInterface dialog, int which) { //Do nothing dialog.dismiss(); Toast.makeText(getApplicationContext(), "Delete cancelled.", Toast.LENGTH_SHORT).show(); } }, false); } }) /** * Send to server functional **/ .setNeutralButton("Send to Server", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (isOnline()) { ArrayList<String> filesList = new ArrayList<String>(); for (int i = 0; i < selected.length; i++) if (selected[i]) { filesList.add(LogWriter.APPEND_PATH + files[i]); //Move to httplogsender //setSentFlags(files[i], 1, MainActivity.this); //Mark file as sent } if (reviewLogsCheckItems(filesList.size() > 0 ? true : false)) { DataPersistence d = new DataPersistence(getApplicationContext()); new HttpLogSender(MainActivity.this, d.getServerName() + getString(R.string.submit_log_url), filesList) .setToken(getToken()).execute(); } // removeDialog(DIALOG_ID_REVIEW); } else { standardAlertDialog(getString(R.string.msg_alert), getString(R.string.msg_no_internet), null); } } }) /** * Email **/ .setPositiveButton("eMail", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { boolean flagSelected = false; // convert from paths to Android friendly // Parcelable Uri's ArrayList<Uri> uris = new ArrayList<Uri>(); for (int i = 0; i < selected.length; i++) if (selected[i]) { flagSelected = true; /** wifi **/ File fileIn = new File(LogWriter.APPEND_PATH + files[i]); Uri u = Uri.fromFile(fileIn); uris.add(u); /** sensors **/ File fileInSensors = new File( LogWriter.APPEND_PATH + files[i].replace(".log", ".dev")); Uri uSens = Uri.fromFile(fileInSensors); uris.add(uSens); setSentFlags(files[i], 2, MainActivity.this); //Mark file as emailed } if (reviewLogsCheckItems(flagSelected)) { /** * Run sending email activity */ Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); emailIntent.setType("plain/text"); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Wifi Searcher Scan Log"); emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); startActivity(Intent.createChooser(emailIntent, "Send mail...")); } // removeDialog(DIALOG_ID_REVIEW); } }).create(); ald.getListView().setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) { AlertDialog segmentNameAlert = segmentNameDailog("Rename Segment", ald.getContext(), files[position], null, view, files, position); segmentNameAlert.setCanceledOnTouchOutside(false); segmentNameAlert.show(); return false; } }); return ald; } else { return standardAlertDialog(getString(R.string.msg_alert), getString(R.string.msg_log_nocount), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { removeDialog(DIALOG_ID_REVIEW); } }); } }
From source file:org.geomajas.sld.editor.expert.common.server.service.InMemorySldServiceImpl.java
@PostConstruct void init() throws SldException { if (getDirectory() != null) { try {/*from w w w .j a va2 s . c o m*/ if (getDirectory().getFile().exists()) { if (getDirectory().getFile().isDirectory()) { File[] sldFiles = getDirectory().getFile().listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".sld") || name.endsWith(".xml"); } }); for (File file : sldFiles) { RawSld raw = new RawSld(); raw.setXml(FileUtils.readFileToString(file, FILE_ENCODING)); String fileName = StringUtils.stripFilenameExtension(file.getName()); StyledLayerDescriptorInfo tmp = parseXml(fileName, raw.getXml()); raw.setName(fileName); raw.setTitle(tmp.getTitle()); raw.setVersion(tmp.getVersion()); log.info("added sld '{}' to service", fileName); allSlds.put(raw.getName(), raw); } } } } catch (Exception e) { // NOSONAR log.warn("Error while initilizing SLD service.", e); } } }
From source file:cc.kave.commons.externalserializationtests.ExternalTestCaseProvider.java
private static File[] getSubdirectories(File currentDirectory) { return currentDirectory.listFiles(new FilenameFilter() { @Override//ww w . ja v a2 s. co m public boolean accept(File current, String name) { return new File(current, name).isDirectory(); } }); }
From source file:io.fabric8.tooling.archetype.generator.ArchetypeTest.java
@Test public void testGenerateQuickstartArchetypes() throws Exception { String[] dirs = new File(basedir, "../archetypes").list(new FilenameFilter() { @Override// w ww . ja v a 2 s .co m public boolean accept(File dir, String name) { return new File(dir, name).isDirectory() && !EXCLUDED_ARCHETYPES.contains(name); } }); for (String dir : dirs) { assertArchetypeCreated(dir, "io.fabric8.archetypes", projectVersion); } }
From source file:io.smartspaces.launcher.bootstrap.FileConfigurationProvider.java
/** * Load all conf files in the configuration folder. *///from ww w .j a v a2 s .c om public void load() { // Look in the specified bundle directory to create a list // of all JAR files to install. File[] files = configFolder.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(CONFIGURATION_FILES_EXTENSION); } }); if (files == null || files.length == 0) { log.error(String.format("Couldn't load config files from %s\n", configFolder.getAbsolutePath())); } for (File file : files) { Properties props = new Properties(); try { props.load(new FileInputStream(file)); for (Entry<Object, Object> p : props.entrySet()) { currentConfiguration.put((String) p.getKey(), (String) p.getValue()); } } catch (IOException e) { log.error(String.format("Couldn't load config file %s\n", file)); } } }
From source file:com.beaconhill.yqd.DataDir.java
List<String> getSymbols(String directoryPath) { File dir = new File(directoryPath); String[] children = dir.list(); // It is also possible to filter the list of returned files. // This example does not return any files that start with `.'. FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { String lname = name.toLowerCase(); return lname.endsWith(".csv"); }/* w ww . j a v a2 s. co m*/ }; children = dir.list(filter); List<String> rtn = new ArrayList<String>(); for (String s : children) { try { rtn.add(FilenameUtils.getBaseName((new File(s).getCanonicalPath()).toUpperCase())); } catch (IOException ioEx) { System.err.println(ioEx.getMessage()); } } return rtn; }