Top Description Inners Fields Constructors Methods
com.sun.jna.examples

public abstract Class FileMonitor

extends Object
Class Inheritance
Known Direct Subclasses
com.sun.jna.examples.FileMonitor.W32FileMonitor, com.sun.jna.examples.FileMonitor.KQueueFileMonitor, com.sun.jna.examples.FileMonitor.INotifyFileMonitor
Imports
java.io.File, .FileNotFoundException, .IOException, java.util.ArrayList, .EventObject, .HashMap, .Iterator, .List, .Map, com.sun.jna.Pointer, com.sun.jna.examples.win32.Kernel32, .Kernel32.FILE_NOTIFY_INFORMATION, .Kernel32.OVERLAPPED, .W32API.HANDLE, .W32API.HANDLEByReference, com.sun.jna.ptr.IntByReference, .PointerByReference

Provides notification of file system changes. Actual capabilities may vary slightly by platform.

Watched files which are removed from the filesystem are no longer watched.

Author
twall

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
public static interface
private static class
FileMonitor.Holder

Canonical lazy loading of a singleton.

private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
private List<E>
private Map<K, V>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public synchronized void
public void
public void
addWatch(File dir, int mask)

public void
addWatch(File dir, int mask, boolean recursive)

protected abstract void
protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
public static FileMonitor
protected void
public synchronized void
public void
protected abstract void
unwatch(File file)

protected abstract void
watch(File file, int mask, boolean recursive)

Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

FILE_ACCESSEDback to summary
public static final int FILE_ACCESSED
FILE_ANYback to summary
public static final int FILE_ANY
FILE_ATTRIBUTES_CHANGEDback to summary
public static final int FILE_ATTRIBUTES_CHANGED
FILE_CREATEDback to summary
public static final int FILE_CREATED
FILE_DELETEDback to summary
public static final int FILE_DELETED
FILE_MODIFIEDback to summary
public static final int FILE_MODIFIED
FILE_NAME_CHANGED_NEWback to summary
public static final int FILE_NAME_CHANGED_NEW
FILE_NAME_CHANGED_OLDback to summary
public static final int FILE_NAME_CHANGED_OLD
FILE_RENAMEDback to summary
public static final int FILE_RENAMED
FILE_SECURITY_CHANGEDback to summary
public static final int FILE_SECURITY_CHANGED
FILE_SIZE_CHANGEDback to summary
public static final int FILE_SIZE_CHANGED
listenersback to summary
private List<E> listeners
watchedback to summary
private Map<K, V> watched

Constructor Detail

FileMonitorback to summary
public FileMonitor()

Method Detail

addFileListenerback to summary
public synchronized void addFileListener(FileMonitor.FileListener x)
addWatchback to summary
public void addWatch(File dir) throws IOException
addWatchback to summary
public void addWatch(File dir, int mask) throws IOException
addWatchback to summary
public void addWatch(File dir, int mask, boolean recursive) throws IOException
disposeback to summary
protected abstract void dispose()
finalizeback to summary
protected void finalize()

Overrides java.lang.Object.finalize.

Doc from java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

When running in a Java virtual machine in which finalization has been disabled or removed, the garbage collector will never call finalize(). In a Java virtual machine in which finalization is enabled, the garbage collector might call finalize only after an indefinite delay.

The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

getInstanceback to summary
public static FileMonitor getInstance()
notifyback to summary
protected void notify(FileMonitor.FileEvent e)
removeFileListenerback to summary
public synchronized void removeFileListener(FileMonitor.FileListener x)
removeWatchback to summary
public void removeWatch(File file)
unwatchback to summary
protected abstract void unwatch(File file)
watchback to summary
protected abstract void watch(File file, int mask, boolean recursive) throws IOException
com.sun.jna.examples back to summary

public Class FileMonitor.FileEvent

extends EventObject
Class Inheritance

Field Summary

Modifier and TypeField and Description
private File
private int
Inherited from java.util.EventObject:
source

Constructor Summary

AccessConstructor and Description
public
FileEvent(File file, int type)

Method Summary

Modifier and TypeMethod and Description
public File
public int
public String
toString()

Overrides java.util.EventObject.toString.

Returns a String representation of this EventObject.
Inherited from java.util.EventObject:
getSource

Field Detail

fileback to summary
private File file
typeback to summary
private int type

Constructor Detail

FileEventback to summary
public FileEvent(File file, int type)

Method Detail

getFileback to summary
public File getFile()
getTypeback to summary
public int getType()
toStringback to summary
public String toString()

Overrides java.util.EventObject.toString.

Doc from java.util.EventObject.toString.

Returns a String representation of this EventObject.

Returns:String

a String representation of this EventObject

com.sun.jna.examples back to summary

public Interface FileMonitor.FileListener


Method Summary

Modifier and TypeMethod and Description
public void

Method Detail

fileChangedback to summary
public void fileChanged(FileMonitor.FileEvent e)
com.sun.jna.examples back to summary

private Class FileMonitor.Holder

extends Object
Class Inheritance

Canonical lazy loading of a singleton.

Field Summary

Modifier and TypeField and Description
public static final FileMonitor

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
public static final FileMonitor INSTANCE

Constructor Detail

Holderback to summary
private Holder()
com.sun.jna.examples back to summary

private Class FileMonitor.INotifyFileMonitor

extends FileMonitor
Class Inheritance

Field Summary

Inherited from com.sun.jna.examples.FileMonitor:
FILE_ACCESSEDFILE_ANYFILE_ATTRIBUTES_CHANGEDFILE_CREATEDFILE_DELETEDFILE_MODIFIEDFILE_NAME_CHANGED_NEWFILE_NAME_CHANGED_OLDFILE_RENAMEDFILE_SECURITY_CHANGEDFILE_SIZE_CHANGED

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected void
protected void
protected void
watch(File file, int mask, boolean recursive)

Implements abstract com.sun.jna.examples.FileMonitor.watch.

Inherited from com.sun.jna.examples.FileMonitor:
addFileListeneraddWatchaddWatchaddWatchfinalizegetInstancenotifyremoveFileListenerremoveWatch

Constructor Detail

INotifyFileMonitorback to summary
private INotifyFileMonitor()

Method Detail

disposeback to summary
protected void dispose()

Implements abstract com.sun.jna.examples.FileMonitor.dispose.

unwatchback to summary
protected void unwatch(File file)

Implements abstract com.sun.jna.examples.FileMonitor.unwatch.

watchback to summary
protected void watch(File file, int mask, boolean recursive)

Implements abstract com.sun.jna.examples.FileMonitor.watch.

com.sun.jna.examples back to summary

private Class FileMonitor.KQueueFileMonitor

extends FileMonitor
Class Inheritance

Field Summary

Inherited from com.sun.jna.examples.FileMonitor:
FILE_ACCESSEDFILE_ANYFILE_ATTRIBUTES_CHANGEDFILE_CREATEDFILE_DELETEDFILE_MODIFIEDFILE_NAME_CHANGED_NEWFILE_NAME_CHANGED_OLDFILE_RENAMEDFILE_SECURITY_CHANGEDFILE_SIZE_CHANGED

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected void
protected void
protected void
watch(File file, int mask, boolean recursive)

Implements abstract com.sun.jna.examples.FileMonitor.watch.

Inherited from com.sun.jna.examples.FileMonitor:
addFileListeneraddWatchaddWatchaddWatchfinalizegetInstancenotifyremoveFileListenerremoveWatch

Constructor Detail

KQueueFileMonitorback to summary
private KQueueFileMonitor()

Method Detail

disposeback to summary
protected void dispose()

Implements abstract com.sun.jna.examples.FileMonitor.dispose.

unwatchback to summary
protected void unwatch(File file)

Implements abstract com.sun.jna.examples.FileMonitor.unwatch.

watchback to summary
protected void watch(File file, int mask, boolean recursive)

Implements abstract com.sun.jna.examples.FileMonitor.watch.

com.sun.jna.examples back to summary

private Class FileMonitor.W32FileMonitor

extends FileMonitor
Class Inheritance

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private static final int
private Map<K, V>
private Map<K, V>
private W32API.HANDLE
private Thread
Inherited from com.sun.jna.examples.FileMonitor:
FILE_ACCESSEDFILE_ANYFILE_ATTRIBUTES_CHANGEDFILE_CREATEDFILE_DELETEDFILE_MODIFIEDFILE_NAME_CHANGED_NEWFILE_NAME_CHANGED_OLDFILE_RENAMEDFILE_SECURITY_CHANGEDFILE_SIZE_CHANGED

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private int
convertMask(int mask)

protected synchronized void
private String
getSystemError(int code)

private void
protected synchronized void
private FileMonitor.W32FileMonitor.FileInfo
protected synchronized void
watch(File file, int eventMask, boolean recursive)

Implements abstract com.sun.jna.examples.FileMonitor.watch.

Inherited from com.sun.jna.examples.FileMonitor:
addFileListeneraddWatchaddWatchaddWatchfinalizegetInstancenotifyremoveFileListenerremoveWatch

Field Detail

BUFFER_SIZEback to summary
private static final int BUFFER_SIZE
fileMapback to summary
private Map<K, V> fileMap
handleMapback to summary
private Map<K, V> handleMap
portback to summary
private W32API.HANDLE port
watcherback to summary
private Thread watcher

Constructor Detail

W32FileMonitorback to summary
private W32FileMonitor()

Method Detail

convertMaskback to summary
private int convertMask(int mask)
disposeback to summary
protected synchronized void dispose()

Implements abstract com.sun.jna.examples.FileMonitor.dispose.

getSystemErrorback to summary
private String getSystemError(int code)
handleChangesback to summary
private void handleChanges(FileMonitor.W32FileMonitor.FileInfo finfo) throws IOException
unwatchback to summary
protected synchronized void unwatch(File file)

Implements abstract com.sun.jna.examples.FileMonitor.unwatch.

waitForChangeback to summary
private FileMonitor.W32FileMonitor.FileInfo waitForChange()
watchback to summary
protected synchronized void watch(File file, int eventMask, boolean recursive) throws IOException

Implements abstract com.sun.jna.examples.FileMonitor.watch.

com.sun.jna.examples back to summary

private Class FileMonitor.W32FileMonitor.FileInfo

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
public File
public W32API.HANDLE
public Kernel32.FILE_NOTIFY_INFORMATION
public IntByReference
public int
public Kernel32.OVERLAPPED
public boolean

Constructor Summary

AccessConstructor and Description
public
FileInfo(File f, W32API.HANDLE h, int mask, boolean recurse)

Field Detail

fileback to summary
public File file
handleback to summary
public W32API.HANDLE handle
infoback to summary
public Kernel32.FILE_NOTIFY_INFORMATION info
infoLengthback to summary
public IntByReference infoLength
notifyMaskback to summary
public int notifyMask
overlappedback to summary
public Kernel32.OVERLAPPED overlapped
recursiveback to summary
public boolean recursive

Constructor Detail

FileInfoback to summary
public FileInfo(File f, W32API.HANDLE h, int mask, boolean recurse)