concept filesystem in category java

This is an excerpt from Manning's book Spring Integration in Action.
The most basic approach is for one application to produce a file and for that file to be made available to another system. This approach is simple and generally interoperable because all that’s required is for interacting applications to be able to read and write files. Because the basic requirements for using file-based integration are simple, it’s a fairly common solution, but some of the limitations of filesystems mean that additional complexity may be created in applications having to deal with files.
One limitation is that filesystems aren’t transactional and don’t provide metadata about the current state and validity of a file. As a consequence, it’s hard to tell, for example, if another process is currently updating the file. In general, to work properly, this type of integration requires some strategies to ensure that the receiver doesn’t read inconsistent data, such as a half-written file. Also, it requires setting up a process by which corrupt files are moved out of the way to prevent repeated attempts to process them. Another significant drawback is that applications generally need to poll specific locations to discover if more files are ready to be processed, thus introducing additional application complexity and a potential for unnecessary delay.
Some files are too big to just leave them, but you can’t afford to lose a single one. In this case, you can’t delete the file from the transformer because you could lose the data if the JVM is killed, but you have to delete the file in process. A file-reading endpoint will set the original file on the message as a header. This header can be used to delete a file after it’s fully processed. Usually, the process should write a file to a processed directory when processing is complete. You can do this with a <file:outbound-channel-adapter ... delete-source-files="true" />, but it’s not a real transaction. If the filesystem is full or the process crashes midstream, input files could sit in the input directory even though they’re already processed. To mitigate this risk, you can implement an idempotent receiver in the endpoint that processes the file. Then again, it might be easier to just leave the file and write a separate cleanup routine.
Most Java developers dread dealing with the filesystem like they dread dealing with concurrency. If you consider yourself a good developer and you really like those things, you might have noticed that applying yourself to using them doesn’t make you friends in your team. In the introduction, we associated file-based integration with the simplest thing that might possibly work, but in many cases, dealing with files properly is far from simple. Simplicity is the best friend you can have in your programming career. More often than you’d expect, things like the filesystem can be safely ignored in favor of a memory solution.
A component as common as the filesystem can’t be all bad. In UNIX, for example, everything is a file, and working with intermediary files is often the simplest solution. In an object-oriented realm such as the Java Virtual Machine (JVM), dealing with the filesystem requires an extra abstraction, which adds complexity. Table 11.1 lists the advantages and disadvantages of using files.
Table 11.1. Advantages and disadvantages of interacting with the filesystem
Advantage
Disadvantage
Files survive an application crash. Extra complexity dealing with resources, open streams, locking. The disk has much more room than memory, so running out of room is less likely. Filesystem access is much slower than memory access. Files are easier than more advanced data stores to integrate with other applications. Filesystem has no atomicity, consistency, isolation, durability (ACID) or Representational State Transfer (REST) semantics, and scalability is more complicated. If you can get away with the simple solution of using objects on the heap, go for it. But if it just doesn’t work, look at the filesystem seriously before you jump into even more complex solutions. We look at an example that can best be implemented using file sharing. The rest of the chapter teaches you how you can implement it using Spring Integration’s file support.