Package org.apache.poi.poifs.filesystem
Class FilteringDirectoryNode
- java.lang.Object
-
- org.apache.poi.poifs.filesystem.FilteringDirectoryNode
-
- All Implemented Interfaces:
java.lang.Iterable<Entry>
,DirectoryEntry
,Entry
public class FilteringDirectoryNode extends java.lang.Object implements DirectoryEntry
A DirectoryEntry filter, which exposes another DirectoryEntry less certain parts. This is typically used when copying or comparing Filesystems.
-
-
Constructor Summary
Constructors Constructor Description FilteringDirectoryNode(DirectoryEntry directory, java.util.Collection<java.lang.String> excludes)
Creates a filter round the specified directory, which will exclude entries such as "MyNode" and "MyDir/IgnoreNode".
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DirectoryEntry
createDirectory(java.lang.String name)
create a new DirectoryEntryDocumentEntry
createDocument(java.lang.String name, int size, POIFSWriterListener writer)
create a new DocumentEntry; the data will be provided laterDocumentEntry
createDocument(java.lang.String name, java.io.InputStream stream)
create a new DocumentEntryboolean
delete()
Delete this Entry.java.util.Iterator<Entry>
getEntries()
get an iterator of the Entry instances contained directly in this instance (in other words, children only; no grandchildren etc.)Entry
getEntry(java.lang.String name)
get a specified Entry by nameint
getEntryCount()
find out how many Entry instances are contained directly within this DirectoryEntryjava.util.Set<java.lang.String>
getEntryNames()
get the names of all the Entries contained directly in this instance (in other words, names of children only; no grandchildren etc).java.lang.String
getName()
get the name of the EntryDirectoryEntry
getParent()
get this Entry's parent (the DirectoryEntry that owns this Entry).ClassID
getStorageClsid()
Gets the storage clsid of the directory entryboolean
hasEntry(java.lang.String name)
Checks if entry with specified name presentboolean
isDirectoryEntry()
is this a DirectoryEntry?boolean
isDocumentEntry()
is this a DocumentEntry?boolean
isEmpty()
is this DirectoryEntry empty?java.util.Iterator<Entry>
iterator()
boolean
renameTo(java.lang.String newName)
Rename this Entry.void
setStorageClsid(ClassID clsidStorage)
Sets the storage clsid for the directory entryjava.util.Spliterator<Entry>
spliterator()
-
-
-
Constructor Detail
-
FilteringDirectoryNode
public FilteringDirectoryNode(DirectoryEntry directory, java.util.Collection<java.lang.String> excludes)
Creates a filter round the specified directory, which will exclude entries such as "MyNode" and "MyDir/IgnoreNode". The excludes can stretch into children, if they contain a /.- Parameters:
directory
- The Directory to filterexcludes
- The Entries to exclude- Throws:
java.lang.IllegalArgumentException
- if directory is null
-
-
Method Detail
-
createDirectory
public DirectoryEntry createDirectory(java.lang.String name) throws java.io.IOException
Description copied from interface:DirectoryEntry
create a new DirectoryEntry- Specified by:
createDirectory
in interfaceDirectoryEntry
- Parameters:
name
- the name of the new DirectoryEntry- Returns:
- the new DirectoryEntry
- Throws:
java.io.IOException
-
createDocument
public DocumentEntry createDocument(java.lang.String name, java.io.InputStream stream) throws java.io.IOException
Description copied from interface:DirectoryEntry
create a new DocumentEntry- Specified by:
createDocument
in interfaceDirectoryEntry
- Parameters:
name
- the name of the new DocumentEntrystream
- the InputStream from which to create the new DocumentEntry- Returns:
- the new DocumentEntry
- Throws:
java.io.IOException
-
createDocument
public DocumentEntry createDocument(java.lang.String name, int size, POIFSWriterListener writer) throws java.io.IOException
Description copied from interface:DirectoryEntry
create a new DocumentEntry; the data will be provided later- Specified by:
createDocument
in interfaceDirectoryEntry
- Parameters:
name
- the name of the new DocumentEntrysize
- the size of the new DocumentEntrywriter
- the writer of the new DocumentEntry- Returns:
- the new DocumentEntry
- Throws:
java.io.IOException
-
getEntries
public java.util.Iterator<Entry> getEntries()
Description copied from interface:DirectoryEntry
get an iterator of the Entry instances contained directly in this instance (in other words, children only; no grandchildren etc.)- Specified by:
getEntries
in interfaceDirectoryEntry
- Returns:
- iterator; never null, but hasNext() may return false immediately (i.e., this DirectoryEntry is empty). All objects retrieved by next() are guaranteed to be implementations of Entry.
-
iterator
public java.util.Iterator<Entry> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<Entry>
-
spliterator
public java.util.Spliterator<Entry> spliterator()
- Specified by:
spliterator
in interfacejava.lang.Iterable<Entry>
- Since:
- POI 5.2.0
-
getEntryCount
public int getEntryCount()
Description copied from interface:DirectoryEntry
find out how many Entry instances are contained directly within this DirectoryEntry- Specified by:
getEntryCount
in interfaceDirectoryEntry
- Returns:
- number of immediately (no grandchildren etc.) contained Entry instances
-
getEntryNames
public java.util.Set<java.lang.String> getEntryNames()
Description copied from interface:DirectoryEntry
get the names of all the Entries contained directly in this instance (in other words, names of children only; no grandchildren etc).- Specified by:
getEntryNames
in interfaceDirectoryEntry
- Returns:
- the names of all the entries that may be retrieved with getEntry(String), which may be empty (if this DirectoryEntry is empty)
-
isEmpty
public boolean isEmpty()
Description copied from interface:DirectoryEntry
is this DirectoryEntry empty?- Specified by:
isEmpty
in interfaceDirectoryEntry
- Returns:
- true if this instance contains no Entry instances
-
hasEntry
public boolean hasEntry(java.lang.String name)
Description copied from interface:DirectoryEntry
Checks if entry with specified name present- Specified by:
hasEntry
in interfaceDirectoryEntry
-
getEntry
public Entry getEntry(java.lang.String name) throws java.io.FileNotFoundException
Description copied from interface:DirectoryEntry
get a specified Entry by name- Specified by:
getEntry
in interfaceDirectoryEntry
- Parameters:
name
- the name of the Entry to obtain.- Returns:
- the specified Entry, if it is directly contained in this DirectoryEntry
- Throws:
java.io.FileNotFoundException
- if no Entry with the specified name exists in this DirectoryEntry
-
getStorageClsid
public ClassID getStorageClsid()
Description copied from interface:DirectoryEntry
Gets the storage clsid of the directory entry- Specified by:
getStorageClsid
in interfaceDirectoryEntry
- Returns:
- storage Class ID
-
setStorageClsid
public void setStorageClsid(ClassID clsidStorage)
Description copied from interface:DirectoryEntry
Sets the storage clsid for the directory entry- Specified by:
setStorageClsid
in interfaceDirectoryEntry
- Parameters:
clsidStorage
- storage Class ID
-
delete
public boolean delete()
Description copied from interface:Entry
Delete this Entry. This operation should succeed, but there are special circumstances when it will not: If this Entry is the root of the Entry tree, it cannot be deleted, as there is no way to create another one. If this Entry is a directory, it cannot be deleted unless it is empty.
-
renameTo
public boolean renameTo(java.lang.String newName)
Description copied from interface:Entry
Rename this Entry. This operation will fail if: There is a sibling Entry (i.e., an Entry whose parent is the same as this Entry's parent) with the same name. This Entry is the root of the Entry tree. Its name is dictated by the Filesystem and many not be changed.
-
getName
public java.lang.String getName()
Description copied from interface:Entry
get the name of the Entry
-
getParent
public DirectoryEntry getParent()
Description copied from interface:Entry
get this Entry's parent (the DirectoryEntry that owns this Entry). All Entry objects, except the root Entry, has a parent.
-
isDirectoryEntry
public boolean isDirectoryEntry()
Description copied from interface:Entry
is this a DirectoryEntry?- Specified by:
isDirectoryEntry
in interfaceEntry
- Returns:
- true if the Entry is a DirectoryEntry, else false
-
isDocumentEntry
public boolean isDocumentEntry()
Description copied from interface:Entry
is this a DocumentEntry?- Specified by:
isDocumentEntry
in interfaceEntry
- Returns:
- true if the Entry is a DocumentEntry, else false
-
-