Package thredds.inventory.partition
Class DirectoryCollection
- java.lang.Object
-
- thredds.inventory.CollectionAbstract
-
- thredds.inventory.partition.DirectoryCollection
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,MCollection
- Direct Known Subclasses:
FilePartition
public class DirectoryCollection extends CollectionAbstract
Manage MFiles from one directory. Doesnt know about parents or children. Use getFileIterator() for best performance on large directories- Since:
- 11/16/13
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
DirectoryCollection.Visitor
-
Nested classes/interfaces inherited from class thredds.inventory.CollectionAbstract
CollectionAbstract.DateSorter, CollectionAbstract.MyStreamFilter
-
-
Field Summary
-
Fields inherited from class thredds.inventory.CollectionAbstract
auxInfo, CATALOG, collectionName, dateExtractor, DIR, FILE, GLOB, lastModified, LIST, logger, protoChoice, root, sfilter, startCollection
-
-
Constructor Summary
Constructors Constructor Description DirectoryCollection(String topCollectionName, String topDirS, boolean isTop, String olderThan, org.slf4j.Logger logger)
DirectoryCollection(String topCollectionName, Path collectionDir, boolean isTop, String olderThan, org.slf4j.Logger logger)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close and release any resources.CloseableIterator<MFile>
getFileIterator()
Get the current collection of MFile, no guaranteed order.Iterable<MFile>
getFilesSorted()
Get the current collection of MFile.String
getIndexFilename(String suffix)
String
getRoot()
Get common root directory of all MFiles in the collection - may be nullvoid
iterateOverMFileCollection(DirectoryCollection.Visitor visit)
static Path
makeCollectionIndexPath(String topCollectionName, Path dir, String suffix)
Create standard name = topCollectionName + last directorystatic String
makeCollectionName(String topCollectionName, Path dir)
Create standard name = topCollectionName + last directory-
Methods inherited from class thredds.inventory.CollectionAbstract
cleanName, extractDate, getAuxInfo, getCollectionName, getFilenames, getLastModified, getLatestFile, getPartitionDate, getProtoIndex, hasDateExtractor, makeFileListSorted, open, parseOlderThanString, putAuxInfo, setDateExtractor, setRoot, setStreamFilter
-
-
-
-
Method Detail
-
makeCollectionName
public static String makeCollectionName(String topCollectionName, Path dir)
Create standard name = topCollectionName + last directory- Parameters:
topCollectionName
- from config, name of the collectiondir
- directory for this- Returns:
- standard collection name, to name the index file
-
makeCollectionIndexPath
public static Path makeCollectionIndexPath(String topCollectionName, Path dir, String suffix)
Create standard name = topCollectionName + last directory- Parameters:
topCollectionName
- from config, name of the collectiondir
- directory for this- Returns:
- standard collection name, to name the index file
-
getRoot
public String getRoot()
Description copied from interface:MCollection
Get common root directory of all MFiles in the collection - may be null- Specified by:
getRoot
in interfaceMCollection
- Overrides:
getRoot
in classCollectionAbstract
- Returns:
- root directory name, or null.
-
getIndexFilename
public String getIndexFilename(String suffix)
- Specified by:
getIndexFilename
in interfaceMCollection
- Overrides:
getIndexFilename
in classCollectionAbstract
-
getFilesSorted
public Iterable<MFile> getFilesSorted() throws IOException
Description copied from interface:MCollection
Get the current collection of MFile. if hasDateExtractor() == true, these will be sorted by Date, otherwise by path.- Returns:
- current collection of MFile as an Iterable.
- Throws:
IOException
-
getFileIterator
public CloseableIterator<MFile> getFileIterator() throws IOException
Description copied from interface:MCollection
Get the current collection of MFile, no guaranteed order. May be faster than getFilesSorted() for large collections, use when order is not important.try (CloseableIterator
iter = getFileIterator()) { while (iter.hasNext()) { MFile file = iter.next(); } } - Returns:
- current collection of MFile as an CloseableIterator.
- Throws:
IOException
-
close
public void close()
Description copied from interface:MCollection
Close and release any resources. Do not make further calls on this object.
-
iterateOverMFileCollection
public void iterateOverMFileCollection(DirectoryCollection.Visitor visit) throws IOException
- Throws:
IOException
-
-