Class POIFSFileSystem
java.lang.Object
org.docx4j.org.apache.poi.poifs.filesystem.BlockStore
org.docx4j.org.apache.poi.poifs.filesystem.NPOIFSFileSystem
org.docx4j.org.apache.poi.poifs.filesystem.POIFSFileSystem
- All Implemented Interfaces:
Closeable,AutoCloseable,POIFSViewable
Transition class for the move from
POIFSFileSystem to
OPOIFSFileSystem, and from NPOIFSFileSystem to
POIFSFileSystem. Currently, this is OPOIFS-powered-
Nested Class Summary
Nested classes/interfaces inherited from class org.docx4j.org.apache.poi.poifs.filesystem.BlockStore
BlockStore.ChainLoopDetector -
Constructor Summary
ConstructorsConstructorDescriptionConstructor, intended for writingPOIFSFileSystem(InputStream stream) Create a POIFSFileSystem from an InputStream. -
Method Summary
Modifier and TypeMethodDescriptionstatic InputStreamConvenience method for clients that want to avoid the auto-close behaviour of the constructor.static booleanhasPOIFSHeader(byte[] header8Bytes) Checks if the supplied first 8 bytes of a stream / file has a POIFS (OLE2) header.static booleanChecks that the supplied InputStream (which MUST support mark and reset, or be a PushbackInputStream) has a POIFS (OLE2) header at the start of it.static voidread in a file and write it back out againMethods inherited from class org.docx4j.org.apache.poi.poifs.filesystem.NPOIFSFileSystem
close, createBlockIfNeeded, createDirectory, createDocument, createDocument, createDocumentInputStream, getBATBlockAndIndex, getBigBlockSize, getBigBlockSizeDetails, getBlockAt, getBlockStoreBlockSize, getChainLoopDetector, getFreeBlock, getMiniStore, getNextBlock, getRoot, getShortDescription, getViewableArray, getViewableIterator, preferArray, setNextBlock, size, writeFilesystem, writeFilesystemMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.docx4j.org.apache.poi.poifs.dev.POIFSViewable
getShortDescription, getViewableArray, getViewableIterator, preferArray
-
Constructor Details
-
POIFSFileSystem
public POIFSFileSystem()Constructor, intended for writing -
POIFSFileSystem
Create a POIFSFileSystem from an InputStream. Normally the stream is read until EOF. The stream is always closed. Some streams are usable after reaching EOF (typically those that returntruefor markSupported()). In the unlikely case that the caller has such a stream and needs to use it after this constructor completes, a work around is to wrap the stream in order to trap the close() call. A convenience method ( createNonClosingInputStream()) has been provided for this purpose:InputStream wrappedStream = POIFSFileSystem.createNonClosingInputStream(is); HSSFWorkbook wb = new HSSFWorkbook(wrappedStream); is.reset(); doSomethingElse(is);
Note also the special case of ByteArrayInputStream for which the close() method does nothing.ByteArrayInputStream bais = ... HSSFWorkbook wb = new HSSFWorkbook(bais); // calls bais.close() ! bais.reset(); // no problem doSomethingElse(bais);
- Parameters:
stream- the InputStream from which to read the data- Throws:
IOException- on errors reading, or on invalid data
-
-
Method Details
-
createNonClosingInputStream
Convenience method for clients that want to avoid the auto-close behaviour of the constructor. -
hasPOIFSHeader
Checks that the supplied InputStream (which MUST support mark and reset, or be a PushbackInputStream) has a POIFS (OLE2) header at the start of it. If your InputStream does not support mark / reset, then wrap it in a PushBackInputStream, then be sure to always use that, and not the original!- Parameters:
inp- An InputStream which supports either mark/reset, or is a PushbackInputStream- Throws:
IOException
-
hasPOIFSHeader
public static boolean hasPOIFSHeader(byte[] header8Bytes) Checks if the supplied first 8 bytes of a stream / file has a POIFS (OLE2) header. -
main
read in a file and write it back out again- Parameters:
args- names of the files; arg[ 0 ] is the input file, arg[ 1 ] is the output file- Throws:
IOException
-