List of usage examples for com.google.common.io PatternFilenameFilter PatternFilenameFilter
public PatternFilenameFilter(Pattern pattern)
From source file:net.myrrix.common.LoadRunner.java
/** * @param client recommender to load/* ww w . jav a2s. c o m*/ * @param dataDirectory a directory containing data files from which user and item IDs should be read * @param steps number of load steps to run */ public LoadRunner(MyrrixRecommender client, File dataDirectory, int steps) throws IOException { Preconditions.checkNotNull(client); Preconditions.checkNotNull(dataDirectory); Preconditions.checkArgument(steps > 0); log.info("Reading IDs..."); FastIDSet userIDsSet = new FastIDSet(); FastIDSet itemIDsSet = new FastIDSet(); Splitter comma = Splitter.on(','); for (File f : dataDirectory.listFiles(new PatternFilenameFilter(".+\\.csv(\\.(zip|gz))?"))) { for (CharSequence line : new FileLineIterable(f)) { Iterator<String> it = comma.split(line).iterator(); userIDsSet.add(Long.parseLong(it.next())); itemIDsSet.add(Long.parseLong(it.next())); } } this.client = client; this.uniqueUserIDs = userIDsSet.toArray(); this.uniqueItemIDs = itemIDsSet.toArray(); this.steps = steps; }
From source file:org.apache.s4.fixtures.CoreTestUtils.java
public static File findGradlewInRootDir() { File gradlewFile = null;/* w w w .jav a 2 s.c o m*/ if (new File(System.getProperty("user.dir")).listFiles(new PatternFilenameFilter("gradlew")).length == 1) { gradlewFile = new File(System.getProperty("user.dir") + File.separator + "gradlew"); } else { if (new File(System.getProperty("user.dir")).getParentFile().getParentFile() .listFiles(new PatternFilenameFilter("gradlew")).length == 1) { gradlewFile = new File( new File(System.getProperty("user.dir")).getParentFile().getParentFile().getAbsolutePath() + File.separator + "gradlew"); } else { Assert.fail("Cannot find gradlew executable in [" + System.getProperty("user.dir") + "] or [" + new File(System.getProperty("user.dir")).getParentFile().getAbsolutePath() + "]"); } } return gradlewFile; }
From source file:com.cedarsoft.couchdb.core.DesignDocuments.java
/** * Lists all js files within the given directory * * @param baseDir the base dir/*from w w w .j a va 2s . c o m*/ * @return the list of all files ending with "js" */ @Nonnull public static Collection<? extends File> listJsFiles(@Nonnull File baseDir) { return ImmutableList.copyOf(baseDir.listFiles(new PatternFilenameFilter(".*" + JS_SUFFIX))); }
From source file:eu.crisis_economics.abm.dashboard.cluster.script.BashScheduler.java
private void makeScriptsExecutable() { File scriptsDirectory = new File(scriptsDir + File.separator + schedulerType); String[] scripts = scriptsDirectory.list(new PatternFilenameFilter(".*\\.sh")); CommandLine commandLine = new CommandLine("chmod"); commandLine.addArgument("755"); for (String script : scripts) { commandLine.addArgument(scriptsDir + File.separator + schedulerType + File.separator + script, false); }//from w w w. j a v a 2s.c o m DefaultExecutor executor = new DefaultExecutor(); try { executor.execute(commandLine); } catch (ExecuteException e) { // ignore this; there will be an exception later, if this scheduler is used } catch (IOException e) { // ignore this; there will be an exception later, if this scheduler is used } }
From source file:ru.runa.wfe.commons.IoCommons.java
public static File[] getJarFiles(File directory) { return directory.listFiles(new PatternFilenameFilter(".*\\.jar")); }
From source file:net.myrrix.online.eval.ReconstructionEvaluator.java
private static Multimap<Long, RecommendedItem> readAndCopyDataFiles(File dataDir, File tempDir) throws IOException { Multimap<Long, RecommendedItem> data = ArrayListMultimap.create(); for (File dataFile : dataDir.listFiles(new PatternFilenameFilter(".+\\.csv(\\.(zip|gz))?"))) { log.info("Reading {}", dataFile); int count = 0; for (CharSequence line : new FileLineIterable(dataFile)) { Iterator<String> parts = COMMA_TAB_SPLIT.split(line).iterator(); long userID = Long.parseLong(parts.next()); long itemID = Long.parseLong(parts.next()); if (parts.hasNext()) { String token = parts.next().trim(); if (!token.isEmpty()) { data.put(userID, new GenericRecommendedItem(itemID, LangUtils.parseFloat(token))); }//from w w w . j a va 2 s .c o m // Ignore remove lines } else { data.put(userID, new GenericRecommendedItem(itemID, 1.0f)); } if (++count % 1000000 == 0) { log.info("Finished {} lines", count); } } Files.copy(dataFile, new File(tempDir, dataFile.getName())); } return data; }
From source file:de.hu_berlin.german.korpling.saltnpepper.debugger.PepperConversionWorker.java
private void copyFiles(File pluginDir) throws IOException { Pattern versionPattern = Pattern.compile("(-|_)?([\\.0-9]|-SNAPSHOT)+\\.jar$"); Pattern packagePattern = Pattern.compile("^de\\.hu_berlin.german\\.korpling\\.saltnpepper\\."); // copy all the needed jars into the plugin folder for (File f : selectedModules) { // delete existing other versions of this file with a heuristic // remove the version part of the current name String pureName = versionPattern.matcher(f.getName()).replaceFirst(""); // also remove a trailing package name which is used by the core pepper plugins pureName = packagePattern.matcher(pureName).replaceFirst(""); for (File existing : pluginDir.listFiles(new PatternFilenameFilter("^" + pureName + ".*\\.jar$"))) { if (existing.delete()) { log.info("Deleted existing version {}", existing.getName()); }//from w ww . j a v a2s .c o m } Files.copy(f, new File(pluginDir, f.getName())); publish("copied " + f.getName() + "\n"); } }
From source file:com.mgmtp.perfload.loadprofiles.ui.ctrl.ConfigController.java
/** * @return the availableSettingsFiles/*from www . j a va 2s . com*/ */ public Set<String> getAvailableSettingsFiles() { if (availableSettingsFiles == null) { String[] list = settingsDir.list(new PatternFilenameFilter(".*\\.xml")); if (list == null) { availableSettingsFiles = newTreeSet(); } else { availableSettingsFiles = newTreeSet(asList(list)); } } return ImmutableSet.copyOf(availableSettingsFiles); }
From source file:com.simpligility.maven.plugins.androidndk.common.UnpackedLibHelper.java
public void extractAarLib(Artifact aarArtifact) throws MojoExecutionException { final File aarFile = artifactResolverHelper.resolveArtifactToFile(aarArtifact); if (aarFile.isDirectory()) { log.warn("The aar artifact points to '" + aarFile + "' which is a directory; skipping unpacking it."); return;//from www . ja va 2s . co m } final UnArchiver unArchiver = new ZipUnArchiver(aarFile) { @Override protected Logger getLogger() { return new ConsoleLogger(log.getThreshold(), "dependencies-unarchiver"); } }; final File aarDirectory = getUnpackedLibFolder(aarArtifact); aarDirectory.mkdirs(); unArchiver.setDestDirectory(aarDirectory); log.debug("Extracting AAR to " + aarDirectory); try { unArchiver.extract(); } catch (ArchiverException e) { throw new MojoExecutionException("ArchiverException while extracting " + aarDirectory.getAbsolutePath() + ". Message: " + e.getLocalizedMessage(), e); } // Move native libraries from libs to jni folder for legacy AARs. // This ensures backward compatibility with older AARs where libs are in "libs" folder. final File jniFolder = new File(aarDirectory, UnpackedLibHelper.AAR_NATIVE_LIBRARIES_FOLDER); final File libsFolder = new File(aarDirectory, UnpackedLibHelper.APKLIB_NATIVE_LIBRARIES_FOLDER); if (!jniFolder.exists() && libsFolder.isDirectory() && libsFolder.exists()) { String[] natives = libsFolder.list(new PatternFilenameFilter("^.*(?<!(?i)\\.jar)$")); if (natives.length > 0) { log.debug("Moving AAR native libraries from libs to jni folder"); for (String nativeLibPath : natives) { try { FileUtils.moveToDirectory(new File(libsFolder, nativeLibPath), jniFolder, true); } catch (IOException e) { throw new MojoExecutionException("Could not move native libraries from " + libsFolder, e); } } } } }
From source file:com.simpligility.maven.plugins.android.common.UnpackedLibHelper.java
public void extractAarLib(Artifact aarArtifact) throws MojoExecutionException { final File aarFile = artifactResolverHelper.resolveArtifactToFile(aarArtifact); if (aarFile.isDirectory()) { log.warn("The aar artifact points to '" + aarFile + "' which is a directory; skipping unpacking it."); return;// w w w . j a va 2 s . co m } final UnArchiver unArchiver = new ZipUnArchiver(aarFile) { @Override protected Logger getLogger() { return new ConsoleLogger(log.getThreshold(), "dependencies-unarchiver"); } }; final File aarDirectory = getUnpackedLibFolder(aarArtifact); aarDirectory.mkdirs(); unArchiver.setDestDirectory(aarDirectory); log.debug("Extracting AAR to " + aarDirectory); try { unArchiver.extract(); } catch (ArchiverException e) { throw new MojoExecutionException("ArchiverException while extracting " + aarDirectory.getAbsolutePath() + ". Message: " + e.getLocalizedMessage(), e); } // Move native libraries from libs to jni folder for legacy AARs. // This ensures backward compatibility with older AARs where libs are in "libs" folder. final File jniFolder = new File(aarDirectory, AarMojo.NATIVE_LIBRARIES_FOLDER); final File libsFolder = new File(aarDirectory, ApklibMojo.NATIVE_LIBRARIES_FOLDER); if (!jniFolder.exists() && libsFolder.isDirectory() && libsFolder.exists()) { String[] natives = libsFolder.list(new PatternFilenameFilter("^.*(?<!(?i)\\.jar)$")); if (natives.length > 0) { log.debug("Moving AAR native libraries from libs to jni folder"); for (String nativeLibPath : natives) { try { FileUtils.moveToDirectory(new File(libsFolder, nativeLibPath), jniFolder, true); } catch (IOException e) { throw new MojoExecutionException("Could not move native libraries from " + libsFolder, e); } } } } }