#56791 More updates from OPOIFS to NPOIFS

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1678787 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2015-05-11 18:15:03 +00:00
parent 32579cda68
commit 1c4d0baeca
15 changed files with 80 additions and 92 deletions

View File

@ -24,7 +24,7 @@ import java.io.*;
import java.util.*;
import org.apache.poi.poifs.filesystem.DocumentInputStream;
import org.apache.poi.poifs.filesystem.POIFSDocument;
import org.apache.poi.poifs.filesystem.OPOIFSDocument;
import org.apache.poi.poifs.filesystem.POIFSDocumentPath;
import org.apache.poi.poifs.property.DirectoryProperty;
import org.apache.poi.poifs.property.Property;
@ -241,18 +241,18 @@ public class POIFSReader
if (listeners.hasNext())
{
int size = property.getSize();
POIFSDocument document = null;
OPOIFSDocument document = null;
if (property.shouldUseSmallBlocks())
{
document =
new POIFSDocument(name, small_blocks
new OPOIFSDocument(name, small_blocks
.fetchBlocks(startBlock, -1), size);
}
else
{
document =
new POIFSDocument(name, big_blocks
new OPOIFSDocument(name, big_blocks
.fetchBlocks(startBlock, -1), size);
}
while (listeners.hasNext())

View File

@ -217,7 +217,7 @@ public class DirectoryNode
*
* @exception IOException
*/
DocumentEntry createDocument(final POIFSDocument document)
DocumentEntry createDocument(final OPOIFSDocument document)
throws IOException
{
DocumentProperty property = document.getDocumentProperty();
@ -418,7 +418,7 @@ public class DirectoryNode
if(_nfilesystem != null) {
return createDocument(new NPOIFSDocument(name, _nfilesystem, stream));
} else {
return createDocument(new POIFSDocument(name, stream));
return createDocument(new OPOIFSDocument(name, stream));
}
}
@ -441,7 +441,7 @@ public class DirectoryNode
if(_nfilesystem != null) {
return createDocument(new NPOIFSDocument(name, size, _nfilesystem, writer));
} else {
return createDocument(new POIFSDocument(name, size, _path, writer));
return createDocument(new OPOIFSDocument(name, size, _path, writer));
}
}

View File

@ -72,7 +72,7 @@ public class DocumentInputStream extends InputStream implements LittleEndianInpu
*
* @param document the Document to be read
*/
public DocumentInputStream(POIFSDocument document) {
public DocumentInputStream(OPOIFSDocument document) {
delegate = new ODocumentInputStream(document);
}

View File

@ -27,18 +27,15 @@ import org.apache.poi.poifs.dev.POIFSViewable;
import org.apache.poi.poifs.property.DocumentProperty;
/**
* Simple implementation of DocumentEntry
*
* @author Marc Johnson (mjohnson at apache dot org)
* Simple implementation of DocumentEntry for OPOIFS
*/
public class DocumentNode
extends EntryNode
implements DocumentEntry, POIFSViewable
{
// underlying POIFSDocument instance
private POIFSDocument _document;
private OPOIFSDocument _document;
/**
* create a DocumentNode. This method is not public by design; it
@ -59,8 +56,7 @@ public class DocumentNode
*
* @return the internal POIFSDocument
*/
POIFSDocument getDocument()
OPOIFSDocument getDocument()
{
return _document;
}

View File

@ -23,9 +23,7 @@ import org.apache.poi.poifs.storage.DataInputBlock;
/**
* This class provides methods to read a DocumentEntry managed by a
* {@link POIFSFileSystem} instance.
*
* @author Marc Johnson (mjohnson at apache dot org)
* {@link OPOIFSFileSystem} instance.
*/
public final class ODocumentInputStream extends DocumentInputStream {
/** current offset into the Document */
@ -41,7 +39,7 @@ public final class ODocumentInputStream extends DocumentInputStream {
private boolean _closed;
/** the actual Document */
private POIFSDocument _document;
private OPOIFSDocument _document;
/** the data block containing the current stream pointer */
private DataInputBlock _currentBlock;
@ -59,7 +57,7 @@ public final class ODocumentInputStream extends DocumentInputStream {
throw new IOException("Cannot open internal document storage");
}
DocumentNode documentNode = (DocumentNode)document;
if(documentNode.getDocument() == null) {
if (documentNode.getDocument() == null) {
throw new IOException("Cannot open internal document storage");
}
@ -76,7 +74,7 @@ public final class ODocumentInputStream extends DocumentInputStream {
*
* @param document the Document to be read
*/
public ODocumentInputStream(POIFSDocument document) {
public ODocumentInputStream(OPOIFSDocument document) {
_current_offset = 0;
_marked_offset = 0;
_document_size = document.getSize();

View File

@ -40,11 +40,10 @@ import org.apache.poi.poifs.storage.SmallDocumentBlock;
import org.apache.poi.util.HexDump;
/**
* This class manages a document in the POIFS filesystem.
*
* @author Marc Johnson (mjohnson at apache dot org)
* This class manages a document in a old-style
* OPOIFS filesystem.
*/
public final class POIFSDocument implements BATManaged, BlockWritable, POIFSViewable {
public final class OPOIFSDocument implements BATManaged, BlockWritable, POIFSViewable {
private static final DocumentBlock[] EMPTY_BIG_BLOCK_ARRAY = { };
private static final SmallDocumentBlock[] EMPTY_SMALL_BLOCK_ARRAY = { };
private DocumentProperty _property;
@ -63,7 +62,7 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
* @param blocks the big blocks making up the POIFSDocument
* @param length the actual length of the POIFSDocument
*/
public POIFSDocument(String name, RawDataBlock[] blocks, int length) throws IOException {
public OPOIFSDocument(String name, RawDataBlock[] blocks, int length) throws IOException {
_size = length;
if(blocks.length == 0) {
_bigBigBlockSize = POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS;
@ -104,7 +103,7 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
* @param blocks the small blocks making up the POIFSDocument
* @param length the actual length of the POIFSDocument
*/
public POIFSDocument(String name, SmallDocumentBlock[] blocks, int length) {
public OPOIFSDocument(String name, SmallDocumentBlock[] blocks, int length) {
_size = length;
if(blocks.length == 0) {
@ -126,7 +125,7 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
* @param blocks the small blocks making up the POIFSDocument
* @param length the actual length of the POIFSDocument
*/
public POIFSDocument(String name, POIFSBigBlockSize bigBlockSize, ListManagedBlock[] blocks, int length) throws IOException {
public OPOIFSDocument(String name, POIFSBigBlockSize bigBlockSize, ListManagedBlock[] blocks, int length) throws IOException {
_size = length;
_bigBigBlockSize = bigBlockSize;
_property = new DocumentProperty(name, _size);
@ -139,7 +138,7 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
_small_store = new SmallBlockStore(bigBlockSize,EMPTY_SMALL_BLOCK_ARRAY);
}
}
public POIFSDocument(String name, ListManagedBlock[] blocks, int length) throws IOException {
public OPOIFSDocument(String name, ListManagedBlock[] blocks, int length) throws IOException {
this(name, POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, blocks, length);
}
@ -149,7 +148,7 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
* @param name the name of the POIFSDocument
* @param stream the InputStream we read data from
*/
public POIFSDocument(String name, POIFSBigBlockSize bigBlockSize, InputStream stream) throws IOException {
public OPOIFSDocument(String name, POIFSBigBlockSize bigBlockSize, InputStream stream) throws IOException {
List<DocumentBlock> blocks = new ArrayList<DocumentBlock>();
_size = 0;
@ -178,7 +177,7 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
_small_store = new SmallBlockStore(bigBlockSize,EMPTY_SMALL_BLOCK_ARRAY);
}
}
public POIFSDocument(String name, InputStream stream) throws IOException {
public OPOIFSDocument(String name, InputStream stream) throws IOException {
this(name, POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, stream);
}
@ -190,7 +189,7 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
* @param path the path of the POIFSDocument
* @param writer the writer who will eventually write the document contents
*/
public POIFSDocument(String name, int size, POIFSBigBlockSize bigBlockSize, POIFSDocumentPath path, POIFSWriterListener writer) {
public OPOIFSDocument(String name, int size, POIFSBigBlockSize bigBlockSize, POIFSDocumentPath path, POIFSWriterListener writer) {
_size = size;
_bigBigBlockSize = bigBlockSize;
_property = new DocumentProperty(name, _size);
@ -203,7 +202,7 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
_big_store = new BigBlockStore(_bigBigBlockSize, path, name, size, writer);
}
}
public POIFSDocument(String name, int size, POIFSDocumentPath path, POIFSWriterListener writer) {
public OPOIFSDocument(String name, int size, POIFSDocumentPath path, POIFSWriterListener writer) {
this(name, size, POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, path, writer);
}

View File

@ -445,7 +445,7 @@ public class OPOIFSFileSystem
* @param document the POIFSDocument being added
*/
void addDocument(final POIFSDocument document)
void addDocument(final OPOIFSDocument document)
{
_documents.add(document);
_property_table.addProperty(document.getDocumentProperty());
@ -508,19 +508,19 @@ public class OPOIFSFileSystem
{
int startBlock = property.getStartBlock();
int size = property.getSize();
POIFSDocument document = null;
OPOIFSDocument document = null;
if (property.shouldUseSmallBlocks())
{
document =
new POIFSDocument(name,
new OPOIFSDocument(name,
small_blocks.fetchBlocks(startBlock, headerPropertiesStartAt),
size);
}
else
{
document =
new POIFSDocument(name,
new OPOIFSDocument(name,
big_blocks.fetchBlocks(startBlock, headerPropertiesStartAt),
size);
}

View File

@ -447,7 +447,7 @@ public class POIFSFileSystem
* @param document the POIFSDocument being added
*/
void addDocument(final POIFSDocument document)
void addDocument(final OPOIFSDocument document)
{
_documents.add(document);
_property_table.addProperty(document.getDocumentProperty());
@ -510,19 +510,19 @@ public class POIFSFileSystem
{
int startBlock = property.getStartBlock();
int size = property.getSize();
POIFSDocument document = null;
OPOIFSDocument document = null;
if (property.shouldUseSmallBlocks())
{
document =
new POIFSDocument(name,
new OPOIFSDocument(name,
small_blocks.fetchBlocks(startBlock, headerPropertiesStartAt),
size);
}
else
{
document =
new POIFSDocument(name,
new OPOIFSDocument(name,
big_blocks.fetchBlocks(startBlock, headerPropertiesStartAt),
size);
}

View File

@ -19,12 +19,10 @@
package org.apache.poi.poifs.property;
import org.apache.poi.poifs.filesystem.POIFSDocument;
import org.apache.poi.poifs.filesystem.OPOIFSDocument;
/**
* Trivial extension of Property for POIFSDocuments
*
* @author Marc Johnson (mjohnson at apache dot org)
*/
public class DocumentProperty
@ -32,7 +30,7 @@ public class DocumentProperty
{
// the POIFSDocument this property is associated with
private POIFSDocument _document;
private OPOIFSDocument _document;
/**
* Constructor
@ -72,7 +70,7 @@ public class DocumentProperty
* @param doc the associated POIFSDocument
*/
public void setDocument(POIFSDocument doc)
public void setDocument(OPOIFSDocument doc)
{
_document = doc;
}
@ -83,7 +81,7 @@ public class DocumentProperty
* @return the associated document
*/
public POIFSDocument getDocument()
public OPOIFSDocument getDocument()
{
return _document;
}

View File

@ -22,7 +22,7 @@ package org.apache.poi.poifs.storage;
import org.apache.poi.poifs.common.POIFSBigBlockSize;
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.poifs.filesystem.BATManaged;
import org.apache.poi.poifs.filesystem.POIFSDocument;
import org.apache.poi.poifs.filesystem.OPOIFSDocument;
import org.apache.poi.poifs.property.RootProperty;
import java.util.*;
@ -62,7 +62,7 @@ public class SmallBlockTableWriter
while (iter.hasNext())
{
POIFSDocument doc = ( POIFSDocument ) iter.next();
OPOIFSDocument doc = ( OPOIFSDocument ) iter.next();
BlockWritable[] blocks = doc.getSmallBlocks();
if (blocks.length != 0)

View File

@ -32,7 +32,6 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;

View File

@ -28,27 +28,25 @@ import org.apache.poi.poifs.storage.RawDataBlock;
import org.apache.poi.poifs.storage.SmallDocumentBlock;
/**
* Class to test POIFSDocument functionality
*
* @author Marc Johnson
* Class to test OPOIFSDocument functionality
*/
public final class TestDocument extends TestCase {
/**
* Integration test -- really about all we can do
*/
public void testPOIFSDocument() throws IOException {
public void testOPOIFSDocument() throws IOException {
// verify correct number of blocks get created for document
// that is exact multituple of block size
POIFSDocument document;
OPOIFSDocument document;
byte[] array = new byte[ 4096 ];
for (int j = 0; j < array.length; j++)
{
array[ j ] = ( byte ) j;
}
document = new POIFSDocument("foo", new SlowInputStream(new ByteArrayInputStream(array)));
document = new OPOIFSDocument("foo", new SlowInputStream(new ByteArrayInputStream(array)));
checkDocument(document, array);
// verify correct number of blocks get created for document
@ -58,7 +56,7 @@ public final class TestDocument extends TestCase {
{
array[ j ] = ( byte ) j;
}
document = new POIFSDocument("bar", new ByteArrayInputStream(array));
document = new OPOIFSDocument("bar", new ByteArrayInputStream(array));
checkDocument(document, array);
// verify correct number of blocks get created for document
@ -68,7 +66,7 @@ public final class TestDocument extends TestCase {
{
array[ j ] = ( byte ) j;
}
document = new POIFSDocument("_bar", new ByteArrayInputStream(array));
document = new OPOIFSDocument("_bar", new ByteArrayInputStream(array));
checkDocument(document, array);
// verify correct number of blocks get created for document
@ -78,7 +76,7 @@ public final class TestDocument extends TestCase {
{
array[ j ] = ( byte ) j;
}
document = new POIFSDocument("_bar2",
document = new OPOIFSDocument("_bar2",
new ByteArrayInputStream(array));
checkDocument(document, array);
@ -88,7 +86,7 @@ public final class TestDocument extends TestCase {
{
array[ j ] = ( byte ) j;
}
document = new POIFSDocument("foobar",
document = new OPOIFSDocument("foobar",
new ByteArrayInputStream(array));
checkDocument(document, array);
document.setStartBlock(0x12345678); // what a big file!!
@ -135,9 +133,9 @@ public final class TestDocument extends TestCase {
}
}
private static POIFSDocument makeCopy(POIFSDocument document, byte[] input, byte[] data)
private static OPOIFSDocument makeCopy(OPOIFSDocument document, byte[] input, byte[] data)
throws IOException {
POIFSDocument copy = null;
OPOIFSDocument copy = null;
if (input.length >= 4096)
{
@ -156,12 +154,12 @@ public final class TestDocument extends TestCase {
}
blocks[ index++ ] = block;
}
copy = new POIFSDocument("test" + input.length, blocks,
copy = new OPOIFSDocument("test" + input.length, blocks,
input.length);
}
else
{
copy = new POIFSDocument(
copy = new OPOIFSDocument(
"test" + input.length,
( SmallDocumentBlock [] ) document.getSmallBlocks(),
input.length);
@ -169,7 +167,7 @@ public final class TestDocument extends TestCase {
return copy;
}
private static void checkDocument(final POIFSDocument document, final byte[] input)
private static void checkDocument(final OPOIFSDocument document, final byte[] input)
throws IOException {
int big_blocks = 0;
int small_blocks = 0;
@ -195,7 +193,7 @@ public final class TestDocument extends TestCase {
}
private static byte[] checkValues(int big_blocks, int small_blocks, int total_output,
POIFSDocument document, byte[] input) throws IOException {
OPOIFSDocument document, byte[] input) throws IOException {
assertEquals(document, document.getDocumentProperty().getDocument());
int increment = ( int ) Math.sqrt(input.length);

View File

@ -64,7 +64,7 @@ public final class TestDocumentInputStream extends TestCase {
{
rawBlocks[ j ] = new RawDataBlock(stream);
}
POIFSDocument document = new POIFSDocument("Workbook", rawBlocks,
OPOIFSDocument document = new OPOIFSDocument("Workbook", rawBlocks,
_workbook_size);
_workbook_o = new DocumentNode(

View File

@ -46,7 +46,7 @@ public final class TestDocumentNode extends TestCase {
{
rawBlocks[ j ] = new RawDataBlock(stream);
}
POIFSDocument document = new POIFSDocument("document", rawBlocks,
OPOIFSDocument document = new OPOIFSDocument("document", rawBlocks,
2000);
DocumentProperty property2 = document.getDocumentProperty();
DirectoryNode parent = new DirectoryNode(property1, (POIFSFileSystem)null, null);

View File

@ -25,7 +25,7 @@ import java.util.List;
import junit.framework.TestCase;
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.poifs.filesystem.POIFSDocument;
import org.apache.poi.poifs.filesystem.OPOIFSDocument;
import org.apache.poi.poifs.property.PropertyTable;
import org.apache.poi.poifs.property.RootProperty;
@ -37,43 +37,43 @@ import org.apache.poi.poifs.property.RootProperty;
public final class TestSmallBlockTableWriter extends TestCase {
public void testWritingConstructor() throws IOException {
List<POIFSDocument> documents = new ArrayList<POIFSDocument>();
List<OPOIFSDocument> documents = new ArrayList<OPOIFSDocument>();
documents.add(
new POIFSDocument(
new OPOIFSDocument(
"doc340", new ByteArrayInputStream(new byte[ 340 ])));
documents.add(
new POIFSDocument(
new OPOIFSDocument(
"doc5000", new ByteArrayInputStream(new byte[ 5000 ])));
documents
.add(new POIFSDocument("doc0",
.add(new OPOIFSDocument("doc0",
new ByteArrayInputStream(new byte[ 0 ])));
documents
.add(new POIFSDocument("doc1",
.add(new OPOIFSDocument("doc1",
new ByteArrayInputStream(new byte[ 1 ])));
documents
.add(new POIFSDocument("doc2",
.add(new OPOIFSDocument("doc2",
new ByteArrayInputStream(new byte[ 2 ])));
documents
.add(new POIFSDocument("doc3",
.add(new OPOIFSDocument("doc3",
new ByteArrayInputStream(new byte[ 3 ])));
documents
.add(new POIFSDocument("doc4",
.add(new OPOIFSDocument("doc4",
new ByteArrayInputStream(new byte[ 4 ])));
documents
.add(new POIFSDocument("doc5",
.add(new OPOIFSDocument("doc5",
new ByteArrayInputStream(new byte[ 5 ])));
documents
.add(new POIFSDocument("doc6",
.add(new OPOIFSDocument("doc6",
new ByteArrayInputStream(new byte[ 6 ])));
documents
.add(new POIFSDocument("doc7",
.add(new OPOIFSDocument("doc7",
new ByteArrayInputStream(new byte[ 7 ])));
documents
.add(new POIFSDocument("doc8",
.add(new OPOIFSDocument("doc8",
new ByteArrayInputStream(new byte[ 8 ])));
documents
.add(new POIFSDocument("doc9",
.add(new OPOIFSDocument("doc9",
new ByteArrayInputStream(new byte[ 9 ])));
HeaderBlock header = new HeaderBlock(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);