Package org.apache.poi
Class POIDocument
- java.lang.Object
- 
- org.apache.poi.POIDocument
 
- 
- All Implemented Interfaces:
- Closeable,- AutoCloseable
 - Direct Known Subclasses:
- HPSFPropertiesOnlyDocument,- HSSFWorkbook,- POIReadOnlyDocument
 
 public abstract class POIDocument extends Object implements Closeable This holds the common functionality for all POI Document classes. Currently, this relates to Document Information Properties
- 
- 
Constructor SummaryConstructors Modifier Constructor Description protectedPOIDocument(DirectoryNode dir)Constructs a POIDocument with the given directory node.protectedPOIDocument(POIFSFileSystem fs)Constructs from the default POIFS
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidclearDirectory()Clear/unlink the attached directory entryvoidclose()Closes the underlyingPOIFSFileSystemfrom which the document was read, if any.voidcreateInformationProperties()Will create whichever of SummaryInformation and DocumentSummaryInformation (HPSF) properties are not already part of your document.DirectoryNodegetDirectory()DocumentSummaryInformationgetDocumentSummaryInformation()Fetch the Document Summary Information of the documentprotected StringgetEncryptedPropertyStreamName()EncryptionInfogetEncryptionInfo()protected PropertySetgetPropertySet(String setName)For a given named property entry, either return it or null if if it wasn't foundprotected PropertySetgetPropertySet(String setName, EncryptionInfo encryptionInfo)For a given named property entry, either return it or null if if it wasn't foundSummaryInformationgetSummaryInformation()Fetch the Summary Information of the documentprotected booleaninitDirectory()check if we were created by POIFS otherwise create a new dummy POIFS for storing the package datavoidreadProperties()Find, and create objects for, the standard Document Information Properties (HPSF).voidreadProperties(boolean warnIfNull)Find, and create objects for, the standard Document Information Properties (HPSF).protected voidreplaceDirectory(DirectoryNode newDirectory)Replaces the attached directory, e.g.protected voidvalidateInPlaceWritePossible()Called during awrite()to ensure that the Document (and associatedPOIFSFileSystem) was opened in a way compatible with an in-place write.abstract voidwrite()Writes the document out to the currently openFile, via the writeablePOIFSFileSystemit was opened from.abstract voidwrite(File newFile)Writes the document out to the specified newFile.abstract voidwrite(OutputStream out)Writes the document out to the specified output stream.protected voidwriteProperties()Writes out the updated standard Document Information Properties (HPSF) into the currently open POIFSFileSystemvoidwriteProperties(POIFSFileSystem outFS)Writes out the standard Document Information Properties (HPSF)protected voidwriteProperties(POIFSFileSystem outFS, List<String> writtenEntries)Writes out the standard Document Information Properties (HPSF)
 
- 
- 
- 
Constructor Detail- 
POIDocumentprotected POIDocument(DirectoryNode dir) Constructs a POIDocument with the given directory node.- Parameters:
- dir- The- DirectoryNodewhere information is read from.
 
 - 
POIDocumentprotected POIDocument(POIFSFileSystem fs) Constructs from the default POIFS- Parameters:
- fs- the filesystem the document is read from
 
 
- 
 - 
Method Detail- 
getDocumentSummaryInformationpublic DocumentSummaryInformation getDocumentSummaryInformation() Fetch the Document Summary Information of the document- Returns:
- The Document Summary Information or null if it could not be read for this document.
 
 - 
getSummaryInformationpublic SummaryInformation getSummaryInformation() Fetch the Summary Information of the document- Returns:
- The Summary information for the document or null if it could not be read for this document.
 
 - 
createInformationPropertiespublic void createInformationProperties() Will create whichever of SummaryInformation and DocumentSummaryInformation (HPSF) properties are not already part of your document. This is normally useful when creating a new document from scratch. If the information properties are already there, then nothing will happen.
 - 
readProperties@Internal public void readProperties() Find, and create objects for, the standard Document Information Properties (HPSF). If a given property set is missing or corrupt, it will remain null;
 - 
readProperties@Internal public void readProperties(boolean warnIfNull) Find, and create objects for, the standard Document Information Properties (HPSF). If a given property set is missing or corrupt, it will remain null.- Parameters:
- warnIfNull- log a warning if any of the property sets come back as null. The directory is null when creating a new document from scratch
 
 - 
getPropertySetprotected PropertySet getPropertySet(String setName) throws IOException For a given named property entry, either return it or null if if it wasn't found- Parameters:
- setName- The property to read
- Returns:
- The value of the given property or null if it wasn't found.
- Throws:
- IOException- If retrieving properties fails
 
 - 
getPropertySetprotected PropertySet getPropertySet(String setName, EncryptionInfo encryptionInfo) throws IOException For a given named property entry, either return it or null if if it wasn't found- Parameters:
- setName- The property to read
- encryptionInfo- the encryption descriptor in case of cryptoAPI encryption
- Returns:
- The value of the given property or null if it wasn't found.
- Throws:
- IOException- If retrieving properties fails
 
 - 
writePropertiesprotected void writeProperties() throws IOExceptionWrites out the updated standard Document Information Properties (HPSF) into the currently open POIFSFileSystem- Throws:
- IOException- if an error when writing to the open- POIFSFileSystemoccurs
 
 - 
writeProperties@Internal public void writeProperties(POIFSFileSystem outFS) throws IOException Writes out the standard Document Information Properties (HPSF)- Parameters:
- outFS- the POIFSFileSystem to write the properties into
- Throws:
- IOException- if an error when writing to the- POIFSFileSystemoccurs
 
 - 
writePropertiesprotected void writeProperties(POIFSFileSystem outFS, List<String> writtenEntries) throws IOException Writes out the standard Document Information Properties (HPSF)- Parameters:
- outFS- the- POIFSFileSystemto write the properties into
- writtenEntries- a list of POIFS entries to add the property names too
- Throws:
- IOException- if an error when writing to the- POIFSFileSystemoccurs
 
 - 
validateInPlaceWritePossibleprotected void validateInPlaceWritePossible() throws IllegalStateExceptionCalled during awrite()to ensure that the Document (and associatedPOIFSFileSystem) was opened in a way compatible with an in-place write.- Throws:
- IllegalStateException- if the document was opened suitably
 
 - 
writepublic abstract void write() throws IOExceptionWrites the document out to the currently openFile, via the writeablePOIFSFileSystemit was opened from.This will fail (with an IllegalStateExceptionif the document was opened read-only, opened from anInputStreaminstead of a File, or if this is not the root document. For those cases, you must usewrite(OutputStream)orwrite(File)to write to a brand new document.- Throws:
- IOException- thrown on errors writing to the file
- IllegalStateException- if this isn't from a writable File
- Since:
- POI 3.15 beta 3
 
 - 
writepublic abstract void write(File newFile) throws IOException Writes the document out to the specified newFile. If the file exists, it will be replaced, otherwise a new one will be created- Parameters:
- newFile- The new File to write to.
- Throws:
- IOException- thrown on errors writing to the file
- Since:
- POI 3.15 beta 3
 
 - 
writepublic abstract void write(OutputStream out) throws IOException Writes the document out to the specified output stream. The stream is not closed as part of this operation. Note - if the Document was opened from aFilerather than anInputStream, you must write out usingwrite()or to a different File. Overwriting the currently open file via an OutputStream isn't possible. Ifstreamis aFileOutputStreamon a networked drive or has a high cost/latency associated with each written byte, consider wrapping the OutputStream in aBufferedOutputStreamto improve write performance, or usewrite()/write(File)if possible.- Parameters:
- out- The stream to write to.
- Throws:
- IOException- thrown on errors writing to the stream
 
 - 
closepublic void close() throws IOExceptionCloses the underlyingPOIFSFileSystemfrom which the document was read, if any. Has no effect on documents opened from an InputStream, or newly created ones.Once close()has been called, no further operations should be called on the document.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Throws:
- IOException
 
 - 
getDirectory@Internal public DirectoryNode getDirectory() 
 - 
clearDirectory@Internal protected void clearDirectory() Clear/unlink the attached directory entry
 - 
initDirectory@Internal protected boolean initDirectory() check if we were created by POIFS otherwise create a new dummy POIFS for storing the package data- Returns:
- trueif dummy directory was created,- falseotherwise
 
 - 
replaceDirectory@Internal protected void replaceDirectory(DirectoryNode newDirectory) throws IOException Replaces the attached directory, e.g. if this document is written to a new POIFSFileSystem- Parameters:
- newDirectory- the new directory
- Throws:
- IOException
 
 - 
getEncryptedPropertyStreamNameprotected String getEncryptedPropertyStreamName() - Returns:
- the stream name of the property set collection, if the document is encrypted
 
 - 
getEncryptionInfopublic EncryptionInfo getEncryptionInfo() throws IOException - Returns:
- the encryption info if the document is encrypted, otherwise null
- Throws:
- IOException- If retrieving the encryption information fails
 
 
- 
 
-