Search in sources :

Example 1 with WildCardFilter

use of nl.nn.adapterframework.util.WildCardFilter in project iaf by ibissource.

the class FileSystemUtils method getFilteredStream.

public static <F> Stream<F> getFilteredStream(IBasicFileSystem<F> fileSystem, String folder, String wildCard, String excludeWildCard) throws FileSystemException, IOException {
    DirectoryStream<F> ds = fileSystem.listFiles(folder);
    if (ds == null) {
        return null;
    }
    Iterator<F> it = ds.iterator();
    if (it == null) {
        return null;
    }
    WildCardFilter wildcardfilter = StringUtils.isEmpty(wildCard) ? null : new WildCardFilter(wildCard);
    WildCardFilter excludeFilter = StringUtils.isEmpty(excludeWildCard) ? null : new WildCardFilter(excludeWildCard);
    return StreamSupport.stream(Spliterators.spliteratorUnknownSize(it, 0), false).filter(F -> (wildcardfilter == null || wildcardfilter.accept(null, fileSystem.getName((F) F))) && (excludeFilter == null || !excludeFilter.accept(null, fileSystem.getName((F) F)))).onClose(() -> {
        try {
            ds.close();
        } catch (IOException e) {
            throw Lombok.sneakyThrow(e);
        }
    });
}
Also used : Misc(nl.nn.adapterframework.util.Misc) Iterator(java.util.Iterator) Date(java.util.Date) Spliterators(java.util.Spliterators) LogUtil(nl.nn.adapterframework.util.LogUtil) IOException(java.io.IOException) Supplier(java.util.function.Supplier) StringUtils(org.apache.commons.lang3.StringUtils) WildCardFilter(nl.nn.adapterframework.util.WildCardFilter) DirectoryStream(java.nio.file.DirectoryStream) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) DateUtils(nl.nn.adapterframework.util.DateUtils) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) FileSystemAction(nl.nn.adapterframework.filesystem.FileSystemActor.FileSystemAction) Map(java.util.Map) MessageContext(nl.nn.adapterframework.stream.MessageContext) StreamSupport(java.util.stream.StreamSupport) Lombok(lombok.Lombok) IOException(java.io.IOException) WildCardFilter(nl.nn.adapterframework.util.WildCardFilter)

Example 2 with WildCardFilter

use of nl.nn.adapterframework.util.WildCardFilter in project iaf by ibissource.

the class FileRecordListener method getFileToProcess.

/**
 * Gets a file to process.
 */
protected File getFileToProcess() {
    WildCardFilter filter = new WildCardFilter(wildcard);
    File dir = new File(getInputDirectory());
    File[] files = dir.listFiles(filter);
    int count = (files == null ? 0 : files.length);
    for (int i = 0; i < count; i++) {
        File file = files[i];
        if (file.isDirectory()) {
            continue;
        }
        return (file);
    }
    return null;
}
Also used : WildCardFilter(nl.nn.adapterframework.util.WildCardFilter) File(java.io.File)

Example 3 with WildCardFilter

use of nl.nn.adapterframework.util.WildCardFilter in project iaf by ibissource.

the class IbisDailyRollingFileAppender method subAppend.

public void subAppend(LoggingEvent event) {
    super.subAppend(event);
    String n = DateUtils.format(new Date(), DateUtils.shortIsoFormat);
    // cleaning up files is done once a day
    if (n.compareTo(nextCheck) > 0) {
        nextCheck = n;
        long deleteBefore = System.currentTimeMillis() - retentionDays * millisPerDay;
        String msgLogFileName = getFile();
        File msgLogFile = new File(msgLogFileName);
        String dirName = msgLogFile.getParent();
        String fileWithoutDirName = msgLogFile.getName();
        WildCardFilter filter = new WildCardFilter(fileWithoutDirName + ".*");
        File dir = new File(dirName);
        File[] files = dir.listFiles(filter);
        int count = (files == null ? 0 : files.length);
        for (int i = 0; i < count; i++) {
            File file = files[i];
            if (file.isDirectory()) {
                continue;
            }
            if (file.lastModified() < deleteBefore) {
                LogLog.debug("Deleting file " + file);
                file.delete();
            }
        }
    }
}
Also used : WildCardFilter(nl.nn.adapterframework.util.WildCardFilter) File(java.io.File) Date(java.util.Date)

Aggregations

WildCardFilter (nl.nn.adapterframework.util.WildCardFilter)3 File (java.io.File)2 Date (java.util.Date)2 IOException (java.io.IOException)1 DirectoryStream (java.nio.file.DirectoryStream)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Spliterators (java.util.Spliterators)1 Supplier (java.util.function.Supplier)1 Stream (java.util.stream.Stream)1 StreamSupport (java.util.stream.StreamSupport)1 Lombok (lombok.Lombok)1 FileSystemAction (nl.nn.adapterframework.filesystem.FileSystemActor.FileSystemAction)1 MessageContext (nl.nn.adapterframework.stream.MessageContext)1 DateUtils (nl.nn.adapterframework.util.DateUtils)1 LogUtil (nl.nn.adapterframework.util.LogUtil)1 Misc (nl.nn.adapterframework.util.Misc)1 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Logger (org.apache.logging.log4j.Logger)1