Package digilib.io
Class DocuDirectory
java.lang.Object
digilib.io.DocuDirectory
- All Implemented Interfaces:
Iterable<DocuDirent>
- Direct Known Subclasses:
CdstarArchiveDocuDirectory
,FsDocuDirectory
Class representing a directory containing (image) files.
Files can be access by index or name. All files are of the same FileClass.
The DocuDirectory holds DirMeta.
Subclasses of DocuDirectory can also hold multiple scaled versions of an image file.
- Author:
- casties
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected long
time directory was last modified on the file systemprotected String
directory name (digilib canonical form)protected FileOps.FileClass
type of files in this DocuDirectoryprotected List
<DocuDirent> list of files (DocuDirent)protected boolean
directory object is valid (exists on disk)protected org.slf4j.Logger
protected DirMeta
directory metadataprotected long
time of last access of this object (not the filesystem)protected DocuDirectory
parent DocuDirectory -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
check directory metadata.void
configure
(String path, FileOps.FileClass fileClass, DigilibConfiguration dlConfig) Configure object with digilib directory path and a parent DocuDirCache.abstract String
createFilename
(String fn) Returns a possible file name for path fn.abstract String
Returns a possible parent directory name for path fn.Finds the DocuDirent with the namefn
.get
(int index) Returns the ImageFileSet at the index.long
long
Returns the digilib canonical name.getMeta()
Returns the parent DocuDirectory.int
Searches for the file with the namefn
.protected boolean
isBasenameAt
(List<DocuDirent> fileList, int idx, String fn) Checks if the basename of the DocuDirent in fileList at the position idx matches fn.protected boolean
isPrefixBasenameAt
(List<DocuDirent> fileList, int idx, String fn) Checks if fn is the prefix of the basename of the DocuDirent in fileList at the position idx.boolean
isRead()
The directory has been read from disk.boolean
isValid()
The directory is valid (exists on disk).iterator()
Returns an Iterator over all DocuDirents in this DocuDirectory in default order.abstract boolean
readDir()
Read the filesystem directory and fill this object.void
readMeta()
Read directory metadata.abstract boolean
refresh()
Check to see if the directory has been modified and reread if necessary.void
Sets the parent DocuDirectory.int
size()
number of DocuFiles in this directory.long
touch()
Update access time.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
logger
protected org.slf4j.Logger logger -
fileClass
type of files in this DocuDirectory -
parent
parent DocuDirectory -
files
list of files (DocuDirent) -
isValid
protected boolean isValiddirectory object is valid (exists on disk) -
dirName
directory name (digilib canonical form) -
meta
directory metadata -
objectATime
protected long objectATimetime of last access of this object (not the filesystem) -
dirMTime
protected long dirMTimetime directory was last modified on the file system
-
-
Constructor Details
-
DocuDirectory
public DocuDirectory()
-
-
Method Details
-
configure
Configure object with digilib directory path and a parent DocuDirCache. Directory names at the given path are appended to the base directories from the cache. The directory is checked on disk and isValid is set.- Parameters:
path
- digilib directory path namefileClass
- type of files in this DocuDirectorydlConfig
- digilib config- See Also:
-
size
public int size()number of DocuFiles in this directory.- Returns:
- the size
-
get
Returns the ImageFileSet at the index.- Parameters:
index
- the index- Returns:
- the DocuDirent
-
readDir
public abstract boolean readDir()Read the filesystem directory and fill this object. Clears the List and (re)reads all files.- Returns:
- boolean the directory exists
-
refresh
public abstract boolean refresh()Check to see if the directory has been modified and reread if necessary.- Returns:
- boolean the directory is valid
-
readMeta
public void readMeta()Read directory metadata. -
checkMeta
public void checkMeta()check directory metadata. -
touch
public long touch()Update access time.- Returns:
- time of last access.
-
indexOf
Searches for the file with the namefn
. Searches the directory for the file with the namefn
and returns its index. Returns -1 if the file cannot be found.- Parameters:
fn
- filename- Returns:
- int index of file
fn
-
isBasenameAt
Checks if the basename of the DocuDirent in fileList at the position idx matches fn.- Parameters:
fileList
-idx
-fn
-- Returns:
-
isPrefixBasenameAt
Checks if fn is the prefix of the basename of the DocuDirent in fileList at the position idx.- Parameters:
fileList
-idx
-fn
-- Returns:
-
find
Finds the DocuDirent with the namefn
. Searches the directory for the DocuDirent with the namefn
and returns it. Returns null if the file cannot be found.- Parameters:
fn
- filename- Returns:
- the DocuDirent
-
getDirName
Returns the digilib canonical name.- Returns:
- the name
-
isValid
public boolean isValid()The directory is valid (exists on disk).- Returns:
- is valid
-
isRead
public boolean isRead()The directory has been read from disk.- Returns:
- is read
-
getAccessTime
public long getAccessTime()- Returns:
- access time
-
getDirMTime
public long getDirMTime()- Returns:
- the mtime
-
getMeta
- Returns:
- the DirMeta
-
iterator
Returns an Iterator over all DocuDirents in this DocuDirectory in default order.- Specified by:
iterator
in interfaceIterable<DocuDirent>
- Returns:
- the Iterator
-
createParentName
Returns a possible parent directory name for path fn.- Parameters:
fn
- the fn- Returns:
- the parent name
-
createFilename
Returns a possible file name for path fn.- Parameters:
fn
- the fn- Returns:
- the name
-
getParent
Returns the parent DocuDirectory.- Returns:
- the DocuDirectory
-
setParent
Sets the parent DocuDirectory.- Parameters:
pd
- the DocuDirectory
-