Package digilib.io
Class DocuDirectory
- java.lang.Object
-
- digilib.io.DocuDirectory
-
- All Implemented Interfaces:
Iterable<DocuDirent>
- Direct Known Subclasses:
CdstarArchiveDocuDirectory
,FsDocuDirectory
public abstract class DocuDirectory extends Object implements Iterable<DocuDirent>
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
Fields Modifier and Type Field Description protected long
dirMTime
time directory was last modified on the file systemprotected String
dirName
directory name (digilib canonical form)protected FileOps.FileClass
fileClass
type of files in this DocuDirectoryprotected List<DocuDirent>
files
list of files (DocuDirent)protected boolean
isValid
directory object is valid (exists on disk)protected org.slf4j.Logger
logger
protected DirMeta
meta
directory metadataprotected long
objectATime
time of last access of this object (not the filesystem)protected DocuDirectory
parent
parent DocuDirectory
-
Constructor Summary
Constructors Constructor Description DocuDirectory()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
checkMeta()
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
createParentName(String fn)
Returns a possible parent directory name for path fn.DocuDirent
find(String fn)
Finds the DocuDirent with the namefn
.DocuDirent
get(int index)
Returns the ImageFileSet at the index.long
getAccessTime()
long
getDirMTime()
String
getDirName()
Returns the digilib canonical name.DirMeta
getMeta()
DocuDirectory
getParent()
Returns the parent DocuDirectory.int
indexOf(String fn)
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<DocuDirent>
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
setParent(DocuDirectory pd)
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 Detail
-
logger
protected org.slf4j.Logger logger
-
fileClass
protected FileOps.FileClass fileClass
type of files in this DocuDirectory
-
parent
protected DocuDirectory parent
parent DocuDirectory
-
files
protected List<DocuDirent> files
list of files (DocuDirent)
-
isValid
protected boolean isValid
directory object is valid (exists on disk)
-
dirName
protected String dirName
directory name (digilib canonical form)
-
meta
protected DirMeta meta
directory metadata
-
objectATime
protected long objectATime
time of last access of this object (not the filesystem)
-
dirMTime
protected long dirMTime
time directory was last modified on the file system
-
-
Method Detail
-
configure
public void configure(String path, FileOps.FileClass fileClass, DigilibConfiguration dlConfig)
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:
readDir()
-
size
public int size()
number of DocuFiles in this directory.- Returns:
- the size
-
get
public DocuDirent get(int index)
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
public int indexOf(String fn)
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
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.- Parameters:
fileList
-idx
-fn
-- Returns:
-
isPrefixBasenameAt
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.- Parameters:
fileList
-idx
-fn
-- Returns:
-
find
public DocuDirent find(String fn)
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
public String 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
public DirMeta getMeta()
- Returns:
- the DirMeta
-
iterator
public Iterator<DocuDirent> iterator()
Returns an Iterator over all DocuDirents in this DocuDirectory in default order.- Specified by:
iterator
in interfaceIterable<DocuDirent>
- Returns:
- the Iterator
-
createParentName
public abstract String createParentName(String fn)
Returns a possible parent directory name for path fn.- Parameters:
fn
- the fn- Returns:
- the parent name
-
createFilename
public abstract String createFilename(String fn)
Returns a possible file name for path fn.- Parameters:
fn
- the fn- Returns:
- the name
-
getParent
public DocuDirectory getParent()
Returns the parent DocuDirectory.- Returns:
- the DocuDirectory
-
setParent
public void setParent(DocuDirectory pd)
Sets the parent DocuDirectory.- Parameters:
pd
- the DocuDirectory
-
-