public class OPOIFSFileSystem extends java.lang.Object implements POIFSViewable
This is the main class of the POIFS system; it manages the entire life cycle of the filesystem.
This is the older version, which uses more memory, and doesn't support in-place writes.
Constructor and Description |
---|
OPOIFSFileSystem()
Constructor, intended for writing
|
OPOIFSFileSystem(java.io.InputStream stream)
Create a OPOIFSFileSystem from an InputStream.
|
Modifier and Type | Method and Description |
---|---|
protected void |
closeInputStream(java.io.InputStream stream,
boolean success) |
DirectoryEntry |
createDirectory(java.lang.String name)
create a new DirectoryEntry in the root directory
|
DocumentEntry |
createDocument(java.io.InputStream stream,
java.lang.String name)
Create a new document to be added to the root directory
|
DocumentEntry |
createDocument(java.lang.String name,
int size,
POIFSWriterListener writer)
create a new DocumentEntry in the root entry; the data will be
provided later
|
DocumentInputStream |
createDocumentInputStream(java.lang.String documentName)
open a document in the root entry's list of entries
|
static java.io.InputStream |
createNonClosingInputStream(java.io.InputStream is)
Convenience method for clients that want to avoid the auto-close behaviour of the constructor.
|
int |
getBigBlockSize() |
POIFSBigBlockSize |
getBigBlockSizeDetails() |
DirectoryNode |
getRoot()
get the root entry
|
java.lang.String |
getShortDescription()
Provides a short description of the object, to be used when a
POIFSViewable object has not provided its contents.
|
java.lang.Object[] |
getViewableArray()
Get an array of objects, some of which may implement
POIFSViewable
|
java.util.Iterator<java.lang.Object> |
getViewableIterator()
Get an Iterator of objects, some of which may implement
POIFSViewable
|
static boolean |
hasPOIFSHeader(byte[] header8Bytes)
Deprecated.
in 3.17-beta2, use
FileMagic.valueOf(InputStream) == FileMagic.OLE2 instead |
static boolean |
hasPOIFSHeader(java.io.InputStream inp)
Deprecated.
in 3.17-beta2, use
FileMagic.valueOf(InputStream) == FileMagic.OLE2 instead |
static void |
main(java.lang.String[] args)
read in a file and write it back out again
|
boolean |
preferArray()
Give viewers a hint as to whether to call getViewableArray or
getViewableIterator
|
void |
writeFilesystem(java.io.OutputStream stream)
Write the filesystem out
|
public OPOIFSFileSystem()
public OPOIFSFileSystem(java.io.InputStream stream) throws java.io.IOException
Some streams are usable after reaching EOF (typically those that return true
for 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 = OPOIFSFileSystem.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);
stream
- the InputStream from which to read the datajava.io.IOException
- on errors reading, or on invalid datapublic static java.io.InputStream createNonClosingInputStream(java.io.InputStream is)
protected void closeInputStream(java.io.InputStream stream, boolean success)
stream
- the stream to be closedsuccess
- false
if an exception is currently being thrown in the calling method@Deprecated @Removal(version="4.0") public static boolean hasPOIFSHeader(java.io.InputStream inp) throws java.io.IOException
FileMagic.valueOf(InputStream)
== FileMagic.OLE2
insteadFileMagic.prepareToCheckMagic(InputStream)
to wrap it and make
sure to always use that, and not the original!
After the method call, the InputStream is at the
same position as of the time of entering the method.inp
- An InputStream which supports either mark/resetjava.io.IOException
@Deprecated @Removal(version="4.0") public static boolean hasPOIFSHeader(byte[] header8Bytes)
FileMagic.valueOf(InputStream)
== FileMagic.OLE2
insteadpublic DocumentEntry createDocument(java.io.InputStream stream, java.lang.String name) throws java.io.IOException
stream
- the InputStream from which the document's data
will be obtainedname
- the name of the new POIFSDocumentjava.io.IOException
- on error creating the new POIFSDocumentpublic DocumentEntry createDocument(java.lang.String name, int size, POIFSWriterListener writer) throws java.io.IOException
name
- the name of the new DocumentEntrysize
- the size of the new DocumentEntrywriter
- the writer of the new DocumentEntryjava.io.IOException
public DirectoryEntry createDirectory(java.lang.String name) throws java.io.IOException
name
- the name of the new DirectoryEntryjava.io.IOException
- on name duplicationpublic void writeFilesystem(java.io.OutputStream stream) throws java.io.IOException
stream
- the OutputStream to which the filesystem will be
writtenjava.io.IOException
- thrown on errors writing to the streampublic static void main(java.lang.String[] args) throws java.io.IOException
args
- names of the files; arg[ 0 ] is the input file,
arg[ 1 ] is the output filejava.io.IOException
public DirectoryNode getRoot()
public DocumentInputStream createDocumentInputStream(java.lang.String documentName) throws java.io.IOException
documentName
- the name of the document to be openedjava.io.IOException
- if the document does not exist or the
name is that of a DirectoryEntrypublic java.lang.Object[] getViewableArray()
getViewableArray
in interface POIFSViewable
public java.util.Iterator<java.lang.Object> getViewableIterator()
getViewableIterator
in interface POIFSViewable
public boolean preferArray()
preferArray
in interface POIFSViewable
public java.lang.String getShortDescription()
getShortDescription
in interface POIFSViewable
public int getBigBlockSize()
public POIFSBigBlockSize getBigBlockSizeDetails()
Copyright 2018 The Apache Software Foundation or its licensors, as applicable.