Package java.io

Examples of java.io.FilenameFilter


        //This might not work in all cases if complex rolling patterns
        //are used in Logback
        if (app instanceof RollingFileAppender) {
            final File dir = file.getParentFile();
            final String baseName = file.getName();
            return dir.listFiles(new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return name.startsWith(baseName);
                }
            });
        }
View Full Code Here


            recursive = true;
        }
        final String prefix = StringUtil.beforeFirst("*", pattern);
        final String suffix = StringUtil.afterFirst("*", pattern);
        final boolean finalRecursive = recursive;
        FilenameFilter filter = new FilenameFilter() {
            public boolean accept(File file, String name) {
                if (finalRecursive && new File(file.getPath() + File.separator + name).isDirectory()) {
                    return true;
                }
                return name.startsWith(prefix) && name.endsWith(suffix);
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public void sync() throws JournalException {
        File[] logFiles = root.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.startsWith(basename + ".");
            }
        });
        Arrays.sort(logFiles, new Comparator() {
View Full Code Here

     * version counter. A file named <code>journal.N.log</code> gets renamed to
     * <code>journal.(N+1).log</code>, whereas the main journal file gets renamed
     * to <code>journal.1.log</code>.
     */
    private void switchLogs() {
        FilenameFilter filter = new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.startsWith(basename + ".");
            }
        };
        File[] files = root.listFiles(filter);
View Full Code Here

    public static String getResults(String outputFolder) {
        File fl = new File(outputFolder);
        assertThat(String.format("Folder [%s] not found", outputFolder), fl.exists(), is(true));
        assertThat(new File(outputFolder, "_SUCCESS").exists(), is(true));

        File[] files = fl.listFiles(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                return (name.startsWith("part-r-") || name.startsWith("part-m-"));
            }
        });
View Full Code Here

      // are we in an IDE, can we guess the jar name.
      File target = new File("target");
      final String artifactName = getArtifactName();
      System.err.println("Listing files in "+target.getAbsolutePath()+" looking for "+artifactName);
     
      File[] jars = target.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
          if (!name.endsWith(".jar")) {
            return false;
          }
View Full Code Here

    public static String[] getFilesByExt(String ld, String ext) {
        File dir = new File(ld);
        String[] names = null;
        final String lext = ext;
        if (dir.isDirectory()) {
            names = dir.list(new FilenameFilter() {
                public boolean accept(File d, String name) {
                    if (name.endsWith(lext)) {
                        return true;
                    }
                    return false;
View Full Code Here

  public void setUp() throws Exception {
    checkpointDir = new File(baseDir, "checkpoint");
    dataDir = new File(baseDir, "dataDir");
    Assert.assertTrue(checkpointDir.mkdirs() || checkpointDir.isDirectory());
    Assert.assertTrue(dataDir.mkdirs() || dataDir.isDirectory());
    File[] dataFiles = origDataDir.listFiles(new FilenameFilter() {
      @Override
      public boolean accept(File dir, String name) {
        if(name.contains("lock")) {
          return false;
        }
View Full Code Here

    doTestFixCorruptEvents(true);
  }

  public void doTestFixCorruptEvents(boolean withCheckpoint) throws Exception {
    Set<String> corruptFiles = new HashSet<String>();
    File[] files = dataDir.listFiles(new FilenameFilter() {
      @Override
      public boolean accept(File dir, String name) {
        if(name.contains("lock") || name.contains("meta")) {
          return false;
        }
        return true;
      }
    });
    Random random = new Random();
    int corrupted = 0;
    for (File dataFile : files) {
      LogFile.SequentialReader reader =
        new LogFileV3.SequentialReader(dataFile, null, true);
      RandomAccessFile handle = new RandomAccessFile(dataFile, "rw");
      long eventPosition1 = reader.getPosition();
      LogRecord rec = reader.next();
      //No point corrupting commits, so ignore them
      if(rec == null ||
        rec.getEvent().getClass().getName().
          equals("org.apache.flume.channel.file.Commit")) {
        handle.close();
        reader.close();
        continue;
      }
      long eventPosition2 = reader.getPosition();
      rec = reader.next();
      handle.seek(eventPosition1 + 100);
      handle.writeInt(random.nextInt());
      corrupted++;
      corruptFiles.add(dataFile.getName());
      if (rec == null ||
        rec.getEvent().getClass().getName().
          equals("org.apache.flume.channel.file.Commit")) {
        handle.close();
        reader.close();
        continue;
      }
      handle.seek(eventPosition2 + 100);
      handle.writeInt(random.nextInt());
      corrupted++;
      handle.close();
      reader.close();

    }
    FileChannelIntegrityTool tool = new FileChannelIntegrityTool();
    tool.run(new String[] {"-l", dataDir.toString()});
    FileChannel channel = new FileChannel();
    channel.setName("channel");
    String cp;
    if(withCheckpoint) {
      cp = origCheckpointDir.toString();
    } else {
      FileUtils.deleteDirectory(checkpointDir);
      Assert.assertTrue(checkpointDir.mkdirs());
      cp = checkpointDir.toString();
    }
    ctx.put(FileChannelConfiguration.CHECKPOINT_DIR,cp);
    ctx.put(FileChannelConfiguration.DATA_DIRS, dataDir.toString());
    channel.configure(ctx);
    channel.start();
    Transaction tx = channel.getTransaction();
    tx.begin();
    int i = 0;
    while(channel.take() != null) {
      i++;
    }
    tx.commit();
    tx.close();
    channel.stop();
    Assert.assertEquals(25 - corrupted, i);
    files = dataDir.listFiles(new FilenameFilter() {
      @Override
      public boolean accept(File dir, String name) {
        if(name.contains(".bak")) {
          return true;
        }
View Full Code Here

    if(!shouldContinue) {
      LOG.error("Could not parse command line options. Exiting ...");
      System.exit(1);
    }
    for(File dataDir : dataDirs) {
      File[] dataFiles = dataDir.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
          if(!name.endsWith(Serialization.METADATA_FILENAME)
            && !name.endsWith(Serialization.METADATA_TMP_FILENAME)
            && !name.endsWith(Serialization.OLD_METADATA_FILENAME)
View Full Code Here

TOP

Related Classes of java.io.FilenameFilter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.