mirror of https://github.com/apache/poi.git
#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:
parent
32579cda68
commit
1c4d0baeca
|
@ -24,7 +24,7 @@ import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.apache.poi.poifs.filesystem.DocumentInputStream;
|
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.filesystem.POIFSDocumentPath;
|
||||||
import org.apache.poi.poifs.property.DirectoryProperty;
|
import org.apache.poi.poifs.property.DirectoryProperty;
|
||||||
import org.apache.poi.poifs.property.Property;
|
import org.apache.poi.poifs.property.Property;
|
||||||
|
@ -240,19 +240,19 @@ public class POIFSReader
|
||||||
|
|
||||||
if (listeners.hasNext())
|
if (listeners.hasNext())
|
||||||
{
|
{
|
||||||
int size = property.getSize();
|
int size = property.getSize();
|
||||||
POIFSDocument document = null;
|
OPOIFSDocument document = null;
|
||||||
|
|
||||||
if (property.shouldUseSmallBlocks())
|
if (property.shouldUseSmallBlocks())
|
||||||
{
|
{
|
||||||
document =
|
document =
|
||||||
new POIFSDocument(name, small_blocks
|
new OPOIFSDocument(name, small_blocks
|
||||||
.fetchBlocks(startBlock, -1), size);
|
.fetchBlocks(startBlock, -1), size);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
document =
|
document =
|
||||||
new POIFSDocument(name, big_blocks
|
new OPOIFSDocument(name, big_blocks
|
||||||
.fetchBlocks(startBlock, -1), size);
|
.fetchBlocks(startBlock, -1), size);
|
||||||
}
|
}
|
||||||
while (listeners.hasNext())
|
while (listeners.hasNext())
|
||||||
|
|
|
@ -217,7 +217,7 @@ public class DirectoryNode
|
||||||
*
|
*
|
||||||
* @exception IOException
|
* @exception IOException
|
||||||
*/
|
*/
|
||||||
DocumentEntry createDocument(final POIFSDocument document)
|
DocumentEntry createDocument(final OPOIFSDocument document)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
DocumentProperty property = document.getDocumentProperty();
|
DocumentProperty property = document.getDocumentProperty();
|
||||||
|
@ -418,7 +418,7 @@ public class DirectoryNode
|
||||||
if(_nfilesystem != null) {
|
if(_nfilesystem != null) {
|
||||||
return createDocument(new NPOIFSDocument(name, _nfilesystem, stream));
|
return createDocument(new NPOIFSDocument(name, _nfilesystem, stream));
|
||||||
} else {
|
} else {
|
||||||
return createDocument(new POIFSDocument(name, stream));
|
return createDocument(new OPOIFSDocument(name, stream));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -441,7 +441,7 @@ public class DirectoryNode
|
||||||
if(_nfilesystem != null) {
|
if(_nfilesystem != null) {
|
||||||
return createDocument(new NPOIFSDocument(name, size, _nfilesystem, writer));
|
return createDocument(new NPOIFSDocument(name, size, _nfilesystem, writer));
|
||||||
} else {
|
} else {
|
||||||
return createDocument(new POIFSDocument(name, size, _path, writer));
|
return createDocument(new OPOIFSDocument(name, size, _path, writer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class DocumentInputStream extends InputStream implements LittleEndianInpu
|
||||||
*
|
*
|
||||||
* @param document the Document to be read
|
* @param document the Document to be read
|
||||||
*/
|
*/
|
||||||
public DocumentInputStream(POIFSDocument document) {
|
public DocumentInputStream(OPOIFSDocument document) {
|
||||||
delegate = new ODocumentInputStream(document);
|
delegate = new ODocumentInputStream(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,18 +27,15 @@ import org.apache.poi.poifs.dev.POIFSViewable;
|
||||||
import org.apache.poi.poifs.property.DocumentProperty;
|
import org.apache.poi.poifs.property.DocumentProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple implementation of DocumentEntry
|
* Simple implementation of DocumentEntry for OPOIFS
|
||||||
*
|
|
||||||
* @author Marc Johnson (mjohnson at apache dot org)
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class DocumentNode
|
public class DocumentNode
|
||||||
extends EntryNode
|
extends EntryNode
|
||||||
implements DocumentEntry, POIFSViewable
|
implements DocumentEntry, POIFSViewable
|
||||||
{
|
{
|
||||||
|
|
||||||
// underlying POIFSDocument instance
|
// underlying POIFSDocument instance
|
||||||
private POIFSDocument _document;
|
private OPOIFSDocument _document;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create a DocumentNode. This method is not public by design; it
|
* create a DocumentNode. This method is not public by design; it
|
||||||
|
@ -59,8 +56,7 @@ public class DocumentNode
|
||||||
*
|
*
|
||||||
* @return the internal POIFSDocument
|
* @return the internal POIFSDocument
|
||||||
*/
|
*/
|
||||||
|
OPOIFSDocument getDocument()
|
||||||
POIFSDocument getDocument()
|
|
||||||
{
|
{
|
||||||
return _document;
|
return _document;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,7 @@ import org.apache.poi.poifs.storage.DataInputBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides methods to read a DocumentEntry managed by a
|
* This class provides methods to read a DocumentEntry managed by a
|
||||||
* {@link POIFSFileSystem} instance.
|
* {@link OPOIFSFileSystem} instance.
|
||||||
*
|
|
||||||
* @author Marc Johnson (mjohnson at apache dot org)
|
|
||||||
*/
|
*/
|
||||||
public final class ODocumentInputStream extends DocumentInputStream {
|
public final class ODocumentInputStream extends DocumentInputStream {
|
||||||
/** current offset into the Document */
|
/** current offset into the Document */
|
||||||
|
@ -41,7 +39,7 @@ public final class ODocumentInputStream extends DocumentInputStream {
|
||||||
private boolean _closed;
|
private boolean _closed;
|
||||||
|
|
||||||
/** the actual Document */
|
/** the actual Document */
|
||||||
private POIFSDocument _document;
|
private OPOIFSDocument _document;
|
||||||
|
|
||||||
/** the data block containing the current stream pointer */
|
/** the data block containing the current stream pointer */
|
||||||
private DataInputBlock _currentBlock;
|
private DataInputBlock _currentBlock;
|
||||||
|
@ -59,7 +57,7 @@ public final class ODocumentInputStream extends DocumentInputStream {
|
||||||
throw new IOException("Cannot open internal document storage");
|
throw new IOException("Cannot open internal document storage");
|
||||||
}
|
}
|
||||||
DocumentNode documentNode = (DocumentNode)document;
|
DocumentNode documentNode = (DocumentNode)document;
|
||||||
if(documentNode.getDocument() == null) {
|
if (documentNode.getDocument() == null) {
|
||||||
throw new IOException("Cannot open internal document storage");
|
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
|
* @param document the Document to be read
|
||||||
*/
|
*/
|
||||||
public ODocumentInputStream(POIFSDocument document) {
|
public ODocumentInputStream(OPOIFSDocument document) {
|
||||||
_current_offset = 0;
|
_current_offset = 0;
|
||||||
_marked_offset = 0;
|
_marked_offset = 0;
|
||||||
_document_size = document.getSize();
|
_document_size = document.getSize();
|
||||||
|
|
|
@ -40,11 +40,10 @@ import org.apache.poi.poifs.storage.SmallDocumentBlock;
|
||||||
import org.apache.poi.util.HexDump;
|
import org.apache.poi.util.HexDump;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class manages a document in the POIFS filesystem.
|
* This class manages a document in a old-style
|
||||||
*
|
* OPOIFS filesystem.
|
||||||
* @author Marc Johnson (mjohnson at apache dot org)
|
|
||||||
*/
|
*/
|
||||||
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 DocumentBlock[] EMPTY_BIG_BLOCK_ARRAY = { };
|
||||||
private static final SmallDocumentBlock[] EMPTY_SMALL_BLOCK_ARRAY = { };
|
private static final SmallDocumentBlock[] EMPTY_SMALL_BLOCK_ARRAY = { };
|
||||||
private DocumentProperty _property;
|
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 blocks the big blocks making up the POIFSDocument
|
||||||
* @param length the actual length of 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;
|
_size = length;
|
||||||
if(blocks.length == 0) {
|
if(blocks.length == 0) {
|
||||||
_bigBigBlockSize = POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS;
|
_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 blocks the small blocks making up the POIFSDocument
|
||||||
* @param length the actual length of 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;
|
_size = length;
|
||||||
|
|
||||||
if(blocks.length == 0) {
|
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 blocks the small blocks making up the POIFSDocument
|
||||||
* @param length the actual length of 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;
|
_size = length;
|
||||||
_bigBigBlockSize = bigBlockSize;
|
_bigBigBlockSize = bigBlockSize;
|
||||||
_property = new DocumentProperty(name, _size);
|
_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);
|
_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);
|
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 name the name of the POIFSDocument
|
||||||
* @param stream the InputStream we read data from
|
* @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>();
|
List<DocumentBlock> blocks = new ArrayList<DocumentBlock>();
|
||||||
|
|
||||||
_size = 0;
|
_size = 0;
|
||||||
|
@ -178,7 +177,7 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
|
||||||
_small_store = new SmallBlockStore(bigBlockSize,EMPTY_SMALL_BLOCK_ARRAY);
|
_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);
|
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 path the path of the POIFSDocument
|
||||||
* @param writer the writer who will eventually write the document contents
|
* @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;
|
_size = size;
|
||||||
_bigBigBlockSize = bigBlockSize;
|
_bigBigBlockSize = bigBlockSize;
|
||||||
_property = new DocumentProperty(name, _size);
|
_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);
|
_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);
|
this(name, size, POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, path, writer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -445,7 +445,7 @@ public class OPOIFSFileSystem
|
||||||
* @param document the POIFSDocument being added
|
* @param document the POIFSDocument being added
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void addDocument(final POIFSDocument document)
|
void addDocument(final OPOIFSDocument document)
|
||||||
{
|
{
|
||||||
_documents.add(document);
|
_documents.add(document);
|
||||||
_property_table.addProperty(document.getDocumentProperty());
|
_property_table.addProperty(document.getDocumentProperty());
|
||||||
|
@ -508,21 +508,21 @@ public class OPOIFSFileSystem
|
||||||
{
|
{
|
||||||
int startBlock = property.getStartBlock();
|
int startBlock = property.getStartBlock();
|
||||||
int size = property.getSize();
|
int size = property.getSize();
|
||||||
POIFSDocument document = null;
|
OPOIFSDocument document = null;
|
||||||
|
|
||||||
if (property.shouldUseSmallBlocks())
|
if (property.shouldUseSmallBlocks())
|
||||||
{
|
{
|
||||||
document =
|
document =
|
||||||
new POIFSDocument(name,
|
new OPOIFSDocument(name,
|
||||||
small_blocks.fetchBlocks(startBlock, headerPropertiesStartAt),
|
small_blocks.fetchBlocks(startBlock, headerPropertiesStartAt),
|
||||||
size);
|
size);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
document =
|
document =
|
||||||
new POIFSDocument(name,
|
new OPOIFSDocument(name,
|
||||||
big_blocks.fetchBlocks(startBlock, headerPropertiesStartAt),
|
big_blocks.fetchBlocks(startBlock, headerPropertiesStartAt),
|
||||||
size);
|
size);
|
||||||
}
|
}
|
||||||
parent.createDocument(document);
|
parent.createDocument(document);
|
||||||
}
|
}
|
||||||
|
|
|
@ -447,7 +447,7 @@ public class POIFSFileSystem
|
||||||
* @param document the POIFSDocument being added
|
* @param document the POIFSDocument being added
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void addDocument(final POIFSDocument document)
|
void addDocument(final OPOIFSDocument document)
|
||||||
{
|
{
|
||||||
_documents.add(document);
|
_documents.add(document);
|
||||||
_property_table.addProperty(document.getDocumentProperty());
|
_property_table.addProperty(document.getDocumentProperty());
|
||||||
|
@ -510,21 +510,21 @@ public class POIFSFileSystem
|
||||||
{
|
{
|
||||||
int startBlock = property.getStartBlock();
|
int startBlock = property.getStartBlock();
|
||||||
int size = property.getSize();
|
int size = property.getSize();
|
||||||
POIFSDocument document = null;
|
OPOIFSDocument document = null;
|
||||||
|
|
||||||
if (property.shouldUseSmallBlocks())
|
if (property.shouldUseSmallBlocks())
|
||||||
{
|
{
|
||||||
document =
|
document =
|
||||||
new POIFSDocument(name,
|
new OPOIFSDocument(name,
|
||||||
small_blocks.fetchBlocks(startBlock, headerPropertiesStartAt),
|
small_blocks.fetchBlocks(startBlock, headerPropertiesStartAt),
|
||||||
size);
|
size);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
document =
|
document =
|
||||||
new POIFSDocument(name,
|
new OPOIFSDocument(name,
|
||||||
big_blocks.fetchBlocks(startBlock, headerPropertiesStartAt),
|
big_blocks.fetchBlocks(startBlock, headerPropertiesStartAt),
|
||||||
size);
|
size);
|
||||||
}
|
}
|
||||||
parent.createDocument(document);
|
parent.createDocument(document);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,10 @@
|
||||||
|
|
||||||
package org.apache.poi.poifs.property;
|
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
|
* Trivial extension of Property for POIFSDocuments
|
||||||
*
|
|
||||||
* @author Marc Johnson (mjohnson at apache dot org)
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class DocumentProperty
|
public class DocumentProperty
|
||||||
|
@ -32,7 +30,7 @@ public class DocumentProperty
|
||||||
{
|
{
|
||||||
|
|
||||||
// the POIFSDocument this property is associated with
|
// the POIFSDocument this property is associated with
|
||||||
private POIFSDocument _document;
|
private OPOIFSDocument _document;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
@ -72,7 +70,7 @@ public class DocumentProperty
|
||||||
* @param doc the associated POIFSDocument
|
* @param doc the associated POIFSDocument
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void setDocument(POIFSDocument doc)
|
public void setDocument(OPOIFSDocument doc)
|
||||||
{
|
{
|
||||||
_document = doc;
|
_document = doc;
|
||||||
}
|
}
|
||||||
|
@ -83,7 +81,7 @@ public class DocumentProperty
|
||||||
* @return the associated document
|
* @return the associated document
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public POIFSDocument getDocument()
|
public OPOIFSDocument getDocument()
|
||||||
{
|
{
|
||||||
return _document;
|
return _document;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ package org.apache.poi.poifs.storage;
|
||||||
import org.apache.poi.poifs.common.POIFSBigBlockSize;
|
import org.apache.poi.poifs.common.POIFSBigBlockSize;
|
||||||
import org.apache.poi.poifs.common.POIFSConstants;
|
import org.apache.poi.poifs.common.POIFSConstants;
|
||||||
import org.apache.poi.poifs.filesystem.BATManaged;
|
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 org.apache.poi.poifs.property.RootProperty;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -62,7 +62,7 @@ public class SmallBlockTableWriter
|
||||||
|
|
||||||
while (iter.hasNext())
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
POIFSDocument doc = ( POIFSDocument ) iter.next();
|
OPOIFSDocument doc = ( OPOIFSDocument ) iter.next();
|
||||||
BlockWritable[] blocks = doc.getSmallBlocks();
|
BlockWritable[] blocks = doc.getSmallBlocks();
|
||||||
|
|
||||||
if (blocks.length != 0)
|
if (blocks.length != 0)
|
||||||
|
|
|
@ -32,7 +32,6 @@ import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
|
@ -28,27 +28,25 @@ import org.apache.poi.poifs.storage.RawDataBlock;
|
||||||
import org.apache.poi.poifs.storage.SmallDocumentBlock;
|
import org.apache.poi.poifs.storage.SmallDocumentBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to test POIFSDocument functionality
|
* Class to test OPOIFSDocument functionality
|
||||||
*
|
|
||||||
* @author Marc Johnson
|
|
||||||
*/
|
*/
|
||||||
public final class TestDocument extends TestCase {
|
public final class TestDocument extends TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration test -- really about all we can do
|
* 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
|
// verify correct number of blocks get created for document
|
||||||
// that is exact multituple of block size
|
// that is exact multituple of block size
|
||||||
POIFSDocument document;
|
OPOIFSDocument document;
|
||||||
byte[] array = new byte[ 4096 ];
|
byte[] array = new byte[ 4096 ];
|
||||||
|
|
||||||
for (int j = 0; j < array.length; j++)
|
for (int j = 0; j < array.length; j++)
|
||||||
{
|
{
|
||||||
array[ j ] = ( byte ) 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);
|
checkDocument(document, array);
|
||||||
|
|
||||||
// verify correct number of blocks get created for document
|
// verify correct number of blocks get created for document
|
||||||
|
@ -58,7 +56,7 @@ public final class TestDocument extends TestCase {
|
||||||
{
|
{
|
||||||
array[ j ] = ( byte ) j;
|
array[ j ] = ( byte ) j;
|
||||||
}
|
}
|
||||||
document = new POIFSDocument("bar", new ByteArrayInputStream(array));
|
document = new OPOIFSDocument("bar", new ByteArrayInputStream(array));
|
||||||
checkDocument(document, array);
|
checkDocument(document, array);
|
||||||
|
|
||||||
// verify correct number of blocks get created for document
|
// verify correct number of blocks get created for document
|
||||||
|
@ -68,7 +66,7 @@ public final class TestDocument extends TestCase {
|
||||||
{
|
{
|
||||||
array[ j ] = ( byte ) j;
|
array[ j ] = ( byte ) j;
|
||||||
}
|
}
|
||||||
document = new POIFSDocument("_bar", new ByteArrayInputStream(array));
|
document = new OPOIFSDocument("_bar", new ByteArrayInputStream(array));
|
||||||
checkDocument(document, array);
|
checkDocument(document, array);
|
||||||
|
|
||||||
// verify correct number of blocks get created for document
|
// verify correct number of blocks get created for document
|
||||||
|
@ -78,7 +76,7 @@ public final class TestDocument extends TestCase {
|
||||||
{
|
{
|
||||||
array[ j ] = ( byte ) j;
|
array[ j ] = ( byte ) j;
|
||||||
}
|
}
|
||||||
document = new POIFSDocument("_bar2",
|
document = new OPOIFSDocument("_bar2",
|
||||||
new ByteArrayInputStream(array));
|
new ByteArrayInputStream(array));
|
||||||
checkDocument(document, array);
|
checkDocument(document, array);
|
||||||
|
|
||||||
|
@ -88,7 +86,7 @@ public final class TestDocument extends TestCase {
|
||||||
{
|
{
|
||||||
array[ j ] = ( byte ) j;
|
array[ j ] = ( byte ) j;
|
||||||
}
|
}
|
||||||
document = new POIFSDocument("foobar",
|
document = new OPOIFSDocument("foobar",
|
||||||
new ByteArrayInputStream(array));
|
new ByteArrayInputStream(array));
|
||||||
checkDocument(document, array);
|
checkDocument(document, array);
|
||||||
document.setStartBlock(0x12345678); // what a big file!!
|
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 {
|
throws IOException {
|
||||||
POIFSDocument copy = null;
|
OPOIFSDocument copy = null;
|
||||||
|
|
||||||
if (input.length >= 4096)
|
if (input.length >= 4096)
|
||||||
{
|
{
|
||||||
|
@ -156,12 +154,12 @@ public final class TestDocument extends TestCase {
|
||||||
}
|
}
|
||||||
blocks[ index++ ] = block;
|
blocks[ index++ ] = block;
|
||||||
}
|
}
|
||||||
copy = new POIFSDocument("test" + input.length, blocks,
|
copy = new OPOIFSDocument("test" + input.length, blocks,
|
||||||
input.length);
|
input.length);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
copy = new POIFSDocument(
|
copy = new OPOIFSDocument(
|
||||||
"test" + input.length,
|
"test" + input.length,
|
||||||
( SmallDocumentBlock [] ) document.getSmallBlocks(),
|
( SmallDocumentBlock [] ) document.getSmallBlocks(),
|
||||||
input.length);
|
input.length);
|
||||||
|
@ -169,7 +167,7 @@ public final class TestDocument extends TestCase {
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkDocument(final POIFSDocument document, final byte[] input)
|
private static void checkDocument(final OPOIFSDocument document, final byte[] input)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
int big_blocks = 0;
|
int big_blocks = 0;
|
||||||
int small_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,
|
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());
|
assertEquals(document, document.getDocumentProperty().getDocument());
|
||||||
int increment = ( int ) Math.sqrt(input.length);
|
int increment = ( int ) Math.sqrt(input.length);
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,8 @@ public final class TestDocumentInputStream extends TestCase {
|
||||||
{
|
{
|
||||||
rawBlocks[ j ] = new RawDataBlock(stream);
|
rawBlocks[ j ] = new RawDataBlock(stream);
|
||||||
}
|
}
|
||||||
POIFSDocument document = new POIFSDocument("Workbook", rawBlocks,
|
OPOIFSDocument document = new OPOIFSDocument("Workbook", rawBlocks,
|
||||||
_workbook_size);
|
_workbook_size);
|
||||||
|
|
||||||
_workbook_o = new DocumentNode(
|
_workbook_o = new DocumentNode(
|
||||||
document.getDocumentProperty(),
|
document.getDocumentProperty(),
|
||||||
|
|
|
@ -46,7 +46,7 @@ public final class TestDocumentNode extends TestCase {
|
||||||
{
|
{
|
||||||
rawBlocks[ j ] = new RawDataBlock(stream);
|
rawBlocks[ j ] = new RawDataBlock(stream);
|
||||||
}
|
}
|
||||||
POIFSDocument document = new POIFSDocument("document", rawBlocks,
|
OPOIFSDocument document = new OPOIFSDocument("document", rawBlocks,
|
||||||
2000);
|
2000);
|
||||||
DocumentProperty property2 = document.getDocumentProperty();
|
DocumentProperty property2 = document.getDocumentProperty();
|
||||||
DirectoryNode parent = new DirectoryNode(property1, (POIFSFileSystem)null, null);
|
DirectoryNode parent = new DirectoryNode(property1, (POIFSFileSystem)null, null);
|
||||||
|
|
|
@ -25,7 +25,7 @@ import java.util.List;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.poifs.common.POIFSConstants;
|
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.PropertyTable;
|
||||||
import org.apache.poi.poifs.property.RootProperty;
|
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 final class TestSmallBlockTableWriter extends TestCase {
|
||||||
|
|
||||||
public void testWritingConstructor() throws IOException {
|
public void testWritingConstructor() throws IOException {
|
||||||
List<POIFSDocument> documents = new ArrayList<POIFSDocument>();
|
List<OPOIFSDocument> documents = new ArrayList<OPOIFSDocument>();
|
||||||
|
|
||||||
documents.add(
|
documents.add(
|
||||||
new POIFSDocument(
|
new OPOIFSDocument(
|
||||||
"doc340", new ByteArrayInputStream(new byte[ 340 ])));
|
"doc340", new ByteArrayInputStream(new byte[ 340 ])));
|
||||||
documents.add(
|
documents.add(
|
||||||
new POIFSDocument(
|
new OPOIFSDocument(
|
||||||
"doc5000", new ByteArrayInputStream(new byte[ 5000 ])));
|
"doc5000", new ByteArrayInputStream(new byte[ 5000 ])));
|
||||||
documents
|
documents
|
||||||
.add(new POIFSDocument("doc0",
|
.add(new OPOIFSDocument("doc0",
|
||||||
new ByteArrayInputStream(new byte[ 0 ])));
|
new ByteArrayInputStream(new byte[ 0 ])));
|
||||||
documents
|
documents
|
||||||
.add(new POIFSDocument("doc1",
|
.add(new OPOIFSDocument("doc1",
|
||||||
new ByteArrayInputStream(new byte[ 1 ])));
|
new ByteArrayInputStream(new byte[ 1 ])));
|
||||||
documents
|
documents
|
||||||
.add(new POIFSDocument("doc2",
|
.add(new OPOIFSDocument("doc2",
|
||||||
new ByteArrayInputStream(new byte[ 2 ])));
|
new ByteArrayInputStream(new byte[ 2 ])));
|
||||||
documents
|
documents
|
||||||
.add(new POIFSDocument("doc3",
|
.add(new OPOIFSDocument("doc3",
|
||||||
new ByteArrayInputStream(new byte[ 3 ])));
|
new ByteArrayInputStream(new byte[ 3 ])));
|
||||||
documents
|
documents
|
||||||
.add(new POIFSDocument("doc4",
|
.add(new OPOIFSDocument("doc4",
|
||||||
new ByteArrayInputStream(new byte[ 4 ])));
|
new ByteArrayInputStream(new byte[ 4 ])));
|
||||||
documents
|
documents
|
||||||
.add(new POIFSDocument("doc5",
|
.add(new OPOIFSDocument("doc5",
|
||||||
new ByteArrayInputStream(new byte[ 5 ])));
|
new ByteArrayInputStream(new byte[ 5 ])));
|
||||||
documents
|
documents
|
||||||
.add(new POIFSDocument("doc6",
|
.add(new OPOIFSDocument("doc6",
|
||||||
new ByteArrayInputStream(new byte[ 6 ])));
|
new ByteArrayInputStream(new byte[ 6 ])));
|
||||||
documents
|
documents
|
||||||
.add(new POIFSDocument("doc7",
|
.add(new OPOIFSDocument("doc7",
|
||||||
new ByteArrayInputStream(new byte[ 7 ])));
|
new ByteArrayInputStream(new byte[ 7 ])));
|
||||||
documents
|
documents
|
||||||
.add(new POIFSDocument("doc8",
|
.add(new OPOIFSDocument("doc8",
|
||||||
new ByteArrayInputStream(new byte[ 8 ])));
|
new ByteArrayInputStream(new byte[ 8 ])));
|
||||||
documents
|
documents
|
||||||
.add(new POIFSDocument("doc9",
|
.add(new OPOIFSDocument("doc9",
|
||||||
new ByteArrayInputStream(new byte[ 9 ])));
|
new ByteArrayInputStream(new byte[ 9 ])));
|
||||||
|
|
||||||
HeaderBlock header = new HeaderBlock(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
|
HeaderBlock header = new HeaderBlock(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
|
||||||
|
|
Loading…
Reference in New Issue