You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-integration-file/src/test/java/org/springframework/integration/file/config/AutoCreateDirectoryIntegrationTests.java
+11-8Lines changed: 11 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
/*
2
-
* Copyright 2002-2009 the original author or authors.
2
+
* Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
Copy file name to clipboardExpand all lines: src/reference/asciidoc/file.adoc
+26-38Lines changed: 26 additions & 38 deletions
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,8 @@ Microsoft Windows, on the other hand, has a dedicated file attribute to indicate
37
37
38
38
[IMPORTANT]
39
39
====
40
-
Version 4.2 introduced the `IgnoreHiddenFileListFilter`. In prior versions, hidden files were included.
40
+
Version 4.2 introduced the `IgnoreHiddenFileListFilter`.
41
+
In prior versions, hidden files were included.
41
42
With the default configuration, the `IgnoreHiddenFileListFilter` is triggered first, followed by the `AcceptOnceFileListFilter`.
42
43
====
43
44
@@ -53,8 +54,7 @@ This filter matches on the filename and modified time.
53
54
Since version 4.0, this filter requires a `ConcurrentMetadataStore`.
54
55
When used with a shared data store (such as `Redis` with the `RedisMetadataStore`), it lets filter keys be shared across multiple application instances or across a network file share being used by multiple servers.
55
56
56
-
Since version 4.1.5, this filter has a new property (`flushOnUpdate`), which causes it to flush the
57
-
metadata store on every update (if the store implements `Flushable`).
57
+
Since version 4.1.5, this filter has a new property (`flushOnUpdate`), which causes it to flush the metadata store on every update (if the store implements `Flushable`).
58
58
====
59
59
60
60
The following example configures a `FileReadingMessageSource` with a filter:
@@ -97,7 +97,7 @@ The `CompositeFileListFilter` enables the composition, as the following example
97
97
----
98
98
====
99
99
100
-
If it is not possible to create the file with a temporary name and rename to the final name, Spring Integratio provides another alternative.
100
+
If it is not possible to create the file with a temporary name and rename to the final name, Spring Integration provides another alternative.
101
101
Version 4.2 added the `LastModifiedFileListFilter`.
102
102
This filter can be configured with an `age` property so that only files older than this value are passed by the filter.
103
103
The age defaults to 60 seconds, but you should choose an age that is large enough to avoid picking up a file early (due to, say, network glitches).
@@ -150,14 +150,17 @@ The `CompositeFileListFilter` also implements a `DiscardAwareFileListFilter` and
150
150
151
151
NOTE: Since `CompositeFileListFilter` matches the files against all delegates, the `discardCallback` may be called several times for the same file.
152
152
153
+
Starting with version 5.1, the `FileReadingMessageSource` doesn't check a directory for existence and doesn't create it until its `start()` is called (typically via wrapping `SourcePollingChannelAdapter`).
154
+
Previously, there was no simple way to prevent an operation system permissions error when referencing the directory, for example from tests, or when permissions are applied later.
155
+
153
156
==== Message Headers
154
157
155
158
Starting with version 5.0, the `FileReadingMessageSource` (in addition to the `payload` as a polled `File`) populates the following headers to the outbound `Message`:
156
159
157
160
* `FileHeaders.FILENAME`: The `File.getName()` of the file to send.
158
161
Can be used for subsequent rename or copy logic.
159
162
* `FileHeaders.ORIGINAL_FILE`: The `File` object itself.
160
-
Typically, this header is populated automatically by framework components (such as <<file-splitter,splitters>> or`<<file-transforming,transformers>>) when we lose the original `File` object.
163
+
Typically, this header is populated automatically by framework components (such as <<file-splitter,splitters>> or<<file-transforming,transformers>>) when we lose the original `File` object.
161
164
However, for consistency and convenience with any other custom use cases, this header can be useful to get access to the original file.
162
165
* `FileHeaders.RELATIVE_PATH`: A new header introduced to represent the part of file path relative to the root directory for the scan.
163
166
This header can be useful when the requirement is to restore a source directory hierarchy in the other places.
@@ -167,21 +170,16 @@ For this purpose, the `DefaultFileNameGenerator` (see "`<<file-writing-file-name
167
170
168
171
The `FileReadingMessageSource` does not produce messages for files from the directory immediately.
169
172
It uses an internal queue for 'eligible files' returned by the `scanner`.
170
-
The `scanEachPoll` option is used to ensure that the internal queue is refreshed with the latest input directory
171
-
content on each poll.
172
-
By default (`scanEachPoll = false`), the `FileReadingMessageSource` empties its queue before scanning the directory
173
-
again.
173
+
The `scanEachPoll` option is used to ensure that the internal queue is refreshed with the latest input directory content on each poll.
174
+
By default (`scanEachPoll = false`), the `FileReadingMessageSource` empties its queue before scanning the directory again.
174
175
This default behavior is particularly useful to reduce scans of large numbers of files in a directory.
175
-
However, in cases where custom ordering is required, it is important to consider the effects of setting this flag to
176
-
`true`.
176
+
However, in cases where custom ordering is required, it is important to consider the effects of setting this flag to `true`.
177
177
The order in which files are processed may not be as expected.
178
178
By default, files in the queue are processed in their natural (`path`) order.
179
-
New files added by a scan, even when the queue already has files, are inserted in the appropriate position to maintain
180
-
that natural order.
179
+
New files added by a scan, even when the queue already has files, are inserted in the appropriate position to maintain that natural order.
181
180
To customize the order, the `FileReadingMessageSource` can accept a `Comparator<File>` as a constructor argument.
182
181
It is used by the internal (`PriorityBlockingQueue`) to reorder its content according to the business requirements.
183
-
Therefore, to process files in a specific order, you should provide a comparator to the `FileReadingMessageSource`
184
-
rather than ordering the list produced by a custom `DirectoryScanner`.
182
+
Therefore, to process files in a specific order, you should provide a comparator to the `FileReadingMessageSource` rather than ordering the list produced by a custom `DirectoryScanner`.
185
183
186
184
Version 5.0 introduced `RecursiveDirectoryScanner` to perform file tree visiting.
187
185
The implementation is based on the `Files.walk(Path start, int maxDepth, FileVisitOption... options)` functionality.
@@ -248,8 +246,7 @@ Therefore, you can also leave off the `prevent-duplicates` and `ignore-hidden` a
248
246
Spring Integration 4.2 introduced the `ignore-hidden` attribute. In prior versions, hidden files were included.
249
247
=====
250
248
251
-
The second channel adapter example uses a custom filter, the third uses the `filename-pattern` attribute to
252
-
add an `AntPathMatcher` based filter, and the fourth uses the `filename-regex` attribute to add a regular expression pattern-based filter to the `FileReadingMessageSource`.
249
+
The second channel adapter example uses a custom filter, the third uses the `filename-pattern` attribute to add an `AntPathMatcher` based filter, and the fourth uses the `filename-regex` attribute to add a regular expression pattern-based filter to the `FileReadingMessageSource`.
253
250
The `filename-pattern` and `filename-regex` attributes are each mutually exclusive with the regular `filter` reference attribute.
254
251
However, you can use the `filter` attribute to reference an instance of `CompositeFileListFilter` that combines any number of filters, including one or more pattern-based filters to fit your particular needs.
255
252
@@ -301,7 +298,7 @@ You can inject a custom `DirectoryScanner` into the `<int-file:inbound-channel-a
301
298
302
299
Doing so gives you full freedom to choose the ordering, listing, and locking strategies.
303
300
304
-
It is also important to understand that filters (including `patterns`, `regex`, `prevent-duplicates`, and otehrs) and `locker` instances are actually used by the `scanner`.
301
+
It is also important to understand that filters (including `patterns`, `regex`, `prevent-duplicates`, and others) and `locker` instances are actually used by the `scanner`.
305
302
Any of these attributes set on the adapter are subsequently injected into the internal `scanner`.
306
303
For the case of an external `scanner`, all filter and locker attributes are prohibited on the `FileReadingMessageSource`.
307
304
They must be specified (if required) on that custom `DirectoryScanner`.
@@ -324,14 +321,12 @@ If a new subdirectory is added, its creation event is used to walk the new subtr
324
321
NOTE: There is an issue with `WatchKey` when its internal events `queue` is not drained by the program as quickly as the directory modification events occur.
325
322
If the queue size is exceeded, a `StandardWatchEventKinds.OVERFLOW` is emitted to indicate that some file system events may be lost.
326
323
In this case, the root directory is re-scanned completely.
327
-
To avoid duplicates, consider using an appropriate `FileListFilter` (such as the `AcceptOnceFileListFilter`) or
328
-
removing files when processing is complete.
324
+
To avoid duplicates, consider using an appropriate `FileListFilter` (such as the `AcceptOnceFileListFilter`) or removing files when processing is complete.
329
325
330
326
The `WatchServiceDirectoryScanner` can be enabled through the `FileReadingMessageSource.use-watch-service` option, which is mutually exclusive with the `scanner` option.
331
327
An internal `FileReadingMessageSource.WatchServiceDirectoryScanner` instance is populated for the provided `directory`.
332
328
333
-
In addition, now the `WatchService` polling logic can track the `StandardWatchEventKinds.ENTRY_MODIFY` and
334
-
`StandardWatchEventKinds.ENTRY_DELETE`.
329
+
In addition, now the `WatchService` polling logic can track the `StandardWatchEventKinds.ENTRY_MODIFY` and `StandardWatchEventKinds.ENTRY_DELETE`.
335
330
336
331
If you need to track the modification of existing files as well as new files, you should implement the `ENTRY_MODIFY` events logic in the `FileListFilter`.
337
332
Otherwise, the files from those events are treated the same way.
@@ -345,6 +340,7 @@ For this purpose, the `watch-events` property (`FileReadingMessageSource.setWatc
345
340
(`WatchEventType` is a public inner enumeration in `FileReadingMessageSource`.)
346
341
With such an option, we can use one downstream flow logic for new files and use some other logic for modified files.
347
342
The following example shows how to configure different logic for create and modify events in the same directory:
343
+
348
344
====
349
345
[source,xml]
350
346
----
@@ -372,13 +368,10 @@ Any other filters (including `prevent-duplicates="true"`) overwrote the filter u
372
368
[NOTE]
373
369
=====
374
370
The use of a `HeadDirectoryScanner` is incompatible with an `AcceptOnceFileListFilter`.
375
-
Since all filters are consulted during the poll decision, the `AcceptOnceFileListFilter` does not know
376
-
that other filters might be temporarily filtering files.
377
-
Even if files that were previously filtered by the `HeadDirectoryScanner.HeadFilter` are now available, the
378
-
`AcceptOnceFileListFilter` filters them.
371
+
Since all filters are consulted during the poll decision, the `AcceptOnceFileListFilter` does not know that other filters might be temporarily filtering files.
372
+
Even if files that were previously filtered by the `HeadDirectoryScanner.HeadFilter` are now available, the `AcceptOnceFileListFilter` filters them.
379
373
380
-
Generally, instead of using an `AcceptOnceFileListFilter` in this case, you should remove the processed
381
-
files so that the previously filtered files are available on a future poll.
374
+
Generally, instead of using an `AcceptOnceFileListFilter` in this case, you should remove the processed files so that the previously filtered files are available on a future poll.
382
375
=====
383
376
384
377
==== Configuring with Java Configuration
@@ -611,8 +604,7 @@ This class can deal with the following payload types:
611
604
612
605
For a String payload, you can configure the encoding and the charset.
613
606
614
-
To make things easier, you can configure the `FileWritingMessageHandler` as part of an outbound channel adapter or
615
-
outbound gateway by using the XML namespace.
607
+
To make things easier, you can configure the `FileWritingMessageHandler` as part of an outbound channel adapter or outbound gateway by using the XML namespace.
616
608
617
609
Starting with version 4.3, you can specify the buffer size to use when writing files.
618
610
@@ -720,8 +712,7 @@ For other payloads, the `FileHeaders.SET_MODIFIED` (`file_setModified`) header i
720
712
If the header is missing or has a value that is not a `Number`, the file is always replaced.
721
713
`APPEND`::
722
714
This mode lets you append message content to the existing file instead of creating a new file each time.
723
-
Note that this attribute is mutually exclusive with the `temporary-file-suffix` attribute because, when it appends content to
724
-
the existing file, the adapter no longer uses a temporary file.
715
+
Note that this attribute is mutually exclusive with the `temporary-file-suffix` attribute because, when it appends content to the existing file, the adapter no longer uses a temporary file.
725
716
The file is closed after each message.
726
717
`APPEND_NO_FLUSH`::
727
718
This option has the same semantics as `APPEND`, but the data is not flushed and the file is not closed after each message.
@@ -747,10 +738,8 @@ Spring Integration provides several flushing strategies to mitigate this data lo
747
738
This is approximate and may be up to `1.33x` this time (with an average of `1.167x`).
748
739
* Send a message containing a regular expression to the message handler's `trigger` method.
749
740
Files with absolute path names matching the pattern are flushed.
750
-
* Provide the handler with a custom `MessageFlushPredicate` implementation to modify the action taken when a message
751
-
is sent to the `trigger` method.
752
-
* Invoke one of the handler's `flushIfNeeded` methods by passing in a custom `FileWritingMessageHandler.FlushPredicate`
753
-
or `FileWritingMessageHandler.MessageFlushPredicate` implementation.
741
+
* Provide the handler with a custom `MessageFlushPredicate` implementation to modify the action taken when a message is sent to the `trigger` method.
742
+
* Invoke one of the handler's `flushIfNeeded` methods by passing in a custom `FileWritingMessageHandler.FlushPredicate` or `FileWritingMessageHandler.MessageFlushPredicate` implementation.
754
743
755
744
The predicates are called for each open file.
756
745
See the https://docs.spring.io/spring-integration/api/index.html[Javadoc] for these interfaces for more information.
@@ -1027,8 +1016,7 @@ The default is `true`.
1027
1016
1028
1017
The `FileSplitter` also splits any text-based `InputStream` into lines.
1029
1018
Starting with version 4.3, when used in conjunction with an FTP or SFTP streaming inbound channel adapter or an FTP or SFTP outbound gateway that uses the `stream` option to retrieve a file, the splitter automatically closes the session that supports the stream when the file is completely consumed
1030
-
See <<ftp-streaming>> and <<sftp-streaming>> as well as <<ftp-outbound-gateway>> and <<sftp-outbound-gateway>> for more
1031
-
information about these facilities.
1019
+
See <<ftp-streaming>> and <<sftp-streaming>> as well as <<ftp-outbound-gateway>> and <<sftp-outbound-gateway>> for more information about these facilities.
1032
1020
1033
1021
When using Java configuration, an additional constructor is available, as the following example shows:
0 commit comments