org.apache.commons.io.filefilter.SuffixFileFilter Java Examples

The following examples show how to use org.apache.commons.io.filefilter.SuffixFileFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestNcmlWriteAndCompareLocal.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Parameterized.Parameters(name = "{0}")
public static List<Object[]> getTestParameters() {
  List<Object[]> result = new ArrayList<>(500);

  // try everything from these directories
  try {
    TestDir.actOnAllParameterized(TestDir.cdmLocalFromTestDataDir + "point/", new SuffixFileFilter(".ncml"), result);
    TestDir.actOnAllParameterized(TestDir.cdmLocalFromTestDataDir + "ncml/standalone/", new SuffixFileFilter(".ncml"),
        result);

  } catch (IOException e) {
    e.printStackTrace();
  }

  return result;
}
 
Example #2
Source File: AssetBarcodeInventoryInputFileType.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Return set of file user identifiers from a list of files
 * 
 * @param user user who uploaded or will upload file
 * @param files list of files objects
 * @return Set containing all user identifiers from list of files
 * 
 * @see org.kuali.kfs.sys.batch.BatchInputFileSetType#extractFileUserIdentifiers(org.kuali.rice.kim.api.identity.Person, java.util.List)
 */
public Set<String> extractFileUserIdentifiers(Person user, List<File> files) {
    Set<String> extractedFileUserIdentifiers = new TreeSet<String>();

    StringBuilder buf = new StringBuilder();
    buf.append(FILE_NAME_PREFIX).append(FILE_NAME_PART_DELIMITER).append(user.getPrincipalName()).append(FILE_NAME_PART_DELIMITER);
    String prefixString = buf.toString();

    IOFileFilter prefixFilter = new PrefixFileFilter(prefixString);
    IOFileFilter suffixFilter = new SuffixFileFilter(CamsConstants.BarCodeInventory.DATA_FILE_EXTENSION);
    IOFileFilter combinedFilter = new AndFileFilter(prefixFilter, suffixFilter);

    for (File file : files) {
        if (combinedFilter.accept(file)) {
            String fileName = file.getName();
            if (fileName.endsWith(CamsConstants.BarCodeInventory.DATA_FILE_EXTENSION)) {
                extractedFileUserIdentifiers.add(StringUtils.substringBetween(fileName, prefixString, CamsConstants.BarCodeInventory.DATA_FILE_EXTENSION));
            } else {
                LOG.error("Unable to determine file user identifier for file name: " + fileName);
                throw new RuntimeException("Unable to determine file user identifier for file name: " + fileName);
            }
        }
    }

    return extractedFileUserIdentifiers;
}
 
Example #3
Source File: FilesController.java    From AudioBookConverter with GNU General Public License v2.0 6 votes vote down vote up
private List<String> collectFiles(Collection<File> files) {
    List<String> fileNames = new ArrayList<>();
    ImmutableSet<String> extensions = ImmutableSet.copyOf(FILE_EXTENSIONS);

    for (File file : files) {
        if (file.isDirectory()) {
            SuffixFileFilter suffixFileFilter = new SuffixFileFilter(toSuffixes(".", FILE_EXTENSIONS), IOCase.INSENSITIVE);
            Collection<File> nestedFiles = FileUtils.listFiles(file, suffixFileFilter, TrueFileFilter.INSTANCE);
            nestedFiles.stream().map(File::getPath).forEach(fileNames::add);
        } else {
            boolean allowedFileExtension = extensions.contains(FilenameUtils.getExtension(file.getName()).toLowerCase());
            if (allowedFileExtension) {
                fileNames.add(file.getPath());
            }
        }
    }
    return fileNames;
}
 
Example #4
Source File: ConfigProfile.java    From Rails with GNU General Public License v2.0 5 votes vote down vote up
static void readUser() {
    File userFolder = SystemOS.get().getConfigurationFolder(PROFILE_FOLDER, false);
    if (userFolder == null) return;
    FilenameFilter filter = new SuffixFileFilter(PROFILE_EXTENSION, IOCase.SYSTEM);
    for (String fileName:userFolder.list(filter)) {
        new ConfigProfile(Type.USER, FilenameUtils.getBaseName(fileName));
    }
}
 
Example #5
Source File: SchemaTool.java    From kite with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the list of HBase Common Avro schema strings from dir. It recursively
 * searches dir to find files that end in .avsc to locate those strings.
 * 
 * @param dir
 *          The dir to recursively search for schema strings
 * @return The list of schema strings
 */
private List<String> getSchemaStringsFromDir(File dir) {
  List<String> schemaStrings = new ArrayList<String>();
  Collection<File> schemaFiles = FileUtils.listFiles(dir,
      new SuffixFileFilter(".avsc"), TrueFileFilter.INSTANCE);
  for (File schemaFile : schemaFiles) {
    schemaStrings.add(getSchemaStringFromFile(schemaFile));
  }
  return schemaStrings;
}
 
Example #6
Source File: CommonsIOUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenGetFilewith_ANDFileFilter_thenFindsampletxt() throws IOException {

    String path = getClass().getClassLoader().getResource("fileTest.txt").getPath();
    File dir = FileUtils.getFile(FilenameUtils.getFullPath(path));

    Assert.assertEquals("sample.txt", dir.list(new AndFileFilter(new WildcardFileFilter("*ple*", IOCase.INSENSITIVE), new SuffixFileFilter("txt")))[0]);
}
 
Example #7
Source File: GoServer.java    From gocd with Apache License 2.0 5 votes vote down vote up
private List<File> getAddonJarFiles() {
    File addonsPath = new File(systemEnvironment.get(SystemEnvironment.ADDONS_PATH));
    if (!addonsPath.exists() || !addonsPath.canRead()) {
        return new ArrayList<>();
    }

    return new ArrayList<>(FileUtils.listFiles(addonsPath, new SuffixFileFilter("jar", IOCase.INSENSITIVE), FalseFileFilter.INSTANCE));
}
 
Example #8
Source File: CorrectionDocumentServiceImpl.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
protected List<File> getReportsToAggregateIntoReport(String documentNumber) {
    File inputDirectory = new File(temporaryReportsDirectory);
    if (!inputDirectory.exists() || !inputDirectory.isDirectory()) {
        LOG.error(temporaryReportsDirectory + " does not exist or is not a directory.");
        throw new RuntimeException("Unable to locate temporary reports directory");
    }
    String filePrefix = documentNumber + "_" + temporaryReportFilenameComponent;
    FileFilter filter = FileFilterUtils.andFileFilter(
            new PrefixFileFilter(filePrefix), new SuffixFileFilter(temporaryReportFilenameSuffix));
    
    // FSKD-244, KFSMI-5424 sort with filename, just in case 
    List<File> fileList = Arrays.asList(inputDirectory.listFiles(filter));
    
    Comparator fileNameComparator = new Comparator() {
        public int compare(Object obj1, Object obj2) {
            if (obj1 == null) {
                return -1;
            }
            if (obj2 == null) {
                return 1;
            }
            File file1 = (File) obj1;
            File file2 = (File) obj2;
            
            return ((Comparable) file1.getName()).compareTo(file2.getName());
        }
    };
    
    Collections.sort(fileList, fileNameComparator);
    return fileList ;
}
 
Example #9
Source File: EnterpriseFeederFileSetType.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Return set of file user identifiers from a list of files
 * 
 * @param user user who uploaded or will upload file
 * @param files list of files objects
 * @return Set containing all user identifiers from list of files
 * @see org.kuali.kfs.sys.batch.BatchInputFileSetType#extractFileUserIdentifiers(org.kuali.rice.kim.api.identity.Person, java.util.List)
 */
public Set<String> extractFileUserIdentifiers(Person user, List<File> files) {
    Set<String> extractedFileUserIdentifiers = new TreeSet<String>();

    StringBuilder buf = new StringBuilder();
    buf.append(FILE_NAME_PREFIX).append(FILE_NAME_PART_DELIMITER).append(user.getPrincipalName()).append(FILE_NAME_PART_DELIMITER);
    String prefixString = buf.toString();
    IOFileFilter prefixFilter = new PrefixFileFilter(prefixString);

    IOFileFilter suffixFilter = new OrFileFilter(new SuffixFileFilter(EnterpriseFeederService.DATA_FILE_SUFFIX), new SuffixFileFilter(EnterpriseFeederService.RECON_FILE_SUFFIX));

    IOFileFilter combinedFilter = new AndFileFilter(prefixFilter, suffixFilter);

    for (File file : files) {
        if (combinedFilter.accept(file)) {
            String fileName = file.getName();
            if (fileName.endsWith(EnterpriseFeederService.DATA_FILE_SUFFIX)) {
                extractedFileUserIdentifiers.add(StringUtils.substringBetween(fileName, prefixString, EnterpriseFeederService.DATA_FILE_SUFFIX));
            }
            else if (fileName.endsWith(EnterpriseFeederService.RECON_FILE_SUFFIX)) {
                extractedFileUserIdentifiers.add(StringUtils.substringBetween(fileName, prefixString, EnterpriseFeederService.RECON_FILE_SUFFIX));
            }
            else {
                LOG.error("Unable to determine file user identifier for file name: " + fileName);
                throw new RuntimeException("Unable to determine file user identifier for file name: " + fileName);
            }
        }
    }

    return extractedFileUserIdentifiers;
}
 
Example #10
Source File: ReportAggregationStep.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
protected List<File> retrieveFilesToAggregate() {
    File inputDirectory = new File(inputFilePath);
    if (!inputDirectory.exists() || !inputDirectory.isDirectory()) {
        throw new RuntimeException(inputFilePath + " does not exist or is not a directory.");
    }
    FileFilter filter = FileFilterUtils.andFileFilter(
            new PrefixFileFilter(inputFilePrefix), new SuffixFileFilter(inputFileSuffix));
    
    List<File> fileList = Arrays.asList(inputDirectory.listFiles(filter));
    
    Collections.sort(fileList);
    
    return fileList;
}
 
Example #11
Source File: PrintPreviewDialog.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Object[] doInBackground()
{
	IOFileFilter pdfFilter = FileFilterUtils.asFileFilter(this);
	IOFileFilter suffixFilter = FileFilterUtils.notFileFilter(new SuffixFileFilter(".fo"));
	IOFileFilter sheetFilter = FileFilterUtils.prefixFileFilter(Constants.CHARACTER_TEMPLATE_PREFIX);
	IOFileFilter fileFilter = FileFilterUtils.and(pdfFilter, suffixFilter, sheetFilter);

	IOFileFilter dirFilter = TrueFileFilter.INSTANCE;
	File dir = new File(ConfigurationSettings.getOutputSheetsDir());
	Collection<File> files = FileUtils.listFiles(dir, fileFilter, dirFilter);
	URI osPath = new File(ConfigurationSettings.getOutputSheetsDir()).toURI();
	return files.stream().map(v -> osPath.relativize(v.toURI())).toArray();
}
 
Example #12
Source File: MavenRepositoryDeployer.java    From maven-repository-tools with Eclipse Public License 1.0 5 votes vote down vote up
public static Collection<File> getPomFiles( File repoPath )
{
    Collection<File> pomFiles = new ArrayList<File>();
    Collection<File> leafDirectories = getLeafDirectories( repoPath );
    for ( File leafDirectory : leafDirectories )
    {
        IOFileFilter fileFilter = new AndFileFilter( new WildcardFileFilter( "*.pom" ),
                                           new NotFileFilter( new SuffixFileFilter( "sha1" ) ) );
        pomFiles.addAll( FileUtils.listFiles( leafDirectory, fileFilter, null ) );
    }
    return pomFiles;
}
 
Example #13
Source File: PrintPreviewDialog.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Object[] doInBackground()
{
	IOFileFilter pdfFilter = FileFilterUtils.asFileFilter(this);
	IOFileFilter suffixFilter = FileFilterUtils.notFileFilter(new SuffixFileFilter(".fo"));
	IOFileFilter sheetFilter = FileFilterUtils.prefixFileFilter(Constants.CHARACTER_TEMPLATE_PREFIX);
	IOFileFilter fileFilter = FileFilterUtils.and(pdfFilter, suffixFilter, sheetFilter);

	IOFileFilter dirFilter = TrueFileFilter.INSTANCE;
	File dir = new File(ConfigurationSettings.getOutputSheetsDir());
	Collection<File> files = FileUtils.listFiles(dir, fileFilter, dirFilter);
	URI osPath = new File(ConfigurationSettings.getOutputSheetsDir()).toURI();
	return files.stream().map(v -> osPath.relativize(v.toURI())).toArray();
}
 
Example #14
Source File: LoggerUtils.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
public static File setupExternalFileOutput() {
    try {
        Date currentDate = new Date();
        long currentTime = currentDate.getTime();
        String fileName = new SimpleDateFormat("yyMMddhhmm").format(currentDate) + ".log";
        File logFile = new File(LwjglFiles.externalPath + AppConstants.LOGS_DIR + File.separator + fileName);
        logFile.getParentFile().mkdirs();
        for (File oldLogFile : logFile.getParentFile().listFiles((FileFilter)new SuffixFileFilter(LOG_FILE_EXTENSION))) {
            long lastModified = oldLogFile.lastModified();
            if (currentTime - lastModified > EXPIRATION_THRESHOLD) {
                try { oldLogFile.delete(); } catch (SecurityException ignored) { }
            }
        }
        FileOutputStream logFileOutputStream = new FileOutputStream(logFile);
        System.setOut(new PrintStream(new OutputStreamMultiplexer(
                new FileOutputStream(FileDescriptor.out),
                logFileOutputStream
        )));
        System.setErr(new PrintStream(new OutputStreamMultiplexer(
                new FileOutputStream(FileDescriptor.err),
                logFileOutputStream
        )));
        System.out.println("Version: " + AppConstants.version);
        System.out.println("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch"));
        System.out.println("JRE: " + System.getProperty("java.version") + " " + System.getProperty("java.vendor"));
        System.out.println("External log file: " + logFile.getAbsolutePath());
        return logFile;
    } catch (FileNotFoundException e) {
        System.err.println("Can't setup logging to external file.");
        e.printStackTrace();
        return null;
    }
}
 
Example #15
Source File: ClassUtils.java    From confucius-commons with Apache License 2.0 5 votes vote down vote up
protected static Set<String> findClassNamesInDirectory(File classesDirectory, boolean recursive) {
    Set<String> classNames = Sets.newLinkedHashSet();
    SimpleFileScanner simpleFileScanner = SimpleFileScanner.INSTANCE;
    Set<File> classFiles = simpleFileScanner.scan(classesDirectory, recursive, new SuffixFileFilter(FileSuffixConstants.CLASS));
    for (File classFile : classFiles) {
        String className = resolveClassName(classesDirectory, classFile);
        classNames.add(className);
    }
    return classNames;
}
 
Example #16
Source File: TestN3iospCompare.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> getTestParameters() {
  Collection<Object[]> filenames = new ArrayList<>();
  try {
    TestDir.actOnAllParameterized(testDir, new SuffixFileFilter(".nc"), filenames);
  } catch (IOException e) {
    filenames.add(new Object[] {e.getMessage()});
  }
  return filenames;
}
 
Example #17
Source File: WMRouterTransform.java    From WMRouter with Apache License 2.0 5 votes vote down vote up
/**
 * 扫描由注解生成器生成到包 {@link Const#GEN_PKG_SERVICE} 里的初始化类
 */
private void scanDir(File dir, Set<String> initClasses) throws IOException {
    File packageDir = new File(dir, INIT_SERVICE_DIR);
    if (packageDir.exists() && packageDir.isDirectory()) {
        Collection<File> files = FileUtils.listFiles(packageDir,
                new SuffixFileFilter(SdkConstants.DOT_CLASS, IOCase.INSENSITIVE), TrueFileFilter.INSTANCE);
        for (File f : files) {
            String className = trimName(f.getAbsolutePath(), dir.getAbsolutePath().length() + 1)
                    .replace(File.separatorChar, '.');
            initClasses.add(className);
            WMRouterLogger.info("    find ServiceInitClass: %s", className);
        }
    }
}
 
Example #18
Source File: TestOpenWithEnhanceP.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Parameterized.Parameters(name = "{0}")
public static List<Object[]> getTestParameters() {
  List<Object[]> result = new ArrayList<>(500);
  try {
    TestDir.actOnAllParameterized(TestDir.cdmUnitTestDir + "conventions", new SuffixFileFilter(".nc"), result);
  } catch (IOException e) {
    e.printStackTrace();
  }
  return result;
}
 
Example #19
Source File: TestDatasetWrap.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Parameterized.Parameters(name = "{0}")
public static List<Object[]> getTestParameters() {
  List<Object[]> result = new ArrayList<>(500);
  try {
    TestDir.actOnAllParameterized(TestDir.cdmUnitTestDir + "ft/grid", new SuffixFileFilter(".nc"), result);
  } catch (IOException e) {
    e.printStackTrace();
  }
  return result;
}
 
Example #20
Source File: TestNc4JniReadCompare.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Parameterized.Parameters(name = "{0}")
public static List<Object[]> getTestParameters() {

  FileFilter ff = new NotFileFilter(new SuffixFileFilter(".cdl"));
  List<Object[]> result = new ArrayList<Object[]>(500);
  try {
    TestDir.actOnAllParameterized(TestDir.cdmUnitTestDir + "formats/netcdf3/", ff, result);
    TestDir.actOnAllParameterized(TestDir.cdmUnitTestDir + "formats/netcdf4/", ff, result);
  } catch (IOException e) {
    e.printStackTrace();
  }

  return result;
}
 
Example #21
Source File: TestGribCoverageRdavmIndicesP.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Parameterized.Parameters(name = "{0}")
public static List<Object[]> getTestParameters() {
  List<Object[]> result = new ArrayList<>(30);
  try {
    TestDir.actOnAllParameterized(topdir, new SuffixFileFilter(".ncx4"), result);
  } catch (IOException e) {
    e.printStackTrace();
  }
  return result;
}
 
Example #22
Source File: UploadFile.java    From sms-ssm with MIT License 5 votes vote down vote up
/**
 * @description: 效验所上传图片的大小及格式等信息...
 * @param: photo
 * @param: path
 * @date: 2019-06-18 11:01 AM
 * @return: java.util.Map<java.lang.String, java.lang.Object>
 */
private static Map<String, Object> uploadPhoto(MultipartFile photo, String path) {
    //限制头像大小(20M)
    int MAX_SIZE = 20971520;
    //获取图片的原始名称
    String orginalName = photo.getOriginalFilename();
    //如果保存文件的路径不存在,则创建该目录
    File filePath = new File(path);
    if (!filePath.exists()) {
        filePath.mkdirs();
    }
    //限制上传文件的大小
    if (photo.getSize() > MAX_SIZE) {
        error_result.put("success", false);
        error_result.put("msg", "上传的图片大小不能超过20M哟!");
        return error_result;
    }
    // 限制上传的文件类型
    String[] suffixs = new String[]{".png", ".PNG", ".jpg", ".JPG", ".jpeg", ".JPEG", ".gif", ".GIF", ".bmp", ".BMP"};
    SuffixFileFilter suffixFileFilter = new SuffixFileFilter(suffixs);
    if (!suffixFileFilter.accept(new File(path + orginalName))) {
        error_result.put("success", false);
        error_result.put("msg", "禁止上传此类型文件! 请上传图片哟!");
        return error_result;
    }

    return null;
}
 
Example #23
Source File: MessageQueueHelper.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void unlockLockedFilesOnQueue() {
final PropertyHandler propertyHandler = PropertyHandler.getInstance();
    if (propertyHandler.hasProperty("MESSAGE_QUEUE_FOLDER")) {
        String messageQueueFolderPath = propertyHandler.getProperty("MESSAGE_QUEUE_FOLDER");
        File messageQueueFolder = new File(messageQueueFolderPath);
        if (messageQueueFolder.exists()) {
            String lockedFileSuffix = "_LOCK";
            SuffixFileFilter suffixFileFilter = new SuffixFileFilter(lockedFileSuffix);

            Integer numberOfMinutes = propertyHandler.getIntegerProperty("locked.file.retention", "2");

            AgeFileFilter ageFileFilter = new AgeFileFilter(System.currentTimeMillis() - (numberOfMinutes * 60 * 1000));

            Collection<File> lockedFiles = FileUtils.listFiles(messageQueueFolder, FileFilterUtils.and(suffixFileFilter, ageFileFilter), TrueFileFilter.INSTANCE);
            for (File file : lockedFiles) {
                String lockedFileName = file.getAbsolutePath();
                File unlockedFile = new File(StringUtils.remove(lockedFileName, lockedFileSuffix));
                file.setLastModified(new Date().getTime());
                Boolean succesFullyUnlocked = file.renameTo(unlockedFile);
                if (succesFullyUnlocked) {
                    LOG.info("File: " + lockedFileName + " successfully unlocked.");
                }
            }
        } else {
            LOG.info("No directory found on location: " + messageQueueFolderPath + ". No files unlocked");
        }
    } else {
        LOG.info("No MESSAGE_QUEUE_FOLDER property in properties file. No files unlocked.");
    }
}
 
Example #24
Source File: MessageQueueHelper.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void unlockLockedFilesOnQueue() {
   PropertyHandler propertyHandler = PropertyHandler.getInstance();
   if (propertyHandler.hasProperty("MESSAGE_QUEUE_FOLDER")) {
      String messageQueueFolderPath = propertyHandler.getProperty("MESSAGE_QUEUE_FOLDER");
      File messageQueueFolder = new File(messageQueueFolderPath);
      if (messageQueueFolder.exists()) {
         String lockedFileSuffix = "_LOCK";
         SuffixFileFilter suffixFileFilter = new SuffixFileFilter(lockedFileSuffix);
         Integer numberOfMinutes = propertyHandler.getIntegerProperty("locked.file.retention", "2");
         AgeFileFilter ageFileFilter = new AgeFileFilter(System.currentTimeMillis() - (long)(numberOfMinutes.intValue() * 60 * 1000));
         Collection<File> lockedFiles = FileUtils.listFiles(messageQueueFolder, FileFilterUtils.and(suffixFileFilter, ageFileFilter), TrueFileFilter.INSTANCE);
         Iterator var9 = lockedFiles.iterator();

         while(var9.hasNext()) {
            File file = (File)var9.next();
            String lockedFileName = file.getAbsolutePath();
            File unlockedFile = new File(StringUtils.remove(lockedFileName, lockedFileSuffix));
            file.setLastModified((new Date()).getTime());
            Boolean succesFullyUnlocked = file.renameTo(unlockedFile);
            if (succesFullyUnlocked.booleanValue()) {
               LOG.info("File: " + lockedFileName + " successfully unlocked.");
            }
         }
      } else {
         LOG.info("No directory found on location: " + messageQueueFolderPath + ". No files unlocked");
      }
   } else {
      LOG.info("No MESSAGE_QUEUE_FOLDER property in properties file. No files unlocked.");
   }

}
 
Example #25
Source File: MessageQueueHelper.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void unlockLockedFilesOnQueue() {
final PropertyHandler propertyHandler = PropertyHandler.getInstance();
    if (propertyHandler.hasProperty("MESSAGE_QUEUE_FOLDER")) {
        String messageQueueFolderPath = propertyHandler.getProperty("MESSAGE_QUEUE_FOLDER");
        File messageQueueFolder = new File(messageQueueFolderPath);
        if (messageQueueFolder.exists()) {
            String lockedFileSuffix = "_LOCK";
            SuffixFileFilter suffixFileFilter = new SuffixFileFilter(lockedFileSuffix);

            Integer numberOfMinutes = propertyHandler.getIntegerProperty("locked.file.retention", "2");

            AgeFileFilter ageFileFilter = new AgeFileFilter(System.currentTimeMillis() - (numberOfMinutes * 60 * 1000));

            Collection<File> lockedFiles = FileUtils.listFiles(messageQueueFolder, FileFilterUtils.and(suffixFileFilter, ageFileFilter), TrueFileFilter.INSTANCE);
            for (File file : lockedFiles) {
                String lockedFileName = file.getAbsolutePath();
                File unlockedFile = new File(StringUtils.remove(lockedFileName, lockedFileSuffix));
                file.setLastModified(new Date().getTime());
                Boolean succesFullyUnlocked = file.renameTo(unlockedFile);
                if (succesFullyUnlocked) {
                    LOG.info("File: " + lockedFileName + " successfully unlocked.");
                }
            }
        } else {
            LOG.info("No directory found on location: " + messageQueueFolderPath + ". No files unlocked");
        }
    } else {
        LOG.info("No MESSAGE_QUEUE_FOLDER property in properties file. No files unlocked.");
    }
}
 
Example #26
Source File: MessageQueueHelper.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void unlockLockedFilesOnQueue() {
final PropertyHandler propertyHandler = PropertyHandler.getInstance();
    if (propertyHandler.hasProperty("MESSAGE_QUEUE_FOLDER")) {
        String messageQueueFolderPath = propertyHandler.getProperty("MESSAGE_QUEUE_FOLDER");
        File messageQueueFolder = new File(messageQueueFolderPath);
        if (messageQueueFolder.exists()) {
            String lockedFileSuffix = "_LOCK";
            SuffixFileFilter suffixFileFilter = new SuffixFileFilter(lockedFileSuffix);

            Integer numberOfMinutes = propertyHandler.getIntegerProperty("locked.file.retention", "2");

            AgeFileFilter ageFileFilter = new AgeFileFilter(System.currentTimeMillis() - (numberOfMinutes * 60 * 1000));

            Collection<File> lockedFiles = FileUtils.listFiles(messageQueueFolder, FileFilterUtils.and(suffixFileFilter, ageFileFilter), TrueFileFilter.INSTANCE);
            for (File file : lockedFiles) {
                String lockedFileName = file.getAbsolutePath();
                File unlockedFile = new File(StringUtils.remove(lockedFileName, lockedFileSuffix));
                file.setLastModified(new Date().getTime());
                Boolean succesFullyUnlocked = file.renameTo(unlockedFile);
                if (succesFullyUnlocked) {
                    LOG.info("File: " + lockedFileName + " successfully unlocked.");
                }
            }
        } else {
            LOG.info("No directory found on location: " + messageQueueFolderPath + ". No files unlocked");
        }
    } else {
        LOG.info("No MESSAGE_QUEUE_FOLDER property in properties file. No files unlocked.");
    }
}
 
Example #27
Source File: ConfigurationFileHelper.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param conf
 * @param configDirectory
 * @param configSuffix
 */
public static void setConfigurationFromFiles(Configuration conf, String configDirectory, String configSuffix) {
    File directory = new File(configDirectory);
    Collection<File> fileList = FileUtils.listFiles(directory, new SuffixFileFilter(configSuffix), null);
    for (File configFile : fileList) {
        try {
            conf.addResource(new Path(configFile.getCanonicalPath()));
        } catch (IOException ex) {
            log.error("Could not add config file to configuration: " + configFile, ex);
        }
    }
}
 
Example #28
Source File: CasMergeSuiteTest.java    From webanno with Apache License 2.0 4 votes vote down vote up
@Parameters(name = "{index}: running on data {0}")
public static Iterable<File> tsvFiles()
{
    return asList(new File("src/test/resources/testsuite/").listFiles(
            (FilenameFilter) new SuffixFileFilter(asList("Test"))));
}
 
Example #29
Source File: DefaultPackageInfo.java    From jackrabbit-filevault with Apache License 2.0 4 votes vote down vote up
/** Reads the package info from a given file
 * 
 * @param file the package file as zip or an exploded directory containing metadata.
 * @return the package info if the package is valid, otherwise {@code null}.
 * @throws IOException if an error occurs. */
public static @Nullable PackageInfo read(@NotNull File file) throws IOException {
    DefaultPackageInfo info = new DefaultPackageInfo(null, null, PackageType.MIXED);
    if (!file.exists()) {
        throw new FileNotFoundException("Could not find file " + file);
    }
    if (file.isDirectory()) {
        for (File directoryFile : FileUtils.listFiles(file, new NameFileFilter(new String[] { "MANIFEST.MF", Constants.PROPERTIES_XML, Constants.FILTER_XML}),
                new SuffixFileFilter(new String[] { Constants.META_INF, Constants.VAULT_DIR }))) {
            try (InputStream input = new BufferedInputStream(new FileInputStream(directoryFile))) {
                info = readFromInputStream(new File(file.toURI().relativize(directoryFile.toURI()).getPath()), input, info);
                // bail out as soon as all info was found
                if (info.getId() != null && info.getFilter() != null) {
                    break;
                }
            }

        }
        if (info.getId() == null || info.getFilter() == null) {
            return null;
        } else {
            return info;
        }
    } else if (file.getName().endsWith(".zip")) {
        // try to derive from vault-work?
        try (ZipFile zip = new ZipFile(file)) {
            Enumeration<? extends ZipEntry> entries = zip.entries();
            while (entries.hasMoreElements()) {
                ZipEntry e = entries.nextElement();
                try (InputStream input = zip.getInputStream(e)) {
                    info = readFromInputStream(new File(e.getName()), input, info);
                    // bail out as soon as all info was found
                    if (info.getId() != null && info.getFilter() != null) {
                        break;
                    }
                }
            }
        }
        if (info.getId() == null || info.getFilter() == null) {
            return null;
        } else {
            return info;
        }
    } else {
        throw new IOException("Only metadata from zip files could be extracted but the given file is not a zip:" + file);
    }
}
 
Example #30
Source File: HadoopXmlResourceMonitor.java    From knox with Apache License 2.0 4 votes vote down vote up
private void monitorClouderaManagerDescriptors(String topologyName) {
  final File[] clouderaManagerDescriptorFiles = new File(descriptorsDir).listFiles((FileFilter) new SuffixFileFilter(HADOOP_XML_RESOURCE_FILE_EXTENSION));
  for (File clouderaManagerDescriptorFile : clouderaManagerDescriptorFiles) {
    monitorClouderaManagerDescriptor(Paths.get(clouderaManagerDescriptorFile.getAbsolutePath()), topologyName);
  }
}