public DefaultCommandStore(File file, int maxFileSize, int minTimeMilliToGcAfterModified, int fileNumToKeep, KeeperMonitor keeperMonitor) throws IOException { this.baseDir = file.getParentFile(); this.fileNamePrefix = file.getName(); this.maxFileSize = maxFileSize; this.fileNumToKeep = fileNumToKeep; this.minTimeMilliToGcAfterModified = minTimeMilliToGcAfterModified; this.commandStoreDelay = keeperMonitor.createCommandStoreDelay(this); fileFilter = new PrefixFileFilter(fileNamePrefix); long currentStartOffset = findMaxStartOffset(); File currentFile = fileForStartOffset(currentStartOffset); logger.info("Write to {}", currentFile.getName()); CommandFileContext cmdFileCtx = new CommandFileContext(currentStartOffset, currentFile); cmdFileCtxRef.set(cmdFileCtx); offsetNotifier = new OffsetNotifier(cmdFileCtx.totalLength() - 1); }
/** * Scan a directory for packages that match. This method is used prior to * finding a matching directory. Once the package names is matched * handleDir() is used. * * @param classes * The classes that have been found. * @param packageName * The package name for classes to find. * @param dir * The directory to scan. * @param cFilter * The class acceptance filter. */ private static void scanDir(Set<String> classes, String packageName, File dir, ClassPathFilter cFilter) { if (!dir.exists()) { return; } if (dir.isDirectory()) { if (dir.getPath().endsWith(packageName.replace('.', '/'))) { // we have a match handleDir(classes, packageName, dir, cFilter); } else { // no match check next level for (File file : dir.listFiles((FileFilter) new AndFileFilter(DirectoryFileFilter.DIRECTORY, new NotFileFilter(new PrefixFileFilter("."))))) { scanDir(classes, packageName, file, cFilter); } } } // if it is not a directory we don't process it here as we are looking // for directories that start with the packageName. }
/** * 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; }
/** Import organizations */ private void importOrganizations() throws Exception { String[] organizationFileNames = importDir.list( new PrefixFileFilter( "organization." ) ); logger.info( "Organizations to read: " + organizationFileNames.length ); for ( String organizationFileName : organizationFileNames ) { try { importOrganization( organizationFileName ); } catch ( Exception e ) { logger.warn( "Unable to import organization:" + organizationFileName, e ); } } }
private boolean isTranscodingStepInstalled(String step) { if (StringUtils.isEmpty(step)) { return true; } String executable = StringUtil.split(step)[0]; PrefixFileFilter filter = new PrefixFileFilter(executable); String[] matches = getTranscodeDirectory().list(filter); return matches != null && matches.length > 0; }
public static List<String> getFilenames(String playerName) { checkFilePath(); File file = new File(TombManyGraves.file + FILE_PREFIX); String[] fileNames = file.list(new PrefixFileFilter(playerName)); for (int i=0; i < fileNames.length; i++) { fileNames[i] = fileNames[i].substring(fileNames[i].indexOf("#")+1,fileNames[i].indexOf(".json")); } return Arrays.asList(fileNames); }
public void clear() { File deployFolder = deployableFile.getParentFile(); if (!deployFolder.exists()) { return; } PrefixFileFilter optionsFileFilter = new PrefixFileFilter(getTargetFilePrefix()); Collection<File> targetOptionsFiles = FileUtils.listFiles(deployFolder, optionsFileFilter, null); for (File targetOptionFile : targetOptionsFiles) { FileUtils.deleteQuietly(targetOptionFile); } }
private void addSources(ProjectDefinition project) { final File basedir = project.getBaseDir(); logger.debug(basedir.getAbsolutePath()); // TODO: ignore child modules folders more properly IOFileFilter custom = new IOFileFilter() { @Override public boolean accept(File file) { return file.isDirectory() && !(new File(file, "pom.xml").exists()) || file.getAbsolutePath().equals( basedir.getAbsolutePath()); } @Override public boolean accept(File dir, String name) { return false; } }; Collection<File> files = FileUtils.listFiles(basedir, new SuffixFileFilter(".process"), new AndFileFilter( new NotFileFilter(new PrefixFileFilter("target")), custom)); project.addSources(files.toArray(new File[0])); }
public static void reconstructLineBased(File partFolder, File reconstructed, boolean removeHeaders) throws IOException { Path tmpOut = Files.createTempFile(partFolder.toPath(), "reconstr", ".tmp"); BufferedOutputStream dstOut = new BufferedOutputStream( new FileOutputStream(tmpOut.toFile())); try { if (!Files.isDirectory(partFolder.toPath())) throw new IOException("Not a directory: " + partFolder); File[] fileList = FileUtils.listFiles(partFolder, new PrefixFileFilter("part"), TrueFileFilter.TRUE).toArray( new File[0]); Arrays.sort(fileList); for (int i = 0; i < fileList.length; i++) { if (fileList[i].canRead()) { BufferedReader in = new BufferedReader(new FileReader( fileList[i])); try { if (removeHeaders && i != 0) in.readLine(); IOUtils.copy(in, dstOut); } finally { in.close(); } } } } finally { dstOut.close(); } Files.move(tmpOut, reconstructed.toPath(), StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING); FileUtils.deleteQuietly(tmpOut.toFile()); FileUtils.deleteQuietly(partFolder); }
public static void reconstructTurtle(File partFolder, File reconstructed) throws IOException { Path tmpOut = Files.createTempFile(partFolder.toPath(), "reconstr", ".tmp"); FileOutputStream dstOut = new FileOutputStream(tmpOut.toFile()); FileChannel dstOutChannel = dstOut.getChannel(); try { if (!Files.isDirectory(partFolder.toPath())) throw new IOException("Not a directory: " + partFolder); File[] fileList = FileUtils.listFiles(partFolder, new PrefixFileFilter("part"), TrueFileFilter.TRUE).toArray( new File[0]); Arrays.sort(fileList); RandomAccessFile inputFile; inputFile = new RandomAccessFile(fileList[0], "r"); inputFile.getChannel().transferTo(0, inputFile.length(), dstOutChannel); inputFile.close(); for (int i = 1; i < fileList.length; i++) { inputFile = new RandomAccessFile(fileList[i], "r"); long lastPrefix = findTurtlePrefixEnd(inputFile); inputFile.getChannel().transferTo(lastPrefix, inputFile.length() - lastPrefix, dstOutChannel); inputFile.close(); } } finally { dstOut.close(); } Files.move(tmpOut, reconstructed.toPath(), StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING); FileUtils.deleteQuietly(tmpOut.toFile()); FileUtils.deleteQuietly(partFolder); }
/** * Method that to reconstruct part* files into a single file <BR> * Suitable for line-based, CSV files. * * @param partFolder * directory contatining partial files (part001,part002..) * @param reconstructed * file to which the output is written * @throws IOException */ public static void reconstructLineBased(File partFolder, File reconstructed, boolean removeHeaders) throws IOException { Path tmpOut = Files.createTempFile(partFolder.toPath(), "reconstr", ".tmp"); BufferedOutputStream dstOut = new BufferedOutputStream( new FileOutputStream(tmpOut.toFile())); try { if (!Files.isDirectory(partFolder.toPath())) throw new IOException("Not a directory: " + partFolder); File[] fileList = FileUtils.listFiles(partFolder, new PrefixFileFilter("part"), TrueFileFilter.TRUE).toArray( new File[0]); Arrays.sort(fileList); for (int i = 0; i < fileList.length; i++) { if (fileList[i].canRead()) { BufferedReader in = new BufferedReader(new FileReader( fileList[i])); try { if (removeHeaders && i != 0) in.readLine(); IOUtils.copy(in, dstOut); } finally { in.close(); } } } } finally { dstOut.close(); } Files.move(tmpOut, reconstructed.toPath(), StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING); FileUtils.deleteQuietly(tmpOut.toFile()); FileUtils.deleteQuietly(partFolder); }
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; }
/** * 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.ole.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; }
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 ; }
private boolean isTranscodingStepInstalled(String step) { if (StringUtils.isEmpty(step)) { return true; } String executable = StringUtil.split(step)[0]; PrefixFileFilter filter = new PrefixFileFilter(executable); String[] matches = transcodingService.getTranscodeDirectory().list(filter); return matches != null && matches.length > 0; }
@Override public void execute() throws MojoExecutionException, MojoFailureException { this.pluginDescriptor = ((PluginDescriptor) getPluginContext().get("pluginDescriptor")); if (this.mavenHome == null ) { String mavenEnv = System.getenv("M2_HOME"); Validate.notEmpty(mavenEnv, "M2_HOME is not set you can used the maven-home configuration!"); mavenHome = new File(mavenEnv); } if (!mavenHome.exists() ) { throw new IllegalArgumentException("maven home (M2_HOME or maven-home configuration) is set to bad location : " + mavenHome.getAbsolutePath()); } OrFileFilter prefixFileFilter = new OrFileFilter(); prefixFileFilter.addFileFilter(new PrefixFileFilter("VDoc")); prefixFileFilter.addFileFilter(new PrefixFileFilter("VDP")); AndFileFilter fileFilter = new AndFileFilter(); fileFilter.addFileFilter(prefixFileFilter); fileFilter.addFileFilter(new SuffixFileFilter(".jar")); File[] earFiles = earFolder.listFiles((FileFilter) fileFilter); getLog().info("Scan the vdoc.ear folder"); deployFiles(earFiles); getLog().info("Scan the vdoc.ear/lib folder"); File[] earLibFiles = new File(earFolder, "lib").listFiles((FileFilter) fileFilter); deployFiles(earLibFiles); buildParentPom("sdk"); buildParentPom("sdk.advanced"); }
/** * 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; }
/** * 生成html * <br><i>at 2014年7月12日下午4:36:36</i> * @author lichee * @see <a href="http://nicecoder.net">nicecoder.net</a> */ public void generate(){ //读取各种信息 loadPosts();//读取post信息到app实例中 parseTags();//解析出析post的tags parseCategories();//解析出析post的分类 try { //清理输出目录 File out = new File(outputDir); if(out.exists() && out.isDirectory()){ FileUtils.cleanDirectory(out); }else{ if(out.isFile()) out.delete(); out.mkdir(); } //创建循环输出器,生成html GeneratorWalker generator = new GeneratorWalker(this); generator.execute(); //生成完毕,拷贝其他文件到目标目录 FileUtils.copyDirectory( new File(absRootDir), new File(outputDir), FileFilterUtils.and(FileFilterUtils.notFileFilter(App.genFilter), FileFilterUtils.notFileFilter(new PrefixFileFilter("_")))); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** * Import admin users. */ private void importAdminUsers(int writeThreadCount, int auditThreadCount) throws Exception { String[] fileNames = importDir.list(new PrefixFileFilter(ExportAdmins.ADMIN_USERS_PREFIX + ".")); logger.info( "Applications to read: " + fileNames.length ); for (String fileName : fileNames) { try { importAdminUsers(fileName, writeThreadCount, auditThreadCount); } catch (Exception e) { logger.warn("Unable to import application: " + fileName, e); } } }
/** * Import collections. Collections files are named: collections.<application_name>.Timestamp.json */ private void importMetadata(int writeThreadCount) throws Exception { String[] fileNames = importDir.list( new PrefixFileFilter( ExportAdmins.ADMIN_USER_METADATA_PREFIX + "." ) ); logger.info( "Metadata files to read: " + fileNames.length ); for (String fileName : fileNames) { try { importMetadata(fileName, writeThreadCount); } catch (Exception e) { logger.warn("Unable to import metadata file: " + fileName, e); } } }
/** Import applications */ private void importApplications() throws Exception { String[] nanemspaceFileNames = importDir.list( new PrefixFileFilter( "application." ) ); logger.info( "Applications to read: " + nanemspaceFileNames.length ); for ( String applicationName : nanemspaceFileNames ) { try { importApplication( applicationName ); } catch ( Exception e ) { logger.warn( "Unable to import application: " + applicationName, e ); } } }
/** Import collections. Collections files are named: collections.<application_name>.Timestamp.json */ private void importCollections() throws Exception { String[] collectionsFileNames = importDir.list( new PrefixFileFilter( "collections." ) ); logger.info( "Collections to read: " + collectionsFileNames.length ); for ( String collectionName : collectionsFileNames ) { try { importCollection( collectionName ); } catch ( Exception e ) { logger.warn( "Unable to import collection: " + collectionName, e ); } } }
private File[] findLogFiles() { File dir = new File("build"); return dir.listFiles((FileFilter)new AndFileFilter( new PrefixFileFilter("LoggerFactoryTest"), new SuffixFileFilter(".log"))); }
@Parameters(name = "{index}: running on file {0}") public static Iterable<File> tsvFiles() { return asList(new File("src/test/resources/tsv3-suite/").listFiles( (FilenameFilter) new PrefixFileFilter(asList("test", "issue", "sample")))); }
/** * Remove the stored default images for the given type * * @param typeName * the name of the image type * @param imageProviderId * the ID of the image provider which loaded the default image */ public void removeDefaultImages(String typeName, String imageProviderId) { File cacheDir = getDefaultImageCacheDir(typeName); if (cacheDir.exists()) { deleteFiles(cacheDir, new PrefixFileFilter(imageProviderId + SIZE_MARKER), typeName, imageProviderId); } }