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 Project: netcdf-java   Author: Unidata   File: TestNcmlWriteAndCompareLocal.java    License: 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 Project: AudioBookConverter   Author: yermak   File: FilesController.java    License: 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 #3
Source Project: kfs   Author: kuali   File: AssetBarcodeInventoryInputFileType.java    License: 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 #4
Source Project: netcdf-java   Author: Unidata   File: TestN3iospCompare.java    License: 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 #5
Source Project: netcdf-java   Author: Unidata   File: TestOpenWithEnhanceP.java    License: 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 #6
Source Project: netcdf-java   Author: Unidata   File: TestDatasetWrap.java    License: 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 #7
Source Project: netcdf-java   Author: Unidata   File: TestNc4JniReadCompare.java    License: 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 #8
@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 #9
Source Project: sms-ssm   Author: YUbuntu0109   File: UploadFile.java    License: 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 #10
Source Project: freehealth-connector   Author: taktik   File: MessageQueueHelper.java    License: 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 #11
Source Project: freehealth-connector   Author: taktik   File: MessageQueueHelper.java    License: 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 #12
Source Project: freehealth-connector   Author: taktik   File: MessageQueueHelper.java    License: 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 #13
Source Project: freehealth-connector   Author: taktik   File: MessageQueueHelper.java    License: 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 #14
Source Project: datawave   Author: NationalSecurityAgency   File: ConfigurationFileHelper.java    License: 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 #15
Source Project: WMRouter   Author: meituan   File: WMRouterTransform.java    License: 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 #16
Source Project: Rails   Author: Rails-18xx   File: ConfigProfile.java    License: 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 #17
Source Project: confucius-commons   Author: mercyblitz   File: ClassUtils.java    License: 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 #18
Source Project: gdx-texture-packer-gui   Author: crashinvaders   File: LoggerUtils.java    License: 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 #19
Source Project: pcgen   Author: PCGen   File: PrintPreviewDialog.java    License: 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 #20
Source Project: maven-repository-tools   Author: simpligility   File: MavenRepositoryDeployer.java    License: 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 #21
Source Project: pcgen   Author: PCGen   File: PrintPreviewDialog.java    License: 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 #22
Source Project: kfs   Author: kuali   File: ReportAggregationStep.java    License: 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 #23
Source Project: kfs   Author: kuali   File: EnterpriseFeederFileSetType.java    License: 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 #24
Source Project: kfs   Author: kuali   File: CorrectionDocumentServiceImpl.java    License: 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 #25
Source Project: gocd   Author: gocd   File: GoServer.java    License: 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 #26
Source Project: tutorials   Author: eugenp   File: CommonsIOUnitTest.java    License: 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 #27
Source Project: kite   Author: kite-sdk   File: SchemaTool.java    License: 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 #28
@Parameterized.Parameters(name = "{0}")
public static List<Object[]> getTestParameters() {
  String datadir = TestDir.cdmUnitTestDir;

  List<Object[]> result = new ArrayList<>(500);

  // result.add(new Object[]{datadir + "formats/netcdf4/tst/test_enum_type.nc", false});
  result.add(new Object[] {datadir + "conventions/atd-radar/rgg.20020411.000000.lel.ll.nc", false});
  result.add(new Object[] {datadir + "conventions/atd-radar/SPOL_3Volumes.nc", false});
  result.add(new Object[] {datadir + "conventions/awips/19981109_1200.nc", false});
  result.add(new Object[] {datadir + "conventions/cf/ccsm2.nc", false}); //
  result.add(new Object[] {datadir + "conventions/coards/cldc.mean.nc", false});
  result.add(new Object[] {datadir + "conventions/csm/o3monthly.nc", false});
  result.add(new Object[] {datadir + "conventions/gdv/OceanDJF.nc", false});
  result.add(new Object[] {datadir + "conventions/gief/coamps.wind_uv.nc", false});
  result.add(new Object[] {datadir + "conventions/mars/temp_air_01082000.nc", true});
  result.add(new Object[] {datadir + "conventions/nuwg/eta.nc", false});
  result.add(new Object[] {datadir + "conventions/nuwg/ocean.nc", true});
  result.add(new Object[] {datadir + "conventions/wrf/wrfout_v2_Lambert.nc", false});

  result.add(new Object[] {datadir + "formats/grib2/eta2.wmo", false}); //
  result.add(new Object[] {datadir + "formats/grib2/ndfd.wmo", false}); //

  result.add(new Object[] {datadir + "formats/gini/n0r_20041013_1852-compress", false}); //
  result.add(new Object[] {datadir + "formats/gini/ntp_20041206_2154", true}); //
  result.add(new Object[] {datadir + "formats/dmsp/F14200307192230.n.OIS", false}); //

  result.add(new Object[] {datadir + "formats/nexrad/level2/6500KHGX20000610_000110", false});
  result.add(new Object[] {datadir + "formats/nexrad/level2/Level2_KYUX_20060527_2335.ar2v", true});

  result.add(new Object[] {datadir + "conventions/nuwg/ocean.nc", true});

  // try everything from these directories
  try {
    addFromScan(result, TestDir.cdmUnitTestDir + "formats/netcdf4/",
        new NotFileFilter(new SuffixFileFilter(new String[] {".cdl", ".nc5", ".gbx9"})), false);
  } catch (IOException e) {
    e.printStackTrace();
  }

  return result;
}
 
Example #29
Source Project: torrssen2   Author: tarpha   File: CommonUtils.java    License: MIT License 4 votes vote down vote up
public static List<String> removeDirectory(String path, String outer, SettingRepository settingRepository) {
    String[] exts = {};
    Optional<Setting> exceptExtSetting = settingRepository.findByKey("EXCEPT_EXT");
    if(exceptExtSetting.isPresent()) {
        exts = StringUtils.split(StringUtils.lowerCase(exceptExtSetting.get().getValue()), ",");
    }

    Optional<Setting> delDirSetting = settingRepository.findByKey("DEL_DIR");
    
    if (delDirSetting.isPresent()) {
        if(Boolean.parseBoolean(delDirSetting.get().getValue())) {
            File file = new File(path, outer);
            if (file.isDirectory()) {
                Collection<File> subFiles;
                if(exts != null) {
                    NotFileFilter fileFilter = new NotFileFilter(new SuffixFileFilter(exts)); 
                    subFiles = FileUtils.listFiles(new File(path, outer), fileFilter, TrueFileFilter.INSTANCE);
                } else {
                    subFiles = FileUtils.listFiles(new File(path, outer), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
                }
                
                List<String> ret = new ArrayList<>();

                try {
                    for(File subFile: subFiles) {
                        log.debug(subFile.getPath() + ":" + subFile.getName());
                        File remove = new File(path, subFile.getName());
                        if (remove.isFile()) {
                            FileUtils.forceDelete(remove);
                        }
                        FileUtils.moveFileToDirectory(subFile, new File(path), true);
                        ret.add(subFile.getName());
                    }
                    FileUtils.forceDelete(new File(path, outer));
                } catch (IOException e) {
                    log.error(e.getMessage());
                }

                return ret;
            } 
        }
    }

    return null;
}
 
Example #30
Source Project: hivemq-community-edition   Author: hivemq   File: OnTheFlyCompilationUtil.java    License: Apache License 2.0 4 votes vote down vote up
public static File compileJavaFile(final File javaFile, final File toFolder) throws IOException {
    final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

    final StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);

    fileManager.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singletonList(toFolder));


    // Compile the file
    compiler.getTask(null, fileManager, null, null, null,
            fileManager.getJavaFileObjectsFromFiles(Collections.singletonList(javaFile))).call();
    fileManager.close();

    final Collection<File> files = FileUtils.listFiles(toFolder, new SuffixFileFilter("class"), TrueFileFilter.INSTANCE);

    return Iterables.getOnlyElement(files);
}