List of usage examples for java.io FilenameFilter FilenameFilter
FilenameFilter
From source file:ftp_server.FileUpload.java
public void fileSelecting() throws IOException { File f = new File("D:\\jpg"); FilenameFilter textfile = new FilenameFilter() { @Override/*from w w w . j av a2 s .c om*/ public boolean accept(File dir, String name) { // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. return name.toLowerCase().endsWith(".jpg"); } }; File[] files = f.listFiles(textfile); for (File file : files) { if (file.isDirectory()) { System.out.println("Directory"); } else { System.out.println("File : "); } System.out.println(file.getAbsolutePath()); System.out.println(file.getCanonicalPath()); System.out.println(file.getName()); } }
From source file:de.langmi.spring.batch.examples.playground.file.resource.FiltersFoldersResourceFactory.java
public static Resource[] getInstance(final String filePath, final List<String> acceptedFolders) { final List<FileSystemResource> files = new ArrayList<FileSystemResource>(); runNestedDirs(new File(filePath), files, new FilenameFilter() { @Override// www . j a va2 s . c o m public boolean accept(File dir, String name) { // accept all files, made easy here, files shall contain a suffix separator if (name.contains(".")) { return true; } else if (acceptedFolders.contains(name)) { return true; } else { return false; } } }); return files.toArray(new Resource[0]); }
From source file:io.github.azige.mages.Util.java
static List<Plugin> loadPluginsFromDirectory(File dir) { List<Plugin> list = new LinkedList<>(); File[] files = dir.listFiles(new FilenameFilter() { @Override/*from ww w . j a v a 2 s .c om*/ public boolean accept(File dir, String name) { return name.endsWith(".groovy"); } }); if (files == null) { return list; } try { GroovyClassLoader loader = new GroovyClassLoader(); loader.addClasspath(dir.getCanonicalPath()); final int extLength = ".groovy".length(); for (File f : files) { String name = f.getName(); String script = FileUtils.readFileToString(f, "UTF-8"); list.add(wrapPlugin(name.substring(0, name.length() - extLength), loader.parseClass(script).newInstance())); } } catch (Exception ex) { throw new MagesException(ex); } return list; }
From source file:eu.sisob.uma.footils.File.FileFootils.java
public static File[] finderByName(String dirName, final String fileName) { File dir = new File(dirName); return dir.listFiles(new FilenameFilter() { public boolean accept(File dir, String filename) { return filename.endsWith(fileName + ".*"); }/* w w w.java 2 s . c o m*/ }); }
From source file:com.taobao.datasource.DataSourceConfigFinder.java
@Override protected File[] findConfigFiles(File currentPath) { FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith("-ds.xml"); }//www .j a va 2 s. c o m }; File[] files = currentPath.listFiles(filter); // try conf/*-ds.xml if (ArrayUtils.isEmpty(files)) { File configDir = new File(currentPath, "conf"); if (configDir.isDirectory()) { files = configDir.listFiles(filter); } } return files; }
From source file:docbook.ArticleRoundTripTest.java
private static TestSuite listCases(File dir) { TestSuite cases = new TestSuite(dir.getName()); String[] testFiles = dir.list(new FilenameFilter() { public boolean accept(File file, String filename) { return !filename.startsWith(".") && filename.endsWith(".docbook"); }/*from www . j av a2s . c om*/ }); Arrays.sort(testFiles); for (String filename : testFiles) { File f = new File(dir, filename); if (f.isDirectory()) { cases.addTest(listCases(f)); } else { String name = f.getAbsolutePath(); if (f.getPath().startsWith(testDir.getPath() + '/')) { name = f.getPath().substring(testDir.getPath().length() + 1); } cases.addTest(new ArticleRoundTripTest(name)); } } return cases; }
From source file:com.vaadin.sass.testcases.scss.AbstractDirectoryScanningSassTests.java
private static File[] getScssFiles(URL directoryUrl) throws URISyntaxException { URL sasslangUrl = directoryUrl; File sasslangDir = new File(sasslangUrl.toURI()); File scssDir = new File(sasslangDir, "scss"); Assert.assertTrue(scssDir.exists()); return scssDir.listFiles(new FilenameFilter() { @Override/*w w w. j av a 2 s . co m*/ public boolean accept(File dir, String name) { return name.endsWith(".scss"); } }); }
From source file:core.Utility.java
public static boolean hasTextFiles(File file) { if (file.isDirectory()) { String[] files = file.list(new FilenameFilter() { @Override/*from w ww .ja v a 2 s.c o m*/ public boolean accept(File dir, String name) { return (name.toLowerCase().endsWith(".txt")); } }); return (files.length > 0); } return true; }
From source file:imp.lstm.main.Driver.java
public static void main(String[] args) throws FileNotFoundException, IOException, ConfigurationException, InvalidParametersException { FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>( PropertiesConfiguration.class).configure( new Parameters().properties().setFileName(args[0]).setThrowExceptionOnMissing(true) .setListDelimiterHandler(new DefaultListDelimiterHandler(';')) .setIncludesAllowed(false)); Configuration config = builder.getConfiguration(); String inputSongPath = config.getString("input_song"); String outputFolderPath = config.getString("output_folder"); String autoEncoderParamsPath = config.getString("auto_encoder_params"); String nameGeneratorParamsPath = config.getString("name_generator_params"); String queueFolderPath = config.getString("queue_folder"); String referenceQueuePath = config.getString("reference_queue", "nil"); String inputCorpusFolder = config.getString("input_corpus_folder"); boolean shouldWriteQueue = config.getBoolean("should_write_generated_queue"); boolean frankensteinTest = config.getBoolean("queue_tests_frankenstein"); boolean interpolateTest = config.getBoolean("queue_tests_interpolation"); boolean iterateOverCorpus = config.getBoolean("iterate_over_corpus", false); boolean shouldGenerateSongTitle = config.getBoolean("generate_song_title"); boolean shouldGenerateSong = config.getBoolean("generate_leadsheet"); LogTimer.initStartTime(); //start our logging timer to keep track of our execution time LogTimer.log("Creating name generator..."); //here is just silly code for generating name based on an LSTM lol $wag LSTM lstm = new LSTM(); FullyConnectedLayer fullLayer = new FullyConnectedLayer(Operations.None); Loadable titleNetLoader = new Loadable() { @Override//from www . j a v a2 s .c o m public boolean load(INDArray array, String path) { String car = pathCar(path); String cdr = pathCdr(path); switch (car) { case "full": return fullLayer.load(array, cdr); case "lstm": return lstm.load(array, cdr); default: return false; } } }; LogTimer.log("Packing name generator from files..."); (new NetworkConnectomeLoader()).load(nameGeneratorParamsPath, titleNetLoader); String characterString = " !\"'[],-.01245679:?ABCDEFGHIJKLMNOPQRSTUVWYZabcdefghijklmnopqrstuvwxyz"; //Initialization LogTimer.log("Creating autoencoder..."); int inputSize = 34; int outputSize = EncodingParameters.noteEncoder.getNoteLength(); int featureVectorSize = 100; ProductCompressingAutoencoder autoencoder = new ProductCompressingAutoencoder(24, 48, 84 + 1, false); //create our network int numInterpolationDivisions = 5; //"pack" the network from weights and biases file directory LogTimer.log("Packing autoencoder from files"); (new NetworkConnectomeLoader()).load(autoEncoderParamsPath, autoencoder); File[] songFiles; if (iterateOverCorpus) { songFiles = new File(inputCorpusFolder).listFiles(); } else { songFiles = new File[] { new File(inputSongPath) }; } for (File inputFile : songFiles) { (new NetworkConnectomeLoader()).refresh(autoEncoderParamsPath, autoencoder, "initialstate"); String songTitle; if (shouldGenerateSong) { Random rand = new Random(); AVector charOut = Vector.createLength(characterString.length()); GroupedSoftMaxSampler sampler = new GroupedSoftMaxSampler( new Group[] { new Group(0, characterString.length(), true) }); songTitle = ""; for (int i = 0; i < 50; i++) { charOut = fullLayer.forward(lstm.step(charOut)); charOut = sampler.filter(charOut); int charIndex = 0; for (; charIndex < charOut.length(); charIndex++) { if (charOut.get(charIndex) == 1.0) { break; } } songTitle += characterString.substring(charIndex, charIndex + 1); } songTitle = songTitle.trim(); LogTimer.log("Generated song name: " + songTitle); } else { songTitle = "The Song We Never Name"; } LogTimer.log("Reading file..."); LeadSheetDataSequence inputSequence = LeadSheetIO.readLeadSheet(inputFile); //read our leadsheet to get a data vessel as retrieved in rbm-provisor LeadSheetDataSequence outputSequence = inputSequence.copy(); outputSequence.clearMelody(); if (interpolateTest) { LeadSheetDataSequence additionalOutput = outputSequence.copy(); for (int i = 0; i < numInterpolationDivisions; i++) { outputSequence.concat(additionalOutput.copy()); } } LeadSheetDataSequence decoderInputSequence = outputSequence.copy(); LogTimer.startLog("Encoding data..."); //TradingTimer.initStart(); //start our trading timer to keep track our our generation versus realtime play while (inputSequence.hasNext()) { //iterate through time steps in input data //TradingTimer.waitForNextTimedInput(); autoencoder.encodeStep(inputSequence.retrieve()); //feed the resultant input vector into the network if (advanceDecoding) { //if we are using advance decoding (we start decoding as soon as we can) if (autoencoder.canDecode()) { //if queue has enough data to decode from outputSequence.pushStep(null, null, autoencoder.decodeStep(decoderInputSequence.retrieve())); //take sampled data for a timestep from autoencoder //TradingTimer.logTimestep(); //log our time to TradingTimer so we can know how far ahead of realtime we are } } } LogTimer.endLog(); if (shouldWriteQueue) { String queueFilePath = queueFolderPath + java.io.File.separator + inputFile.getName().replace(".ls", ".q"); FragmentedNeuralQueue currQueue = autoencoder.getQueue(); currQueue.writeToFile(queueFilePath); LogTimer.log("Wrote queue " + inputFile.getName().replace(".ls", ".q") + " to file..."); } if (shouldGenerateSong) { if (interpolateTest) { FragmentedNeuralQueue refQueue = new FragmentedNeuralQueue(); refQueue.initFromFile(referenceQueuePath); FragmentedNeuralQueue currQueue = autoencoder.getQueue(); //currQueue.writeToFile(queueFilePath); autoencoder.setQueue(currQueue.copy()); while (autoencoder.hasDataStepsLeft()) { //we are done encoding all time steps, so just finish decoding!{ outputSequence.pushStep(null, null, autoencoder.decodeStep(decoderInputSequence.retrieve())); //take sampled data for a timestep from autoencoder //TradingTimer.logTimestep(); //log our time to TradingTimer so we can know how far ahead of realtime we are } for (int i = 1; i <= numInterpolationDivisions; i++) { System.out.println("Starting interpolation " + ((1.0 / numInterpolationDivisions) * (i))); (new NetworkConnectomeLoader()).refresh(autoEncoderParamsPath, autoencoder, "initialstate"); FragmentedNeuralQueue currCopy = currQueue.copy(); currCopy.basicInterpolate(refQueue, (1.0 / numInterpolationDivisions) * (i)); autoencoder.setQueue(currCopy); int timeStep = 0; while (autoencoder.hasDataStepsLeft()) { //we are done encoding all time steps, so just finish decoding!{ System.out.println("interpolation " + i + " step " + ++timeStep); outputSequence.pushStep(null, null, autoencoder.decodeStep(decoderInputSequence.retrieve())); //take sampled data for a timestep from autoencoder //TradingTimer.logTimestep(); //log our time to TradingTimer so we can know how far ahead of realtime we are } } } if (frankensteinTest) { LogTimer.startLog("Loading queues"); File queueFolder = new File(queueFolderPath); int numComponents = config.getInt("frankenstein_num_components", 5); int numCombinations = config.getInt("frankenstein_num_combinations", 6); double interpolationMagnitude = config.getDouble("frankenstein_magnitude", 2.0); if (queueFolder.isDirectory()) { File[] queueFiles = queueFolder.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.contains(".q"); } }); List<File> fileList = new ArrayList<>(); for (File file : queueFiles) { fileList.add(file); } Collections.shuffle(fileList); int numSelectedFiles = (numComponents > queueFiles.length) ? queueFiles.length : numComponents; for (int i = 0; i < queueFiles.length - numSelectedFiles; i++) { fileList.remove(fileList.size() - 1); } List<FragmentedNeuralQueue> queuePopulation = new ArrayList<>(fileList.size()); songTitle += " - a mix of "; for (File file : fileList) { FragmentedNeuralQueue newQueue = new FragmentedNeuralQueue(); newQueue.initFromFile(file.getPath()); queuePopulation.add(newQueue); songTitle += file.getName().replaceAll(".ls", "") + ", "; } LogTimer.endLog(); LeadSheetDataSequence additionalOutput = outputSequence.copy(); for (int i = 1; i < numCombinations; i++) { outputSequence.concat(additionalOutput.copy()); } decoderInputSequence = outputSequence.copy(); FragmentedNeuralQueue origQueue = autoencoder.getQueue(); for (int i = 0; i < numCombinations; i++) { LogTimer.startLog("Performing queue interpolation..."); AVector combinationStrengths = Vector.createLength(queuePopulation.size()); Random vectorRand = new Random(i); for (int j = 0; j < combinationStrengths.length(); j++) { combinationStrengths.set(j, vectorRand.nextDouble()); } combinationStrengths.divide(combinationStrengths.elementSum()); FragmentedNeuralQueue currQueue = origQueue.copy(); for (int k = 0; k < combinationStrengths.length(); k++) { currQueue.basicInterpolate(queuePopulation.get(k), combinationStrengths.get(k) * interpolationMagnitude); } LogTimer.endLog(); autoencoder.setQueue(currQueue); LogTimer.startLog("Refreshing autoencoder state..."); (new NetworkConnectomeLoader()).refresh(autoEncoderParamsPath, autoencoder, "initialstate"); LogTimer.endLog(); LogTimer.startLog("Decoding segment..."); while (autoencoder.hasDataStepsLeft()) { //we are done encoding all time steps, so just finish decoding!{ outputSequence.pushStep(null, null, autoencoder.decodeStep(decoderInputSequence.retrieve())); //take sampled data for a timestep from autoencoder //TradingTimer.logTimestep(); //log our time to TradingTimer so we can know how far ahead of realtime we are } LogTimer.endLog(); } } } while (autoencoder.hasDataStepsLeft()) { //we are done encoding all time steps, so just finish decoding!{ outputSequence.pushStep(null, null, autoencoder.decodeStep(decoderInputSequence.retrieve())); //take sampled data for a timestep from autoencoder //TradingTimer.logTimestep(); //log our time to TradingTimer so we can know how far ahead of realtime we are } LogTimer.log("Writing file..."); String outputFilename = outputFolderPath + java.io.File.separator + inputFile.getName().replace(".ls", "_Output"); //we'll write our generated file with the same name plus "_Output" LeadSheetIO.writeLeadSheet(outputSequence, outputFilename, songTitle); System.out.println(outputFilename); } else { autoencoder.setQueue(new FragmentedNeuralQueue()); } } LogTimer.log("Process finished"); //Done! }
From source file:com.cprassoc.solr.auth.model.HistoryVersion.java
private void init() { history = new LinkedHashMap<>(); try {/*from w ww . j a va2 s . c o m*/ if (!historyDir.exists()) { historyDir.mkdirs(); } else { FilenameFilter fileNameFilter = new FilenameFilter() { @Override public boolean accept(File dir, String name) { if (name.contains(".json")) { return true; } return false; } }; File[] files = historyDir.listFiles(fileNameFilter); File file; String json; JSONObject jsonObj; for (int i = 0; i < files.length; i++) { file = files[i]; json = Utils.streamToString(new FileInputStream(file)); jsonObj = new JSONObject(json); String key = jsonObj.getString("key"); JSONObject data = new JSONObject(jsonObj.getString("data")); String title = jsonObj.getString("title"); String desc = jsonObj.getString("description"); Date date = new Date(jsonObj.getString("date")); SecurityJson secu = new SecurityJson(data); SavedVersion version = new SavedVersion(title, desc, date, secu); Log.log(getClass(), "Adding Version: " + version.getTitle()); this.history.put(key, version); } } } catch (Exception e) { e.printStackTrace(); } }