Example usage for org.apache.commons.io.filefilter TrueFileFilter TRUE

List of usage examples for org.apache.commons.io.filefilter TrueFileFilter TRUE

Introduction

In this page you can find the example usage for org.apache.commons.io.filefilter TrueFileFilter TRUE.

Prototype

IOFileFilter TRUE

To view the source code for org.apache.commons.io.filefilter TrueFileFilter TRUE.

Click Source Link

Document

Singleton instance of true filter.

Usage

From source file:com.sangupta.keepwalking.MergeRepo.java

/**
 * @param args//  w  w w.j  a  va  2s  . c o m
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
    if (args.length != 3) {
        usage();
        return;
    }

    final String previousRepo = args[0];
    final String newerRepo = args[1];
    final String mergedRepo = args[2];

    final File previous = new File(previousRepo);
    final File newer = new File(newerRepo);
    final File merged = new File(mergedRepo);

    if (!(previous.exists() && previous.isDirectory())) {
        System.out.println("The previous version does not exists or is not a directory.");
        return;
    }

    if (!(newer.exists() && newer.isDirectory())) {
        System.out.println("The newer version does not exists or is not a directory.");
        return;
    }

    final IOFileFilter directoryFilter = FileFilterUtils.makeCVSAware(FileFilterUtils.makeSVNAware(null));

    final Collection<File> olderFiles = FileUtils.listFiles(previous, TrueFileFilter.TRUE, directoryFilter);
    final Collection<File> newerFiles = FileUtils.listFiles(newer, TrueFileFilter.TRUE, directoryFilter);

    // build a list of unique paths
    System.out.println("Reading files from older version...");
    List<String> olderPaths = new ArrayList<String>();
    for (File oldFile : olderFiles) {
        olderPaths.add(getRelativePath(oldFile, previous));
    }

    System.out.println("Reading files from newer version...");
    List<String> newerPaths = new ArrayList<String>();
    for (File newerFile : newerFiles) {
        newerPaths.add(getRelativePath(newerFile, newer));
    }

    // find which files have been removed from Perforce depot
    List<String> filesRemoved = new ArrayList<String>(olderPaths);
    filesRemoved.removeAll(newerPaths);
    System.out.println("Files removed in newer version: " + filesRemoved.size());
    for (String removed : filesRemoved) {
        System.out.print("    ");
        System.out.println(removed);
    }

    // find which files have been added in Perforce depot
    List<String> filesAdded = new ArrayList<String>(newerPaths);
    filesAdded.removeAll(olderPaths);
    System.out.println("Files added in newer version: " + filesAdded.size());
    for (String added : filesAdded) {
        System.out.print("    ");
        System.out.println(added);
    }

    // find which files are common 
    // now check if they have modified or not
    newerPaths.retainAll(olderPaths);
    List<String> modified = checkModifiedFiles(newerPaths, previous, newer);
    System.out.println("Files modified in newer version: " + modified.size());
    for (String modify : modified) {
        System.out.print("    ");
        System.out.println(modify);
    }

    // clean any previous existence of merged repo
    System.out.println("Cleaning any previous merged repositories...");
    if (merged.exists() && merged.isDirectory()) {
        FileUtils.deleteDirectory(merged);
    }

    System.out.println("Merging from newer to older repository...");
    // copy the original SVN repo to merged
    FileUtils.copyDirectory(previous, merged);

    // now remove all files that need to be
    for (String removed : filesRemoved) {
        File toRemove = new File(merged, removed);
        toRemove.delete();
    }

    // now add all files that are new in perforce
    for (String added : filesAdded) {
        File toAdd = new File(newer, added);
        File destination = new File(merged, added);
        FileUtils.copyFile(toAdd, destination);
    }

    // now over-write modified files
    for (String changed : modified) {
        File change = new File(newer, changed);
        File destination = new File(merged, changed);
        destination.delete();
        FileUtils.copyFile(change, destination);
    }

    System.out.println("Done merging.");
}

From source file:com.turn.ttorrent.cli.TorrentMain.java

/**
 * Torrent reader and creator./*from w  w  w.  ja  va 2 s.  c  o m*/
 *
 * <p>
 * You can use the {@code main()} function of this class to read or create
 * torrent files. See usage for details.
 * </p>
 *
 */
public static void main(String[] args) {
    BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%-5p: %m%n")));

    CmdLineParser parser = new CmdLineParser();
    CmdLineParser.Option help = parser.addBooleanOption('h', "help");
    CmdLineParser.Option filename = parser.addStringOption('t', "torrent");
    CmdLineParser.Option create = parser.addBooleanOption('c', "create");
    CmdLineParser.Option pieceLength = parser.addIntegerOption('l', "length");
    CmdLineParser.Option announce = parser.addStringOption('a', "announce");

    try {
        parser.parse(args);
    } catch (CmdLineParser.OptionException oe) {
        System.err.println(oe.getMessage());
        usage(System.err);
        System.exit(1);
    }

    // Display help and exit if requested
    if (Boolean.TRUE.equals((Boolean) parser.getOptionValue(help))) {
        usage(System.out);
        System.exit(0);
    }

    String filenameValue = (String) parser.getOptionValue(filename);
    if (filenameValue == null) {
        usage(System.err, "Torrent file must be provided!");
        System.exit(1);
    }

    Integer pieceLengthVal = (Integer) parser.getOptionValue(pieceLength);
    if (pieceLengthVal == null) {
        pieceLengthVal = Torrent.DEFAULT_PIECE_LENGTH;
    } else {
        pieceLengthVal = pieceLengthVal * 1024;
    }
    logger.info("Using piece length of {} bytes.", pieceLengthVal);

    Boolean createFlag = (Boolean) parser.getOptionValue(create);

    //For repeated announce urls
    @SuppressWarnings("unchecked")
    Vector<String> announceURLs = (Vector<String>) parser.getOptionValues(announce);

    String[] otherArgs = parser.getRemainingArgs();

    if (Boolean.TRUE.equals(createFlag) && (otherArgs.length != 1 || announceURLs.isEmpty())) {
        usage(System.err,
                "Announce URL and a file or directory must be " + "provided to create a torrent file!");
        System.exit(1);
    }

    OutputStream fos = null;
    try {
        if (Boolean.TRUE.equals(createFlag)) {
            if (filenameValue != null) {
                fos = new FileOutputStream(filenameValue);
            } else {
                fos = System.out;
            }

            //Process the announce URLs into URIs
            List<URI> announceURIs = new ArrayList<URI>();
            for (String url : announceURLs) {
                announceURIs.add(new URI(url));
            }

            //Create the announce-list as a list of lists of URIs
            //Assume all the URI's are first tier trackers
            List<List<URI>> announceList = new ArrayList<List<URI>>();
            announceList.add(announceURIs);

            File source = new File(otherArgs[0]);
            if (!source.exists() || !source.canRead()) {
                throw new IllegalArgumentException(
                        "Cannot access source file or directory " + source.getName());
            }

            String creator = String.format("%s (ttorrent)", System.getProperty("user.name"));

            Torrent torrent = null;
            if (source.isDirectory()) {
                List<File> files = new ArrayList<File>(
                        FileUtils.listFiles(source, TrueFileFilter.TRUE, TrueFileFilter.TRUE));
                Collections.sort(files);
                torrent = Torrent.create(source, files, pieceLengthVal, announceList, creator);
            } else {
                torrent = Torrent.create(source, pieceLengthVal, announceList, creator);
            }

            torrent.save(fos);
        } else {
            Torrent.load(new File(filenameValue), true);
        }
    } catch (Exception e) {
        logger.error("{}", e.getMessage(), e);
        System.exit(2);
    } finally {
        if (fos != System.out) {
            IOUtils.closeQuietly(fos);
        }
    }
}

From source file:com.athena.dolly.websocket.client.test.WebSocketClient.java

public static void main(String[] args) throws Exception {
    URI uri;/*from w  w w .j a va 2s. c om*/
    if (args.length > 0) {
        uri = new URI(args[0]);
    } else {
        uri = new URI("ws://localhost:7700/websocket");
    }
    WebSocketClient client = new WebSocketClient(uri);
    client.initialize();

    File directory = new File("C:/Private");
    Collection<File> files = FileUtils.listFiles(directory, TrueFileFilter.TRUE, TrueFileFilter.TRUE);

    for (Iterator<File> iterator = files.iterator(); iterator.hasNext();) {
        File file = (File) iterator.next();
        client.sendFile(file);
    }
    //client.sendFile(new File("C:/Temp/netty-master.zip"));
    client.shutdown();
}

From source file:com.partnet.automation.util.PathUtils.java

/**
 * Search for a specific file nested inside of a specific path
 * /*from   w  w w.j  a v a  2 s .  co  m*/
 * @param path
 *          - path that contains the file
 * @param fileName
 *          - file name of the file
 * @return - the file that was found
 * 
 * @throws IllegalStateException
 *           - if more then one file with that specific name was found.
 */
public static File getFileInPath(final String path, final String fileName) {
    File dir = new File(path);

    // find the correct file
    List<File> files = (List<File>) FileUtils.listFiles(dir, FileFilterUtils.nameFileFilter(fileName),
            TrueFileFilter.TRUE);

    LOG.debug("Files found: {}", Arrays.asList(files));

    if (files.size() != 1) {
        throw new IllegalStateException(String.format(
                "Searching for a file '%s' did not result in the correct number of files! Found %d, expected %d",
                fileName, files.size(), 1));
    }

    return files.get(0);
}

From source file:biz.paluch.maven.configurator.FileTemplating.java

/**
 * Process files which match the template pattern. Creates a new file using the input file with property
 * replacement. Target filename is without the template name part.
 *
 * @param log//ww  w  .  j a  v  a  2 s  .  c  om
 * @param root
 * @param processor
 * @throws IOException
 */
public static void processFiles(Log log, File root, TemplateProcessor processor) throws IOException {

    Iterator<File> iterator = FileUtils.iterateFiles(root, new RegexFileFilter(FILE_TEMPLATE_PATTERN),
            TrueFileFilter.TRUE);

    while (iterator.hasNext()) {
        File next = iterator.next();
        log.debug("Processing file " + next);
        try {
            processor.processFile(next, getTargetFile(next));
        } catch (IOException e) {
            throw new IOException("Cannot process file " + next.toString() + ": " + e.getMessage(), e);
        }
    }
}

From source file:fr.dutra.tools.maven.deptree.extras.JQueryTreeTableRenderer.java

@Override
protected Collection<File> getFilesToCopy() {
    return FileUtils.listFiles(staticDir,
            FileFilterUtils.or(new PathContainsFilter("treeTable"), new PathContainsFilter("common")),
            TrueFileFilter.TRUE);
}

From source file:de.tudarmstadt.ukp.dkpro.core.api.syntax.tagset.MappingsTest.java

@Test
public void testMappings() throws Exception {
    Collection<File> files = FileUtils.listFiles(
            new File("src/main/resources/de/tudarmstadt/ukp/dkpro/core/api/syntax/tagset"),
            new WildcardFileFilter("*.map"), TrueFileFilter.TRUE);

    assertTagsetMapping(files);//w  w w  .java 2 s .c  o m
}

From source file:de.tudarmstadt.ukp.dkpro.core.api.lexmorph.tagset.MappingsTest.java

@Test
public void testMappings() throws Exception {
    Collection<File> files = FileUtils.listFiles(
            new File("src/main/resources/de/tudarmstadt/ukp/dkpro/core/api/lexmorph/tagset"),
            new WildcardFileFilter("*-pos.map"), TrueFileFilter.TRUE);

    assertTagsetMapping(files);// www.j  a  v a2 s  . co m
}

From source file:com.moneydance.modules.features.importlist.io.ImportAllOperationTest.java

@Before
public void setUp() {
    Helper.INSTANCE.getPreferences();//from ww  w . j ava  2s .c o m
    final StubContextFactory factory = new StubContextFactory();
    StubContext context = factory.getContext();

    this.files = new ArrayList<File>();
    this.files.add(new File("."));

    this.fileOperation = new ImportAllOperation(context, TrueFileFilter.TRUE, FalseFileFilter.FALSE);
}

From source file:fr.dutra.tools.maven.deptree.extras.JQueryJSTreeRenderer.java

@Override
protected Collection<File> getFilesToCopy() {
    return FileUtils.listFiles(staticDir,
            FileFilterUtils.or(new PathContainsFilter("jstree"), new PathContainsFilter("common")),
            TrueFileFilter.TRUE);
}