Add a NPOIFS aware createDocumentInputStream method to DirectoryNode, and use it in POIDocument. Also fix indent in the latter

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1053522 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2010-12-29 03:30:07 +00:00
parent f2b541e026
commit 7fe097413c
2 changed files with 60 additions and 28 deletions

View File

@ -20,6 +20,7 @@ package org.apache.poi;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.List;
@ -143,10 +144,10 @@ public abstract class POIDocument {
//directory can be null when creating new documents
if(directory == null) return null;
DocumentInputStream dis;
InputStream dis;
try {
// Find the entry, and get an input stream for it
dis = directory.createDocumentInputStream(setName);
dis = directory.createDocumentInputStream( directory.getEntry(setName) );
} catch(IOException ie) {
// Oh well, doesn't exist
logger.log(POILogger.WARN, "Error getting property set with name " + setName + "\n" + ie);

View File

@ -19,9 +19,14 @@
package org.apache.poi.poifs.filesystem;
import java.io.*;
import java.util.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.poi.hpsf.ClassID;
import org.apache.poi.poifs.dev.POIFSViewable;
@ -162,7 +167,6 @@ public class DirectoryNode
* @exception IOException if the document does not exist or the
* name is that of a DirectoryEntry
*/
public DocumentInputStream createDocumentInputStream(
final String documentName)
throws IOException
@ -177,6 +181,33 @@ public class DirectoryNode
return new DocumentInputStream(( DocumentEntry ) document);
}
/**
* open a document in the directory's entry's list of entries
*
* @param documentEntry the document to be opened
*
* @return a newly opened DocumentInputStream or NDocumentInputStream
*
* @exception IOException if the document does not exist or the
* name is that of a DirectoryEntry
*/
public InputStream createDocumentInputStream(
final Entry document)
throws IOException
{
if (!document.isDocumentEntry()) {
throw new IOException("Entry '" + document.getName()
+ "' is not a DocumentEntry");
}
DocumentEntry entry = (DocumentEntry)document;
if(_ofilesystem != null) {
return new DocumentInputStream(entry);
} else {
return new NDocumentInputStream(entry);
}
}
/**
* create a new DocumentEntry
*