GithubHelp home page GithubHelp logo

fileutils's Introduction

fileutils

A Simple FileWatcher Utility

To watch for changes to a file simply create a FileWatcher on that file. There are two implementations of the FileWatcher, the PollingFileWatcher and the NioFileWatcher.

The PollingFileWatcher checks the modified timestamp of the file in regular intervalls.

It is created like this:

File file = ...
FileChangeListener listener = ...
// This creates a PollingFileWatcher with a default polling intervall of 500ms and a default grace period of 1000ms.
new PollingFileWatcher(file, fileChangeListener);

Whenever the timestamp of the file changed, the PollingFileWatcher waits a grace period, before it checks the timestamp again to ensure that no further modifications where made and that the modification to the file was completed. Then the registered ChangeListener is notified.

The NioFileWatcher uses the java.nio.file.WatchService, which can be used to register a listener for file changes with the operating system. It can be created like this:

File file = ...
FileChangeListener listener = ...
// This creates a NioFileWatcher with a default grace period of 1000ms.
new NioFileWatcher(file, fileChangeListener);

It also has a grace period to wait that all changes to the file are completed, to reduce the amount of notifications and to prevent access to a file, while it is changed by another process. A notification is issued, when there where no more changes during the grace period.

NioFileWatcher does not work reliably on NFS mounted file systems. The NioFileWatcher registers itself for all changes in the parent directory of the file to watch.

Further details can be found in the JavaDoc of the corresponding classes.

fileutils's People

Contributors

finsterwalder avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.