List of usage examples for java.io FileFilter FileFilter
FileFilter
From source file:net.minecraftforge.fml.relauncher.CoreModManager.java
private static void discoverCoreMods(File mcDir, LaunchClassLoader classLoader) { ModListHelper.parseModList(mcDir);//from w ww . java 2s. co m FMLRelaunchLog.fine("Discovering coremods"); File coreMods = setupCoreModDir(mcDir); FilenameFilter ff = new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".jar"); } }; FilenameFilter derpfilter = new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".jar.zip"); } }; File[] derplist = coreMods.listFiles(derpfilter); if (derplist != null && derplist.length > 0) { FMLRelaunchLog.severe( "FML has detected several badly downloaded jar files, which have been named as zip files. You probably need to download them again, or they may not work properly"); for (File f : derplist) { FMLRelaunchLog.severe("Problem file : %s", f.getName()); } } FileFilter derpdirfilter = new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory() && new File(pathname, "META-INF").isDirectory(); } }; File[] derpdirlist = coreMods.listFiles(derpdirfilter); if (derpdirlist != null && derpdirlist.length > 0) { FMLRelaunchLog.log.getLogger().log(Level.FATAL, "There appear to be jars extracted into the mods directory. This is VERY BAD and will almost NEVER WORK WELL"); FMLRelaunchLog.log.getLogger().log(Level.FATAL, "You should place original jars only in the mods directory. NEVER extract them to the mods directory."); FMLRelaunchLog.log.getLogger().log(Level.FATAL, "The directories below appear to be extracted jar files. Fix this before you continue."); for (File f : derpdirlist) { FMLRelaunchLog.log.getLogger().log(Level.FATAL, "Directory {} contains {}", f.getName(), Arrays.asList(new File(f, "META-INF").list())); } RuntimeException re = new RuntimeException("Extracted mod jars found, loading will NOT continue"); // We're generating a crash report for the launcher to show to the user here try { Class<?> crashreportclass = classLoader.loadClass("b"); Object crashreport = crashreportclass.getMethod("a", Throwable.class, String.class).invoke(null, re, "FML has discovered extracted jar files in the mods directory.\nThis breaks mod loading functionality completely.\nRemove the directories and replace with the jar files originally provided."); File crashreportfile = new File(new File(coreMods.getParentFile(), "crash-reports"), String.format("fml-crash-%1$tY-%1$tm-%1$td_%1$tT.txt", Calendar.getInstance())); crashreportclass.getMethod("a", File.class).invoke(crashreport, crashreportfile); System.out.println("#@!@# FML has crashed the game deliberately. Crash report saved to: #@!@# " + crashreportfile.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); // NOOP - hopefully } throw re; } File[] coreModList = coreMods.listFiles(ff); File versionedModDir = new File(coreMods, FMLInjectionData.mccversion); if (versionedModDir.isDirectory()) { File[] versionedCoreMods = versionedModDir.listFiles(ff); coreModList = ObjectArrays.concat(coreModList, versionedCoreMods, File.class); } coreModList = ObjectArrays.concat(coreModList, ModListHelper.additionalMods.values().toArray(new File[0]), File.class); coreModList = FileListHelper.sortFileList(coreModList); for (File coreMod : coreModList) { FMLRelaunchLog.fine("Examining for coremod candidacy %s", coreMod.getName()); JarFile jar = null; Attributes mfAttributes; String fmlCorePlugin; try { jar = new JarFile(coreMod); if (jar.getManifest() == null) { // Not a coremod and no access transformer list continue; } ModAccessTransformer.addJar(jar); mfAttributes = jar.getManifest().getMainAttributes(); String cascadedTweaker = mfAttributes.getValue("TweakClass"); if (cascadedTweaker != null) { FMLRelaunchLog.info("Loading tweaker %s from %s", cascadedTweaker, coreMod.getName()); Integer sortOrder = Ints.tryParse(Strings.nullToEmpty(mfAttributes.getValue("TweakOrder"))); sortOrder = (sortOrder == null ? Integer.valueOf(0) : sortOrder); handleCascadingTweak(coreMod, jar, cascadedTweaker, classLoader, sortOrder); ignoredModFiles.add(coreMod.getName()); continue; } List<String> modTypes = mfAttributes.containsKey(MODTYPE) ? Arrays.asList(mfAttributes.getValue(MODTYPE).split(",")) : ImmutableList.of("FML"); if (!modTypes.contains("FML")) { FMLRelaunchLog.fine( "Adding %s to the list of things to skip. It is not an FML mod, it has types %s", coreMod.getName(), modTypes); ignoredModFiles.add(coreMod.getName()); continue; } String modSide = mfAttributes.containsKey(MODSIDE) ? mfAttributes.getValue(MODSIDE) : "BOTH"; if (!("BOTH".equals(modSide) || FMLLaunchHandler.side.name().equals(modSide))) { FMLRelaunchLog.fine("Mod %s has ModSide meta-inf value %s, and we're %s. It will be ignored", coreMod.getName(), modSide, FMLLaunchHandler.side.name()); ignoredModFiles.add(coreMod.getName()); continue; } ModListHelper.additionalMods.putAll(extractContainedDepJars(jar, coreMods, versionedModDir)); fmlCorePlugin = mfAttributes.getValue("FMLCorePlugin"); if (fmlCorePlugin == null) { // Not a coremod FMLRelaunchLog.fine("Not found coremod data in %s", coreMod.getName()); continue; } } catch (IOException ioe) { FMLRelaunchLog.log(Level.ERROR, ioe, "Unable to read the jar file %s - ignoring", coreMod.getName()); continue; } finally { if (jar != null) { try { jar.close(); } catch (IOException e) { // Noise } } } // Support things that are mod jars, but not FML mod jars try { classLoader.addURL(coreMod.toURI().toURL()); if (!mfAttributes.containsKey(COREMODCONTAINSFMLMOD)) { FMLRelaunchLog.finer("Adding %s to the list of known coremods, it will not be examined again", coreMod.getName()); ignoredModFiles.add(coreMod.getName()); } else { FMLRelaunchLog.finer( "Found FMLCorePluginContainsFMLMod marker in %s, it will be examined later for regular @Mod instances", coreMod.getName()); candidateModFiles.add(coreMod.getName()); } } catch (MalformedURLException e) { FMLRelaunchLog.log(Level.ERROR, e, "Unable to convert file into a URL. weird"); continue; } loadCoreMod(classLoader, fmlCorePlugin, coreMod); } }
From source file:dk.statsbiblioteket.doms.radiotv.extractor.transcoder.OutputFileUtil.java
private static boolean hasPreview(TranscodeRequest request, ServletConfig config) { final String uuid = request.getPid(); final FileFilter filter = new FileFilter() { @Override/*from w w w . jav a 2s. c om*/ public boolean accept(File pathname) { return pathname.getName().startsWith(uuid + ".") && pathname.getName().contains("preview"); } }; File outputDir = getOutputDir(request, config); if (outputDir == null) { log.warn("Returned null output directory for request '" + request.getPid() + "'"); return false; } final File[] files = outputDir.listFiles(filter); if (files != null) { return files.length > 0; } else { log.warn("Null file list. Is '" + outputDir.getAbsolutePath() + "' a directory?"); return false; } }
From source file:eu.delving.sip.files.StorageHelper.java
static List<SchemaVersion> temporarilyHackedSchemaVersions(File dir) { File[] xsds = dir.listFiles(new FileFilter() { @Override//from w ww. j a v a 2 s . c o m public boolean accept(File file) { return file.isFile() && file.getName().endsWith("-validation.xsd"); } }); List<SchemaVersion> hacked = new ArrayList<SchemaVersion>(); for (File xsd : xsds) { String prefix = xsd.getName(); prefix = prefix.substring(0, prefix.indexOf("-")); for (String[] hint : RecMapping.HACK_VERSION_HINTS) { if (hint[0].equals(prefix)) hacked.add(new SchemaVersion(prefix, hint[1])); } } return hacked; }
From source file:it.readbeyond.minstrel.librarian.Librarian.java
private void discoverPublications(String storagePath, FormatHandler fh, List<Publication> publications) { FileFilter directoryFilter = new FileFilter() { public boolean accept(File file) { return file.isDirectory(); }//w w w.jav a 2 s .co m }; FileFilter fileFilter = new FileFilter() { public boolean accept(File file) { return !file.isDirectory(); } }; try { File d = new File(storagePath); if ((d.exists()) && (d.canRead()) && (d.isDirectory())) { discoverPublicationFiles(d, fh, publications, directoryFilter, fileFilter); } } catch (Exception e) { // nop } }
From source file:me.StevenLawson.TotalFreedomMod.TFM_Util.java
public static void deleteCoreDumps() { final File[] coreDumps = new File(".").listFiles(new FileFilter() { @Override//from ww w .jav a 2s . com public boolean accept(File file) { return file.getName().startsWith("java.core"); } }); for (File dump : coreDumps) { TFM_Log.info("Removing core dump file: " + dump.getName()); dump.delete(); } }
From source file:cz.cas.lib.proarc.desa.SIP2DESATransporter.java
public void adminUpload(String sourceRoot) { long timeStart = System.currentTimeMillis(); File[] sourceFiles;//from ww w . j a v a 2s . co m try { initJAXB(); File sourceFolder = new File(sourceRoot); if (!sourceFolder.exists()) { log.log(Level.SEVERE, "Source folder doesn't exist: " + sourceFolder.getAbsolutePath()); throw new IllegalStateException("Source folder doesn't exist: " + sourceFolder.getAbsolutePath()); } sourceFiles = sourceFolder.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return (pathname.getName().endsWith(".zip")); } }); if (sourceFiles == null || sourceFiles.length == 0) { log.log(Level.SEVERE, "Empty source folder: " + sourceFolder.getAbsolutePath()); throw new IllegalStateException("Empty source folder: " + sourceFolder.getAbsolutePath()); } log.info("Loaded source folder: " + sourceFolder); } catch (Exception e) { log.log(Level.SEVERE, "Error in transporter initialization.", e); throw new IllegalStateException("Error in transporter initialization.", e); } try { for (int i = 0; i < sourceFiles.length; i++) { uploadFile(sourceFiles[i], null, false); } } catch (Throwable th) { log.log(Level.SEVERE, "Error in file upload: ", th); throw new IllegalStateException("Error in file upload: ", th); } long timeFinish = System.currentTimeMillis(); log.info("Elapsed time: " + ((timeFinish - timeStart) / 1000.0) + " seconds. " + sourceFiles.length + " SIP packages transported."); log.info("RESULT: OK"); }
From source file:es.uvigo.ei.sing.adops.datatypes.ProjectExperiment.java
@Override public boolean isClean() { if (this.hasResult()) { return false; } else {//from www . j a va2 s . c o m final FileFilter filter = new FileFilter() { @Override public boolean accept(File pathname) { if (pathname.equals(ProjectExperiment.this.getNotesFile()) || pathname.equals(ProjectExperiment.this.getPropertiesFile()) || pathname.equals(ProjectExperiment.this.getFastaFile()) || pathname.equals(ProjectExperiment.this.getNamesFile())) { return false; } else if (pathname.equals(ProjectExperiment.this.getFilesFolder())) { final List<File> files = Arrays.asList(pathname.listFiles()); int countOutputFolders = 0; if (files.contains(new File(pathname, TCoffeeOutput.OUTPUT_FOLDER_NAME))) countOutputFolders++; if (files.contains(new File(pathname, MrBayesOutput.OUTPUT_FOLDER_NAME))) countOutputFolders++; if (files.contains(new File(pathname, CodeMLOutput.OUTPUT_FOLDER_NAME))) countOutputFolders++; return files.size() != countOutputFolders; } return true; } }; return this.getFolder().listFiles(filter).length == 0; } }
From source file:net.line2soft.preambul.views.ExcursionInfoActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { //Check if this version of Android allows to use custom title bars boolean feature = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); /** Set layout **/ //Base layout super.onCreate(savedInstanceState); setContentView(R.layout.activity_excursion_info); //set title bar if (feature) { getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.activity_title_bar); TextView myTitleText = (TextView) findViewById(R.id.textView0); myTitleText.setText(getString(R.string.title_activity_excursion_info)); }//from w w w. ja v a2 s.c om //Get excursion ID int id = getIntent().getIntExtra(ExcursionListActivity.EXCURSION_ID, 0); if (id > 0) { //Set listener listener = new ExcursionInfoListener(this); //Set tabs TabHost tabHost = (TabHost) findViewById(R.id.tabHost); tabHost.setup(); TabSpec spec1 = tabHost.newTabSpec("Info"); spec1.setContent(R.id.tab1); spec1.setIndicator("", getResources().getDrawable(R.drawable.description_tab)); spec1.setContent(R.id.tab1); TabSpec spec2 = tabHost.newTabSpec("POI"); spec2.setIndicator("", getResources().getDrawable(R.drawable.pois_tab)); spec2.setContent(R.id.tab2); TabSpec spec3 = tabHost.newTabSpec("Instructions"); spec3.setIndicator("", getResources().getDrawable(R.drawable.instruction_tab)); spec3.setContent(R.id.tab3); TabSpec spec4 = tabHost.newTabSpec("Photos"); spec4.setIndicator("", getResources().getDrawable(R.drawable.photos_tab)); spec4.setContent(R.id.tab4); tabHost.addTab(spec1); tabHost.addTab(spec2); tabHost.addTab(spec3); tabHost.addTab(spec4); //set the info tab try { Excursion exc = MapController.getInstance(this).getCurrentLocation().getExcursions(this).get(id); //Display locomotions Locomotion[] locomotionsItems = exc.getLocomotions(); LinearLayout locomotionsLayout = (LinearLayout) findViewById(R.id.locomotionsLayout); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); for (int i = 0; i < locomotionsItems.length; i++) { if (locomotionsItems[i].getIcon() == null) { //Define icon if undefined int imageResource = getResources().getIdentifier( "locomotion_" + locomotionsItems[i].getKey(), "drawable", getPackageName()); if (imageResource != 0) { Drawable ic = getResources().getDrawable(imageResource); locomotionsItems[i].setIcon(ic); } } ImageView img = (ImageView) inflater.inflate(R.layout.locomotion_item, null); img.setImageDrawable(locomotionsItems[i].getIcon()); locomotionsLayout.addView(img); } int value = exc.getDifficulty(); if (value == Excursion.DIFFICULTY_NONE) { ImageView view = (ImageView) findViewById(R.id.ImageView2); view.setImageResource(R.drawable.difficulte1); } else if (value == Excursion.DIFFICULTY_EASY) { ImageView view = (ImageView) findViewById(R.id.ImageView2); view.setImageResource(R.drawable.difficulte2); } else if (value == Excursion.DIFFICULTY_MEDIUM) { ImageView view = (ImageView) findViewById(R.id.ImageView2); view.setImageResource(R.drawable.difficulte3); } else if (value == Excursion.DIFFICULTY_HARD) { ImageView view = (ImageView) findViewById(R.id.ImageView2); view.setImageResource(R.drawable.difficulte4); } else if (value == Excursion.DIFFICULTY_EXPERT) { ImageView view = (ImageView) findViewById(R.id.ImageView2); view.setImageResource(R.drawable.difficulte5); } String time = ExcursionAdapter.convertTime(exc.getTime()); TextView view = (TextView) findViewById(R.id.textView1); view.setText(time); Double length = Double.valueOf(exc.getLength() / 1000); String lengthString = length.toString().substring(0, length.toString().lastIndexOf(".") + 2) + " km"; view = (TextView) findViewById(R.id.textView2); view.setText(lengthString); view = (TextView) findViewById(R.id.textView3); view.setText(exc.getDescription()); } catch (Exception e) { e.printStackTrace(); onBackPressed(); displayInfo(getString(R.string.message_excursion_not_found)); } MapController exc = MapController.getInstance(this); //set the POI tab try { PointOfInterest[] pois = exc.getCurrentLocation().getExcursions(this).get(id) .getSurroundingPois(this); List<NamedPoint> itemsList = Arrays.asList(((NamedPoint[]) pois)); Collections.sort(itemsList, new NamedPointComparator()); pois = itemsList.toArray(new PointOfInterest[itemsList.size()]); if (pois.length > 0) { ListView listPoi = (ListView) findViewById(R.id.listView2); listPoi.setAdapter(new FavoriteAdapter(getLayoutInflater(), pois, this)); listPoi.setOnItemClickListener(listener); listPoi.setVisibility(View.VISIBLE); findViewById(R.id.NoPOIs).setVisibility(View.GONE); } } catch (Exception e) { e.printStackTrace(); System.err.println("Couldn't fill POI tab"); } //set the instruction tab ListView list = (ListView) findViewById(R.id.listView1); if (list != null) { try { NavigationInstruction[] instructions = exc.getCurrentLocation().getExcursions(this).get(id) .getInstructions(); if (instructions.length != 0) { ((TextView) findViewById(R.id.NoInstructions)).setVisibility(View.GONE); } list.setAdapter(new ExcursionInfoInstructionAdapter(this, instructions)); list.setOnItemClickListener(listener); } catch (Exception e) { e.printStackTrace(); } } //Set the picture tab String imagePath = Environment.getExternalStorageDirectory().getPath() + File.separator + "Android" + File.separator + "data" + File.separator + "net.line2soft.preambul" + File.separator + "files" + File.separator + MapController.getInstance(this).getCurrentLocation().getId() + File.separator + "excursions" + File.separator + getIntent().getIntExtra(ExcursionListActivity.EXCURSION_ID, 0); FileFilter filter = new FileFilter() { @Override public boolean accept(File file) { return file.getAbsolutePath().matches(".*\\.jpg"); } }; imagesFile = new File(imagePath).listFiles(filter); ((TextView) findViewById(R.id.NoPhotos)).setVisibility(View.VISIBLE); if (imagesFile != null) { if (imagesFile.length > 0) { ((TextView) findViewById(R.id.NoPhotos)).setVisibility(View.GONE); ImagePagerAdapter adapter = new ImagePagerAdapter(getSupportFragmentManager(), imagesFile, this); ViewPager myPager = (ViewPager) findViewById(R.id.pager_images); myPager.setAdapter(adapter); myPager.setOnPageChangeListener(listener); //Set listener on right and left buttons in picture tab (findViewById(R.id.imageRight)).setOnClickListener(listener); (findViewById(R.id.imageLeft)).setOnClickListener(listener); //Change visibility of these buttons ImageView right = (ImageView) findViewById(R.id.imageRight); ImageView left = (ImageView) findViewById(R.id.imageLeft); left.setVisibility(View.INVISIBLE); right.setVisibility(View.INVISIBLE); int idPhoto = ((ViewPager) findViewById(R.id.pager_images)).getCurrentItem(); int nbPhotos = getImagesFile().length; if (idPhoto != nbPhotos - 1) { right.setVisibility(View.VISIBLE); } } } //Set listener on launch button Button launch = (Button) findViewById(R.id.button_load_excursion); launch.setOnClickListener(listener); } else { onBackPressed(); displayInfo(getString(R.string.message_excursion_not_found)); } }
From source file:com.runwaysdk.dataaccess.io.Backup.java
/** * Zips the directory and then returns the name and location of the zip file. * //from w ww . j a va 2 s . c o m * @param zipBackupFileName * @return the name and location of the zip file. */ private String zipFiles(String zipBackupFileName) { this.logPrintStream.println(ServerExceptionMessageLocalizer .compressingDirectoryMessage(Session.getCurrentLocale(), this.tempBackupFileLocation)); String zipFileNameAndLocation = this.backupFileLocation + File.separator + zipBackupFileName; this.log.trace("Creating zipfile [" + zipBackupFileName + "]"); try { FileFilter fileFilter = new FileFilter() { public boolean accept(File file) { return true; } }; FileIO.zip(this.tempBackupDir, fileFilter, new File(zipFileNameAndLocation)); } catch (IOException e) { CreateBackupException cbe = new CreateBackupException(e); cbe.setLocation(this.tempBackupDir.getAbsolutePath()); throw cbe; } this.log.trace("Finished creating zipfile [" + zipBackupFileName + "]"); return zipFileNameAndLocation; }
From source file:org.apache.carbondata.sdk.file.CSVCarbonWriterTest.java
@Test public void testTaskNo() throws IOException { // TODO: write all data type and read by CarbonRecordReader to verify the content String path = "./testWriteFiles"; FileUtils.deleteDirectory(new File(path)); Field[] fields = new Field[2]; fields[0] = new Field("stringField", DataTypes.STRING); fields[1] = new Field("intField", DataTypes.INT); try {/*from w ww. ja va 2s .co m*/ CarbonWriterBuilder builder = CarbonWriter.builder().taskNo(5).outputPath(path); CarbonWriter writer = builder.withCsvInput(new Schema(fields)).writtenBy("CSVCarbonWriterTest").build(); for (int i = 0; i < 2; i++) { String[] row = new String[] { "robot" + (i % 10), String.valueOf(i) }; writer.write(row); } writer.close(); File[] dataFiles = new File(path).listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().endsWith(CarbonCommonConstants.FACT_FILE_EXT); } }); Assert.assertNotNull(dataFiles); Assert.assertTrue(dataFiles.length > 0); String taskNo = CarbonTablePath.DataFileUtil.getTaskNo(dataFiles[0].getName()); long taskID = CarbonTablePath.DataFileUtil.getTaskIdFromTaskNo(taskNo); Assert.assertEquals("Task Id is not matched", taskID, 5); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } finally { FileUtils.deleteDirectory(new File(path)); } }