List of usage examples for org.apache.commons.io.filefilter FileFileFilter FILE
IOFileFilter FILE
To view the source code for org.apache.commons.io.filefilter FileFileFilter FILE.
Click Source Link
From source file:kr.co.leem.system.FileSystemUtils.java
/** * ./* w w w .j a v a 2 s.c o m*/ * * @param srcDir ? . * @param destDir . * @param isFileOrDir IS_FILE : ? , IS_DIRECTORY : . * @param preserveFileDate . * @see FileUtils#copyDirectory(File, File, FileFilter, boolean) * @see FileFileFilter#FILE * @see DirectoryFileFilter#DIRECTORY */ public static void copyDirectory(final String srcDir, final String destDir, final isFileOrDir filedir, final boolean preserveFileDate) { processIO(new IOCallback<Object>() { public Object doInProcessIO() throws IOException, NullPointerException { switch (filedir) { case IS_FILE: FileUtils.copyDirectory(new File(srcDir), new File(destDir), FileFileFilter.FILE, preserveFileDate); break; case IS_DIRECTORY: FileUtils.copyDirectory(new File(srcDir), new File(destDir), DirectoryFileFilter.DIRECTORY, preserveFileDate); break; default: FileUtils.copyDirectory(new File(srcDir), new File(destDir), DirectoryFileFilter.DIRECTORY, preserveFileDate); } return null; } }); }
From source file:com.hightern.fckeditor.connector.impl.AbstractLocalFileSystemConnector.java
public List<Map<String, Object>> getFiles(ResourceType type, String currentFolder) throws InvalidCurrentFolderException { final String absolutePath = getRealUserFilesAbsolutePath( RequestCycleHandler.getUserFilesAbsolutePath(ThreadLocalData.getRequest())); final File typeDir = AbstractLocalFileSystemConnector.getOrCreateResourceTypeDir(absolutePath, type); final File currentDir = new File(typeDir, currentFolder); if (!currentDir.exists() || !currentDir.isDirectory()) { throw new InvalidCurrentFolderException(); }//from w ww . j av a 2 s. c om // collect files List<Map<String, Object>> files; Map<String, Object> fileMap; final File[] fileList = currentDir.listFiles((FileFilter) FileFileFilter.FILE); files = new ArrayList<Map<String, Object>>(fileList.length); for (final File file : fileList) { fileMap = new HashMap<String, Object>(2); fileMap.put(Connector.KEY_NAME, file.getName()); fileMap.put(Connector.KEY_SIZE, file.length()); files.add(fileMap); } return files; }
From source file:com.safetys.framework.fckeditor.connector.impl.AbstractLocalFileSystemConnector.java
public List<Map<String, Object>> getFiles(ResourceType type, String currentFolder) throws InvalidCurrentFolderException { final String absolutePath = this.getRealUserFilesAbsolutePath( RequestCycleHandler.getUserFilesAbsolutePath(ThreadLocalData.getRequest())); final File typeDir = AbstractLocalFileSystemConnector.getOrCreateResourceTypeDir(absolutePath, type); final File currentDir = new File(typeDir, currentFolder); if (!currentDir.exists() || !currentDir.isDirectory()) { throw new InvalidCurrentFolderException(); }// ww w. j a v a 2 s.co m // collect files List<Map<String, Object>> files; Map<String, Object> fileMap; final File[] fileList = currentDir.listFiles((FileFilter) FileFileFilter.FILE); files = new ArrayList<Map<String, Object>>(fileList.length); for (final File file : fileList) { fileMap = new HashMap<String, Object>(2); fileMap.put(Connector.KEY_NAME, file.getName()); fileMap.put(Connector.KEY_SIZE, file.length()); files.add(fileMap); } return files; }
From source file:de.dentrassi.build.apt.repo.AptWriter.java
public void build() throws Exception { if (this.configuration.getTargetFolder().exists()) { throw new IllegalStateException( "The target path must not exists: " + this.configuration.getTargetFolder()); }// w w w . j a va2 s . co m if (!this.configuration.getSourceFolder().isDirectory()) { throw new IllegalStateException( "The source path must exists and must be a directory: " + this.configuration.getTargetFolder()); } this.configuration.validate(); this.configuration.getTargetFolder().mkdirs(); this.pool = new File(this.configuration.getTargetFolder(), "pool"); this.dists = new File(this.configuration.getTargetFolder(), "dists"); this.pool.mkdirs(); this.dists.mkdirs(); final FileFilter debFilter = new AndFileFilter( // Arrays.asList( // CanReadFileFilter.CAN_READ, // FileFileFilter.FILE, // new SuffixFileFilter(".deb") // ) // ); for (final File packageFile : this.configuration.getSourceFolder().listFiles(debFilter)) { processPackageFile(packageFile); } writePackageLists(); }
From source file:com.weaforce.system.component.fckeditor.response.XmlResponse.java
/** * Lists all files in the given dir as XML tags. * /* w w w .j a va2 s. c o m*/ * @param dir */ public void setFiles(File dir) { if (filesElement != null) { Element parent = (Element) filesElement.getParentNode(); parent.removeChild(filesElement); } filesElement = document.createElement("Files"); document.getDocumentElement().appendChild(filesElement); File[] fileList = dir.listFiles((FileFilter) FileFileFilter.FILE); long length; for (File file : fileList) { Element fileElement = document.createElement("File"); fileElement.setAttribute("name", file.getName()); if (file.length() < 1024) length = 1L; else length = file.length() / 1024; fileElement.setAttribute("size", String.valueOf(length)); filesElement.appendChild(fileElement); } }
From source file:me.neatmonster.spacertk.actions.FileActions.java
/** * Gets a list of files in a directory//from w w w . j ava 2 s. c om * @param directory Base directory * @return List of files */ @Action(aliases = { "listFiles" }) public List<String> listFiles(final String directory) { return Arrays.asList(new File(directory).list(FileFileFilter.FILE)); }
From source file:com.commander4j.thread.InboundMessageThread.java
public void run() { logger.debug("InboundMessageThread running"); Boolean dbconnected = false;// ww w. j av a 2s . com if (Common.hostList.getHost(hostID).isConnected(sessionID) == false) { dbconnected = Common.hostList.getHost(hostID).connect(sessionID, hostID); } else { dbconnected = true; } if (dbconnected) { JDBInterfaceLog il = new JDBInterfaceLog(getHostID(), getSessionID()); JeMail mail = new JeMail(getHostID(), getSessionID()); JDBInterface inter = new JDBInterface(getHostID(), getSessionID()); IncommingMaterialDefinition imd = new IncommingMaterialDefinition(getHostID(), getSessionID()); IncommingProcessOrderStatusChange iposc = new IncommingProcessOrderStatusChange(getHostID(), getSessionID()); IncommingProductionDeclarationConfirmation ipd = new IncommingProductionDeclarationConfirmation( getHostID(), getSessionID()); IncommingProcessOrder ipo = new IncommingProcessOrder(getHostID(), getSessionID()); IncommingLocation ilocn = new IncommingLocation(getHostID(), getSessionID()); IncommingPalletStatusChange ipsc = new IncommingPalletStatusChange(getHostID(), getSessionID()); IncommingPalletMove ipmv = new IncommingPalletMove(getHostID(), getSessionID()); IncommingBatchStatusChange bsc = new IncommingBatchStatusChange(getHostID(), getSessionID()); IncommingJourney ij = new IncommingJourney(getHostID(), getSessionID()); IncommingInspectionResult iirslt = new IncommingInspectionResult(getHostID(), getSessionID()); IncommingDespatchConfirmation idc = new IncommingDespatchConfirmation(getHostID(), getSessionID()); IncommingQMInspectionRequest iireq = new IncommingQMInspectionRequest(getHostID(), getSessionID()); IncommingMaterialAutoMove imam = new IncommingMaterialAutoMove(getHostID(), getSessionID()); GenericMessageHeader gmh = new GenericMessageHeader(); LinkedList<String> filenames = new LinkedList<String>(); BasicFileAttributes attrs; while (true) { com.commander4j.util.JWait.milliSec(100); if (allDone) { if (dbconnected) { Common.hostList.getHost(hostID).disconnect(getSessionID()); } return; } if (InboundMessageCollectionThread.recoveringFiles == false) { dir = new File(inputPath); chld = dir.listFiles((FileFilter) FileFileFilter.FILE); if (chld == null) { allDone = true; } else { Arrays.sort(chld, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR); filenames.clear(); for (int i = 0; (i < chld.length) & (i < maxfiles); i++) { fileName = chld[i].getName(); try { attrs = Files.readAttributes(chld[i].getAbsoluteFile().toPath(), BasicFileAttributes.class); if (attrs.size() > 0) { if (fileName.endsWith(".xml")) { filenames.addFirst(fileName); com.commander4j.util.JWait.milliSec(50); } } else { try { chld[i].delete(); } catch (Exception ex) { } } } catch (IOException e) { } } if (filenames.size() > 0) { logger.debug("Begin processing " + String.valueOf(filenames.size()) + " files."); for (int i = filenames.size() - 1; i >= 0; i--) { if (allDone) { if (dbconnected) { Common.hostList.getHost(hostID).disconnect(getSessionID()); } return; } fromFile = filenames.get(i); try { logger.debug("<--- START OF PROCESSING " + fromFile + " ---->"); logger.debug("Reading message header : " + inputPath + fromFile); if (gmh.readAddressInfo(inputPath + fromFile, getSessionID()) == true) { messageProcessedOK = true; errorMessage = ""; if (gmh.getInterfaceType().length() == 0) { messageProcessedOK = false; errorMessage = "Unrecognised Commander4j XML message format in file " + fromFile; logger.debug(errorMessage); String datetime = ""; datetime = JUtility .getISOTimeStampStringFormat(JUtility.getSQLDateTime()); gmh.setMessageDate(datetime); gmh.setInterfaceDirection("Unknown"); gmh.setMessageInformation(fromFile); gmh.setInterfaceType("Unknown"); gmh.setMessageRef("Unknown"); } else { if (gmh.getInterfaceDirection().equals("Input") == false) { messageProcessedOK = false; errorMessage = "Inbound message ignored - Interface Direction = " + gmh.getInterfaceDirection(); } else { String interfaceType = gmh.getInterfaceType(); logger.debug("Processing " + interfaceType + " started."); if (interfaceType.equals("Despatch Confirmation") == true) { messageProcessedOK = idc.processMessage(gmh); errorMessage = idc.getErrorMessage(); } if (interfaceType.equals("Material Definition") == true) { messageProcessedOK = imd.processMessage(gmh); errorMessage = imd.getErrorMessage(); } if (interfaceType.equals("Process Order") == true) { messageProcessedOK = ipo.processMessage(gmh); errorMessage = ipo.getErrorMessage(); } if (interfaceType.equals("Location") == true) { messageProcessedOK = ilocn.processMessage(gmh); errorMessage = ilocn.getErrorMessage(); } if (interfaceType.equals("Pallet Status Change") == true) { messageProcessedOK = ipsc.processMessage(gmh); errorMessage = ipsc.getErrorMessage(); } if (interfaceType.equals("Pallet Move") == true) { messageProcessedOK = ipmv.processMessage(gmh); errorMessage = ipmv.getErrorMessage(); } if (interfaceType.equals("Batch Status Change") == true) { messageProcessedOK = bsc.processMessage(gmh); errorMessage = bsc.getErrorMessage(); } if (interfaceType.equals("Journey Definition") == true) { messageProcessedOK = ij.processMessage(gmh); errorMessage = ij.getErrorMessage(); } if (interfaceType.equals("Process Order Status Change") == true) { messageProcessedOK = iposc.processMessage(gmh); errorMessage = iposc.getErrorMessage(); } if (interfaceType.equals("Production Declaration") == true) { messageProcessedOK = ipd.processMessage(gmh); errorMessage = ipd.getErrorMessage(); } if (interfaceType.equals("QM Inspection Request") == true) { messageProcessedOK = iireq.processMessage(gmh); errorMessage = iireq.getErrorMessage(); } if (interfaceType.equals("QM Inspection Result") == true) { messageProcessedOK = iirslt.processMessage(gmh); errorMessage = iirslt.getErrorMessage(); } if (interfaceType.equals("Material Auto Move") == true) { messageProcessedOK = imam.processMessage(gmh); errorMessage = imam.getErrorMessage(); } GenericMessageHeader.updateStats("Input", interfaceType, messageProcessedOK.toString()); logger.debug("Processing " + interfaceType + " finished."); } } logger.debug( " === RESULT " + messageProcessedOK.toString() + " ==="); if (messageProcessedOK) { il.write(gmh, GenericMessageHeader.msgStatusSuccess, "Processed OK", "DB Update", fromFile); reader.deleteFile(backupPath + gmh.getInterfaceType() + File.separator + fromFile); reader.move_FileToDirectory(inputPath + fromFile, backupPath + gmh.getInterfaceType(), true); } else { il.write(gmh, GenericMessageHeader.msgStatusError, errorMessage, "DB Update", fromFile); if (inter.getInterfaceProperties(gmh.getInterfaceType(), "Input") == true) { if (inter.getEmailError() == true) { String emailaddresses = inter.getEmailAddresses(); StringConverter stringConverter = new StringConverter(); ArrayConverter arrayConverter = new ArrayConverter( String[].class, stringConverter); arrayConverter.setDelimiter(';'); arrayConverter.setAllowedChars(new char[] { '@', '_' }); String[] emailList = (String[]) arrayConverter .convert(String[].class, emailaddresses); if (emailList.length > 0) { String siteName = Common.hostList.getHost(getHostID()) .getSiteDescription(); String attachedFilename = Common.base_dir + java.io.File.separator + inputPath + fromFile; logger.debug("Attaching file " + Common.base_dir + java.io.File.separator + inputPath + fromFile); mail.postMail(emailList, "Error Processing Incoming " + gmh.getInterfaceType() + " for [" + siteName + "] on " + JUtility.getClientName(), errorMessage, fromFile, attachedFilename); com.commander4j.util.JWait.milliSec(2000); } } } reader.deleteFile( errorPath + gmh.getInterfaceType() + File.separator + fromFile); reader.move_FileToDirectory(inputPath + fromFile, errorPath + gmh.getInterfaceType(), true); } } logger.debug("<--- END OF PROCESSING " + fromFile + " ---->"); } catch (Exception e) { e.printStackTrace(); } } } } } } } }
From source file:fr.acxio.tools.agia.tasks.ZipFilesTasklet.java
protected void zipResource(Resource sSourceResource, ZipArchiveOutputStream sZipArchiveOutputStream, StepContribution sContribution, ChunkContext sChunkContext) throws IOException, ZipFilesException { // TODO : use a queue to reduce the callstack overhead if (sSourceResource.exists()) { File aSourceFile = sSourceResource.getFile(); String aSourcePath = aSourceFile.getCanonicalPath(); if (!aSourcePath.startsWith(sourceBaseDirectoryPath)) { throw new ZipFilesException( "Source file " + aSourcePath + " does not match base directory " + sourceBaseDirectoryPath); }//from www. j a v a2 s. c om if (sContribution != null) { sContribution.incrementReadCount(); } String aZipEntryName = aSourcePath.substring(sourceBaseDirectoryPath.length() + 1); sZipArchiveOutputStream.putArchiveEntry(new ZipArchiveEntry(aZipEntryName)); if (LOGGER.isInfoEnabled()) { LOGGER.info("Zipping {} to {}", sSourceResource.getFile().getCanonicalPath(), aZipEntryName); } if (aSourceFile.isFile()) { InputStream aInputStream = sSourceResource.getInputStream(); IOUtils.copy(aInputStream, sZipArchiveOutputStream); aInputStream.close(); sZipArchiveOutputStream.closeArchiveEntry(); } else { sZipArchiveOutputStream.closeArchiveEntry(); for (File aFile : aSourceFile .listFiles((FileFilter) (recursive ? TrueFileFilter.TRUE : FileFileFilter.FILE))) { zipResource(new FileSystemResource(aFile), sZipArchiveOutputStream, sContribution, sChunkContext); } } if (sContribution != null) { sContribution.incrementWriteCount(1); } } else if (LOGGER.isInfoEnabled()) { LOGGER.info("{} does not exist", sSourceResource.getFilename()); } }
From source file:net.sf.jsignpdf.Signer.java
/** * Sign the files/*from w w w .ja v a2 s . co m*/ * * @param anOpts */ private static void signFiles(SignerOptionsFromCmdLine anOpts) { final SignerLogic tmpLogic = new SignerLogic(anOpts); if (ArrayUtils.isEmpty(anOpts.getFiles())) { // we've used -lp (loadproperties) parameter if (!tmpLogic.signFile()) { exit(Constants.EXIT_CODE_ALL_SIG_FAILED); } return; } int successCount = 0; int failedCount = 0; for (final String wildcardPath : anOpts.getFiles()) { final File wildcardFile = new File(wildcardPath); File[] inputFiles; if (StringUtils.containsAny(wildcardFile.getName(), '*', '?')) { final File inputFolder = wildcardFile.getAbsoluteFile().getParentFile(); final FileFilter fileFilter = new AndFileFilter(FileFileFilter.FILE, new WildcardFileFilter(wildcardFile.getName())); inputFiles = inputFolder.listFiles(fileFilter); if (inputFiles == null) { continue; } } else { inputFiles = new File[] { wildcardFile }; } for (File inputFile : inputFiles) { final String tmpInFile = inputFile.getPath(); if (!inputFile.canRead()) { failedCount++; System.err.println(RES.get("file.notReadable", new String[] { tmpInFile })); continue; } anOpts.setInFile(tmpInFile); String tmpNameBase = inputFile.getName(); String tmpSuffix = ".pdf"; if (StringUtils.endsWithIgnoreCase(tmpNameBase, tmpSuffix)) { tmpSuffix = StringUtils.right(tmpNameBase, 4); tmpNameBase = StringUtils.left(tmpNameBase, tmpNameBase.length() - 4); } final StringBuilder tmpName = new StringBuilder(anOpts.getOutPath()); tmpName.append(anOpts.getOutPrefix()); tmpName.append(tmpNameBase).append(anOpts.getOutSuffix()).append(tmpSuffix); String outFile = anOpts.getOutFile(); if (outFile == null) anOpts.setOutFile(tmpName.toString()); if (tmpLogic.signFile()) { successCount++; } else { failedCount++; } } } if (failedCount > 0) { exit(successCount > 0 ? Constants.EXIT_CODE_SOME_SIG_FAILED : Constants.EXIT_CODE_ALL_SIG_FAILED); } }
From source file:com.jaeksoft.searchlib.cluster.ClusterManager.java
/** * Return the list of instances which already opened the client * /*w w w . j a va 2s . co m*/ * @param indexDir * The directory of the client * @return */ public String[] getClientInstances(File indexDir) { rwl.r.lock(); try { File dir = getClientDir(indexDir); return dir.list(FileFileFilter.FILE); } finally { rwl.r.unlock(); } }