Methods Summary |
---|
void | addDirectory(org.apache.poi.poifs.property.DirectoryProperty directory)add a new DirectoryProperty
_property_table.addProperty(directory);
|
void | addDocument(org.apache.poi.poifs.filesystem.POIFSDocument document)add a new POIFSDocument
_documents.add(document);
_property_table.addProperty(document.getDocumentProperty());
|
public org.apache.poi.poifs.filesystem.DirectoryEntry | createDirectory(java.lang.String name)create a new DirectoryEntry in the root directory
return getRoot().createDirectory(name);
|
public org.apache.poi.poifs.filesystem.DocumentEntry | createDocument(java.io.InputStream stream, java.lang.String name)Create a new document to be added to the root directory
return getRoot().createDocument(name, stream);
|
public org.apache.poi.poifs.filesystem.DocumentEntry | createDocument(java.lang.String name, int size, org.apache.poi.poifs.filesystem.POIFSWriterListener writer)create a new DocumentEntry in the root entry; the data will be
provided later
return getRoot().createDocument(name, size, writer);
|
public org.apache.poi.poifs.filesystem.DocumentInputStream | createDocumentInputStream(java.lang.String documentName)open a document in the root entry's list of entries
Entry document = getRoot().getEntry(documentName);
if (!document.isDocumentEntry())
{
throw new IOException("Entry '" + documentName
+ "' is not a DocumentEntry");
}
return new DocumentInputStream(( DocumentEntry ) document);
|
public org.apache.poi.poifs.filesystem.DirectoryEntry | getRoot()get the root entry
if (_root == null)
{
_root = new DirectoryNode(_property_table.getRoot(), this, null);
}
return _root;
|
public java.lang.String | getShortDescription()Provides a short description of the object, to be used when a
POIFSViewable object has not provided its contents.
return "POIFS FileSystem";
|
public java.lang.Object[] | getViewableArray()Get an array of objects, some of which may implement
POIFSViewable
if (preferArray())
{
return (( POIFSViewable ) getRoot()).getViewableArray();
}
else
{
return new Object[ 0 ];
}
|
public java.util.Iterator | getViewableIterator()Get an Iterator of objects, some of which may implement
POIFSViewable
if (!preferArray())
{
return (( POIFSViewable ) getRoot()).getViewableIterator();
}
else
{
return Collections.EMPTY_LIST.iterator();
}
|
public static void | main(java.lang.String[] args)read in a file and write it back out again
if (args.length != 2)
{
System.err.println(
"two arguments required: input filename and output filename");
System.exit(1);
}
FileInputStream istream = new FileInputStream(args[ 0 ]);
FileOutputStream ostream = new FileOutputStream(args[ 1 ]);
new POIFSFileSystem(istream).writeFilesystem(ostream);
istream.close();
ostream.close();
|
public boolean | preferArray()Give viewers a hint as to whether to call getViewableArray or
getViewableIterator
return (( POIFSViewable ) getRoot()).preferArray();
|
private void | processProperties(org.apache.poi.poifs.storage.BlockList small_blocks, org.apache.poi.poifs.storage.BlockList big_blocks, java.util.Iterator properties, org.apache.poi.poifs.filesystem.DirectoryNode dir)
while (properties.hasNext())
{
Property property = ( Property ) properties.next();
String name = property.getName();
DirectoryNode parent = (dir == null)
? (( DirectoryNode ) getRoot())
: dir;
if (property.isDirectory())
{
DirectoryNode new_dir =
( DirectoryNode ) parent.createDirectory(name);
new_dir.setStorageClsid( property.getStorageClsid() );
processProperties(
small_blocks, big_blocks,
(( DirectoryProperty ) property).getChildren(), new_dir);
}
else
{
int startBlock = property.getStartBlock();
int size = property.getSize();
POIFSDocument document = null;
if (property.shouldUseSmallBlocks())
{
document =
new POIFSDocument(name, small_blocks
.fetchBlocks(startBlock), size);
}
else
{
document =
new POIFSDocument(name,
big_blocks.fetchBlocks(startBlock),
size);
}
parent.createDocument(document);
}
}
|
void | remove(org.apache.poi.poifs.filesystem.EntryNode entry)remove an entry
_property_table.removeProperty(entry.getProperty());
if (entry.isDocumentEntry())
{
_documents.remove((( DocumentNode ) entry).getDocument());
}
|
public void | writeFilesystem(java.io.OutputStream stream)Write the filesystem out
// get the property table ready
_property_table.preWrite();
// create the small block store, and the SBAT
SmallBlockTableWriter sbtw =
new SmallBlockTableWriter(_documents, _property_table.getRoot());
// create the block allocation table
BlockAllocationTableWriter bat =
new BlockAllocationTableWriter();
// create a list of BATManaged objects: the documents plus the
// property table and the small block table
List bm_objects = new ArrayList();
bm_objects.addAll(_documents);
bm_objects.add(_property_table);
bm_objects.add(sbtw);
bm_objects.add(sbtw.getSBAT());
// walk the list, allocating space for each and assigning each
// a starting block number
Iterator iter = bm_objects.iterator();
while (iter.hasNext())
{
BATManaged bmo = ( BATManaged ) iter.next();
int block_count = bmo.countBlocks();
if (block_count != 0)
{
bmo.setStartBlock(bat.allocateSpace(block_count));
}
else
{
// Either the BATManaged object is empty or its data
// is composed of SmallBlocks; in either case,
// allocating space in the BAT is inappropriate
}
}
// allocate space for the block allocation table and take its
// starting block
int batStartBlock = bat.createBlocks();
// get the extended block allocation table blocks
HeaderBlockWriter header_block_writer = new HeaderBlockWriter();
BATBlock[] xbat_blocks =
header_block_writer.setBATBlocks(bat.countBlocks(),
batStartBlock);
// set the property table start block
header_block_writer.setPropertyStart(_property_table.getStartBlock());
// set the small block allocation table start block
header_block_writer.setSBATStart(sbtw.getSBAT().getStartBlock());
// set the small block allocation table block count
header_block_writer.setSBATBlockCount(sbtw.getSBATBlockCount());
// the header is now properly initialized. Make a list of
// writers (the header block, followed by the documents, the
// property table, the small block store, the small block
// allocation table, the block allocation table, and the
// extended block allocation table blocks)
List writers = new ArrayList();
writers.add(header_block_writer);
writers.addAll(_documents);
writers.add(_property_table);
writers.add(sbtw);
writers.add(sbtw.getSBAT());
writers.add(bat);
for (int j = 0; j < xbat_blocks.length; j++)
{
writers.add(xbat_blocks[ j ]);
}
// now, write everything out
iter = writers.iterator();
while (iter.hasNext())
{
BlockWritable writer = ( BlockWritable ) iter.next();
writer.writeBlocks(stream);
}
|