xmlBlaster 2.2.0 API

org.xmlBlaster.contrib.filewatcher
Class DirectoryManager

java.lang.Object
  extended by org.xmlBlaster.contrib.filewatcher.DirectoryManager

public class DirectoryManager
extends java.lang.Object

DirectoryManager

Author:
Michele Laghi

Field Summary
private  boolean copyOnMove
           
private  long delaySinceLastFileChange
           
private  java.io.File directory
           
private  java.util.Map directoryEntries
           
private  java.lang.String directoryName
           
private  java.io.File discardedDirectory
          this is the name of the directory where files are moved if they could not be send (too big)
private  java.io.FileFilter fileFilter
          all files matching the filter will be processed.
private  Global global
           
private  java.lang.String lockExt
          convenience for performance: if lockExtention is '*.gif', then this will be '.gif'
private  java.io.FileFilter lockExtention
          if set, then files will only be published when the lock-file has been removed.
private  java.util.Set lockFiles
           
private static java.util.logging.Logger log
           
private  java.lang.String ME
           
private  java.io.File sentDirectory
          this is the the directory where files are moved to after successful publishing.
private  java.lang.String subDirectoryName
           
 
Constructor Summary
DirectoryManager(Global global, java.lang.String name, java.lang.String directoryName, java.lang.String subDir, long delaySinceLastFileChange, java.lang.String filter, java.lang.String sent, java.lang.String discarded, java.lang.String lockExtention, boolean trueRegex, boolean copyOnMove)
           
 
Method Summary
private  boolean deleteFile(java.io.File tempFile)
          On Windows sometimes the file is not deleted (even if the stream.close() were called before) We try as long until the file is away See http://forum.java.sun.com/thread.jspa?forumID=4&threadID=158689
(package private)  void deleteOrMoveEntry(java.lang.String entryName, boolean success)
          Removes the specified entry from the map.
 java.lang.String[] getAllSubDirs()
          Returns null if no subdirectory found.
 byte[] getContent(FileInfo info)
          Gets the content from the specified file as a byte[].
 java.io.FileInputStream getContentStream(FileInfo info)
           
(package private)  java.io.File getDir()
           
(package private)  java.util.Set getEntries()
          Gets all entries which are ready to be sent (i.e.
private  java.util.Map getNewFiles(java.io.File directory)
          Retrieves all files from the specified directory
 java.lang.String getString()
           
 java.lang.String getSubDir()
           
private  java.io.File initDirectory(java.io.File parent, java.lang.String propNameForLogging, java.lang.String dirName)
          Returns the specified directory or null or if needed it will create one
static boolean isFileNameCasesensitive()
           
private  boolean isReady(FileInfo info, long currentTime)
          Returns false if the info object is null, if the size is zero or if it has not passed sufficient time since the last change.
static void main(java.lang.String[] args)
          java org.xmlBlaster.contrib.filewatcher.DirectoryManager -path /tmp/filewatcher -filter "*.xml" -filterType simple
private  void moveTo(java.io.File file, java.lang.String origName, java.io.File destinationDirectory)
           
private  java.util.TreeSet prepareEntries(java.util.Map existingFiles)
           
private static java.util.List scanSubdirs(java.io.File root, java.lang.String prefix, java.util.List subdirs, java.util.List ignore)
           
private  void updateExistingFiles(java.util.Map existingFiles, java.util.Map newFiles)
          It updates the existing list of files: - if a file which previously existed is not found in the new list anymore it is deleted - new files are added to the list - if something has changed (timestamp or size, then the corresponding info object is touched
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ME

private java.lang.String ME

global

private Global global

log

private static java.util.logging.Logger log

delaySinceLastFileChange

private long delaySinceLastFileChange

directoryName

private java.lang.String directoryName

directory

private java.io.File directory

sentDirectory

private java.io.File sentDirectory
this is the the directory where files are moved to after successful publishing. If null they will be erased


discardedDirectory

private java.io.File discardedDirectory
this is the name of the directory where files are moved if they could not be send (too big)


directoryEntries

private java.util.Map directoryEntries

fileFilter

private java.io.FileFilter fileFilter
all files matching the filter will be processed. Null means everything will be processed


lockExtention

private java.io.FileFilter lockExtention
if set, then files will only be published when the lock-file has been removed.


lockExt

private java.lang.String lockExt
convenience for performance: if lockExtention is '*.gif', then this will be '.gif'


lockFiles

private java.util.Set lockFiles

copyOnMove

private boolean copyOnMove

subDirectoryName

private java.lang.String subDirectoryName
Constructor Detail

DirectoryManager

public DirectoryManager(Global global,
                        java.lang.String name,
                        java.lang.String directoryName,
                        java.lang.String subDir,
                        long delaySinceLastFileChange,
                        java.lang.String filter,
                        java.lang.String sent,
                        java.lang.String discarded,
                        java.lang.String lockExtention,
                        boolean trueRegex,
                        boolean copyOnMove)
                 throws XmlBlasterException
Throws:
XmlBlasterException
Method Detail

scanSubdirs

private static java.util.List scanSubdirs(java.io.File root,
                                          java.lang.String prefix,
                                          java.util.List subdirs,
                                          java.util.List ignore)

getAllSubDirs

public java.lang.String[] getAllSubDirs()
Returns null if no subdirectory found.

Returns:

initDirectory

private java.io.File initDirectory(java.io.File parent,
                                   java.lang.String propNameForLogging,
                                   java.lang.String dirName)
                            throws XmlBlasterException
Returns the specified directory or null or if needed it will create one

Parameters:
propName -
dirName -
Returns:
Throws:
XmlBlasterException

getNewFiles

private java.util.Map getNewFiles(java.io.File directory)
                           throws XmlBlasterException
Retrieves all files from the specified directory

Parameters:
directory -
Returns:
never returns null.
Throws:
XmlBlasterException

deleteFile

private boolean deleteFile(java.io.File tempFile)
On Windows sometimes the file is not deleted (even if the stream.close() were called before) We try as long until the file is away See http://forum.java.sun.com/thread.jspa?forumID=4&threadID=158689

Parameters:
tempFile -
Returns:
true if successfully deleted

isFileNameCasesensitive

public static boolean isFileNameCasesensitive()

isReady

private boolean isReady(FileInfo info,
                        long currentTime)
Returns false if the info object is null, if the size is zero or if it has not passed sufficient time since the last change.

Parameters:
info -
currentTime -
Returns:

prepareEntries

private java.util.TreeSet prepareEntries(java.util.Map existingFiles)

updateExistingFiles

private void updateExistingFiles(java.util.Map existingFiles,
                                 java.util.Map newFiles)
It updates the existing list of files: - if a file which previously existed is not found in the new list anymore it is deleted - new files are added to the list - if something has changed (timestamp or size, then the corresponding info object is touched

Parameters:
existingFiles -
newFiles -

getEntries

java.util.Set getEntries()
                   throws XmlBlasterException
Gets all entries which are ready to be sent (i.e. to be published)

Returns:
all entries as a TreeSet. Elements in the set are of type FileInfo
Throws:
XmlBlasterException - if the application has no read or write rights on the directory

deleteOrMoveEntry

void deleteOrMoveEntry(java.lang.String entryName,
                       boolean success)
                 throws XmlBlasterException
Removes the specified entry from the map. This method does also remove the entry from the file system or it moves it to the requested directory. If for some reason this is not possible, then an exception is thrown.

Parameters:
entryName - the name of the entry to remove.
Throws:
XmlBlasterException

moveTo

private void moveTo(java.io.File file,
                    java.lang.String origName,
                    java.io.File destinationDirectory)
             throws XmlBlasterException
Throws:
XmlBlasterException

getContentStream

public java.io.FileInputStream getContentStream(FileInfo info)
                                         throws XmlBlasterException
Throws:
XmlBlasterException

getContent

public byte[] getContent(FileInfo info)
                  throws XmlBlasterException
Gets the content from the specified file as a byte[]. If this is not possible it will throw an exception.

Parameters:
info -
Returns:
Throws:
XmlBlasterException

getSubDir

public java.lang.String getSubDir()

main

public static void main(java.lang.String[] args)
java org.xmlBlaster.contrib.filewatcher.DirectoryManager -path /tmp/filewatcher -filter "*.xml" -filterType simple


getString

public java.lang.String getString()

getDir

java.io.File getDir()

xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.