Package org.apache.poi.poifs.filesystem
Class DirectoryNode
- java.lang.Object
-
- org.apache.poi.poifs.filesystem.EntryNode
-
- org.apache.poi.poifs.filesystem.DirectoryNode
-
- All Implemented Interfaces:
Iterable<Entry>,POIFSViewable,DirectoryEntry,Entry
public class DirectoryNode extends EntryNode implements DirectoryEntry, POIFSViewable, Iterable<Entry>
Simple implementation of DirectoryEntry
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DirectoryEntrycreateDirectory(String name)create a new DirectoryEntryDocumentEntrycreateDocument(String name, int size, POIFSWriterListener writer)create a new DocumentEntry; the data will be provided laterDocumentEntrycreateDocument(String name, InputStream stream)create a new DocumentEntryDocumentInputStreamcreateDocumentInputStream(String documentName)open a document in the directory's entry's list of entriesDocumentInputStreamcreateDocumentInputStream(Entry document)open a document in the directory's entry's list of entriesDocumentEntrycreateOrUpdateDocument(String name, InputStream stream)Set the contents of a document, creating if needed, otherwise updating.Iterator<Entry>getEntries()get an iterator of the Entry instances contained directly in this instance (in other words, children only; no grandchildren etc.)EntrygetEntry(String name)get a specified Entry by name, case sensitiveEntrygetEntryCaseInsensitive(String name)get a specified Entry by name, case-insensitiveintgetEntryCount()find out how many Entry instances are contained directly within this DirectoryEntrySet<String>getEntryNames()get the literal, case-sensitive names of all the Entries contained directly in this instance (in other words, names of children only; no grandchildren etc).POIFSFileSystemgetFileSystem()POIFSDocumentPathgetPath()StringgetShortDescription()Provides a short description of the object, to be used when a POIFSViewable object has not provided its contents.ClassIDgetStorageClsid()Gets the storage clsid of the directory entryObject[]getViewableArray()Get an array of objects, some of which may implement POIFSViewableIterator<Object>getViewableIterator()Get an Iterator of objects, some of which may implement POIFSViewablebooleanhasEntry(String name)Checks for a specific entry in a case-sensitive way.booleanhasEntryCaseInsensitive(String name)Checks for a specific entry in a case-insensitive way.protected booleanisDeleteOK()extensions use this method to verify internal rules regarding deletion of the underlying store.booleanisDirectoryEntry()is this a DirectoryEntry?booleanisEmpty()is this DirectoryEntry empty?Iterator<Entry>iterator()Returns an Iterator over all the entriesbooleanpreferArray()Give viewers a hint as to whether to call getViewableArray or getViewableIteratorvoidsetStorageClsid(ClassID clsidStorage)Sets the storage clsid for the directory entrySpliterator<Entry>spliterator()Returns a Spliterator over all the entries-
Methods inherited from class org.apache.poi.poifs.filesystem.EntryNode
delete, getName, getParent, getProperty, isDocumentEntry, isRoot, renameTo
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Method Detail
-
getPath
public POIFSDocumentPath getPath()
- Returns:
- this directory's path representation
-
getFileSystem
public POIFSFileSystem getFileSystem()
- Returns:
- the filesystem that this belongs to
-
createDocumentInputStream
public DocumentInputStream createDocumentInputStream(String documentName) throws IOException
open a document in the directory's entry's list of entries- Parameters:
documentName- the name of the document to be opened- Returns:
- a newly opened DocumentInputStream
- Throws:
IOException- if the document does not exist or the name is that of a DirectoryEntry
-
createDocumentInputStream
public DocumentInputStream createDocumentInputStream(Entry document) throws IOException
open a document in the directory's entry's list of entries- Parameters:
document- the document to be opened- Returns:
- a newly opened DocumentInputStream or DocumentInputStream
- Throws:
IOException- if the document does not exist or the name is that of a DirectoryEntry
-
getEntries
public Iterator<Entry> getEntries()
get an iterator of the Entry instances contained directly in this instance (in other words, children only; no grandchildren etc.)- Specified by:
getEntriesin 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.
-
getEntryNames
public Set<String> getEntryNames()
get the literal, case-sensitive names of all the Entries contained directly in this instance (in other words, names of children only; no grandchildren etc).- Specified by:
getEntryNamesin 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()
is this DirectoryEntry empty?- Specified by:
isEmptyin interfaceDirectoryEntry- Returns:
- true if this instance contains no Entry instances
-
getEntryCount
public int getEntryCount()
find out how many Entry instances are contained directly within this DirectoryEntry- Specified by:
getEntryCountin interfaceDirectoryEntry- Returns:
- number of immediately (no grandchildren etc.) contained Entry instances
-
hasEntry
public boolean hasEntry(String name)
Checks for a specific entry in a case-sensitive way.- Specified by:
hasEntryin interfaceDirectoryEntry- Parameters:
name-- Returns:
- whether or not an entry exists for that name (case-sensitive)
-
hasEntryCaseInsensitive
public boolean hasEntryCaseInsensitive(String name)
Checks for a specific entry in a case-insensitive way.- Specified by:
hasEntryCaseInsensitivein interfaceDirectoryEntry- Parameters:
name-- Returns:
- whether or not an entry exists for that name (case-insensitive)
-
getEntry
public Entry getEntry(String name) throws FileNotFoundException
get a specified Entry by name, case sensitive- Specified by:
getEntryin interfaceDirectoryEntry- Parameters:
name- the name of the Entry to obtain.- Returns:
- the specified Entry, if it is directly contained in this DirectoryEntry
- Throws:
FileNotFoundException- if no Entry with the specified name exists in this DirectoryEntry
-
getEntryCaseInsensitive
public Entry getEntryCaseInsensitive(String name) throws FileNotFoundException
get a specified Entry by name, case-insensitive- Specified by:
getEntryCaseInsensitivein interfaceDirectoryEntry- Parameters:
name- the name of the Entry to obtain.- Returns:
- the specified Entry, if it is directly contained in this DirectoryEntry
- Throws:
FileNotFoundException- if no Entry with the specified name exists in this DirectoryEntry
-
createDocument
public DocumentEntry createDocument(String name, InputStream stream) throws IOException
create a new DocumentEntry- Specified by:
createDocumentin interfaceDirectoryEntry- Parameters:
name- the name of the new DocumentEntrystream- the InputStream from which to create the new DocumentEntry- Returns:
- the new DocumentEntry
- Throws:
IOException- if the document can't be created
-
createDocument
public DocumentEntry createDocument(String name, int size, POIFSWriterListener writer) throws IOException
create a new DocumentEntry; the data will be provided later- Specified by:
createDocumentin 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:
IOException- if the document can't be created
-
createDirectory
public DirectoryEntry createDirectory(String name) throws IOException
create a new DirectoryEntry- Specified by:
createDirectoryin interfaceDirectoryEntry- Parameters:
name- the name of the new DirectoryEntry- Returns:
- the new DirectoryEntry
- Throws:
IOException- if the directory can't be created
-
createOrUpdateDocument
public DocumentEntry createOrUpdateDocument(String name, InputStream stream) throws IOException
Set the contents of a document, creating if needed, otherwise updating. Returns the created / updated DocumentEntry- Parameters:
name- the name of the new or existing DocumentEntrystream- the InputStream from which to populate the DocumentEntry- Returns:
- the new or updated DocumentEntry
- Throws:
IOException- if the document can't be created or its content be replaced
-
getStorageClsid
public ClassID getStorageClsid()
Gets the storage clsid of the directory entry- Specified by:
getStorageClsidin interfaceDirectoryEntry- Returns:
- storage Class ID
-
setStorageClsid
public void setStorageClsid(ClassID clsidStorage)
Sets the storage clsid for the directory entry- Specified by:
setStorageClsidin interfaceDirectoryEntry- Parameters:
clsidStorage- storage Class ID
-
isDirectoryEntry
public boolean isDirectoryEntry()
is this a DirectoryEntry?- Specified by:
isDirectoryEntryin interfaceEntry- Overrides:
isDirectoryEntryin classEntryNode- Returns:
- true if the Entry is a DirectoryEntry, else false
-
isDeleteOK
protected boolean isDeleteOK()
extensions use this method to verify internal rules regarding deletion of the underlying store.- Specified by:
isDeleteOKin classEntryNode- Returns:
- true if it's ok to delete the underlying store, else false
-
getViewableArray
public Object[] getViewableArray()
Get an array of objects, some of which may implement POIFSViewable- Specified by:
getViewableArrayin interfacePOIFSViewable- Returns:
- an array of Object; may not be null, but may be empty
-
getViewableIterator
public Iterator<Object> getViewableIterator()
Get an Iterator of objects, some of which may implement POIFSViewable- Specified by:
getViewableIteratorin interfacePOIFSViewable- Returns:
- an Iterator; may not be null, but may have an empty back end store
-
preferArray
public boolean preferArray()
Give viewers a hint as to whether to call getViewableArray or getViewableIterator- Specified by:
preferArrayin interfacePOIFSViewable- Returns:
- true if a viewer should call getViewableArray, false if a viewer should call getViewableIterator
-
getShortDescription
public String getShortDescription()
Provides a short description of the object, to be used when a POIFSViewable object has not provided its contents.- Specified by:
getShortDescriptionin interfacePOIFSViewable- Returns:
- short description
-
spliterator
public Spliterator<Entry> spliterator()
Returns a Spliterator over all the entries- Specified by:
spliteratorin interfaceIterable<Entry>- Since:
- POI 5.2.0
-
-