diff --git a/src/java/org/apache/poi/poifs/filesystem/OPOIFSDocument.java b/src/java/org/apache/poi/poifs/filesystem/OPOIFSDocument.java index 3862b2987..05b21baea 100644 --- a/src/java/org/apache/poi/poifs/filesystem/OPOIFSDocument.java +++ b/src/java/org/apache/poi/poifs/filesystem/OPOIFSDocument.java @@ -209,7 +209,7 @@ public final class OPOIFSDocument implements BATManaged, BlockWritable, POIFSVie /** * @return array of SmallDocumentBlocks; may be empty, cannot be null */ - public BlockWritable[] getSmallBlocks() { + public SmallDocumentBlock[] getSmallBlocks() { return _small_store.getBlocks(); } diff --git a/src/java/org/apache/poi/poifs/filesystem/OPOIFSFileSystem.java b/src/java/org/apache/poi/poifs/filesystem/OPOIFSFileSystem.java index dcd1808a9..19abc48ab 100644 --- a/src/java/org/apache/poi/poifs/filesystem/OPOIFSFileSystem.java +++ b/src/java/org/apache/poi/poifs/filesystem/OPOIFSFileSystem.java @@ -73,7 +73,7 @@ public class OPOIFSFileSystem } private PropertyTable _property_table; - private List _documents; + private List _documents; private DirectoryNode _root; /** @@ -90,7 +90,7 @@ public class OPOIFSFileSystem { HeaderBlock header_block = new HeaderBlock(bigBlockSize); _property_table = new PropertyTable(header_block); - _documents = new ArrayList(); + _documents = new ArrayList(); _root = null; } diff --git a/src/java/org/apache/poi/poifs/storage/SmallBlockTableWriter.java b/src/java/org/apache/poi/poifs/storage/SmallBlockTableWriter.java index 783518f15..9c98bb459 100644 --- a/src/java/org/apache/poi/poifs/storage/SmallBlockTableWriter.java +++ b/src/java/org/apache/poi/poifs/storage/SmallBlockTableWriter.java @@ -40,7 +40,7 @@ public class SmallBlockTableWriter implements BlockWritable, BATManaged { private BlockAllocationTableWriter _sbat; - private List _small_blocks; + private List _small_blocks; private int _big_block_count; private RootProperty _root; @@ -50,20 +50,17 @@ public class SmallBlockTableWriter * @param documents a List of POIFSDocument instances * @param root the Filesystem's root property */ - public SmallBlockTableWriter(final POIFSBigBlockSize bigBlockSize, - final List documents, + final List documents, final RootProperty root) { _sbat = new BlockAllocationTableWriter(bigBlockSize); - _small_blocks = new ArrayList(); + _small_blocks = new ArrayList(); _root = root; - Iterator iter = documents.iterator(); - while (iter.hasNext()) + for (OPOIFSDocument doc : documents) { - OPOIFSDocument doc = ( OPOIFSDocument ) iter.next(); - BlockWritable[] blocks = doc.getSmallBlocks(); + SmallDocumentBlock[] blocks = doc.getSmallBlocks(); if (blocks.length != 0) { @@ -143,11 +140,8 @@ public class SmallBlockTableWriter public void writeBlocks(final OutputStream stream) throws IOException { - Iterator iter = _small_blocks.iterator(); - - while (iter.hasNext()) - { - (( BlockWritable ) iter.next()).writeBlocks(stream); + for (BlockWritable block : _small_blocks) { + block.writeBlocks(stream); } } diff --git a/src/java/org/apache/poi/poifs/storage/SmallDocumentBlock.java b/src/java/org/apache/poi/poifs/storage/SmallDocumentBlock.java index 8c726caa0..d09bf9ecf 100644 --- a/src/java/org/apache/poi/poifs/storage/SmallDocumentBlock.java +++ b/src/java/org/apache/poi/poifs/storage/SmallDocumentBlock.java @@ -29,8 +29,6 @@ import org.apache.poi.poifs.common.POIFSBigBlockSize; /** * Storage for documents that are too small to use regular * DocumentBlocks for their data - * - * @author Marc Johnson (mjohnson at apache dot org) */ public final class SmallDocumentBlock implements BlockWritable, ListManagedBlock { private static final int BLOCK_SHIFT = 6; @@ -49,7 +47,7 @@ public final class SmallDocumentBlock implements BlockWritable, ListManagedBlock System.arraycopy(data, index * _block_size, _data, 0, _block_size); } - private SmallDocumentBlock(final POIFSBigBlockSize bigBlockSize) + protected SmallDocumentBlock(final POIFSBigBlockSize bigBlockSize) { _bigBlockSize = bigBlockSize; _blocks_per_big_block = getBlocksPerBigBlock(bigBlockSize); @@ -110,7 +108,7 @@ public final class SmallDocumentBlock implements BlockWritable, ListManagedBlock * * @return number of big blocks the list encompasses */ - public static int fill(POIFSBigBlockSize bigBlockSize, List blocks) + public static int fill(POIFSBigBlockSize bigBlockSize, List blocks) { int _blocks_per_big_block = getBlocksPerBigBlock(bigBlockSize); @@ -168,12 +166,12 @@ public final class SmallDocumentBlock implements BlockWritable, ListManagedBlock * * @return a List of SmallDocumentBlock's extracted from the input */ - public static List extract(POIFSBigBlockSize bigBlockSize, ListManagedBlock [] blocks) + public static List extract(POIFSBigBlockSize bigBlockSize, ListManagedBlock [] blocks) throws IOException { int _blocks_per_big_block = getBlocksPerBigBlock(bigBlockSize); - List sdbs = new ArrayList(); + List sdbs = new ArrayList(); for (int j = 0; j < blocks.length; j++) { @@ -204,6 +202,11 @@ public final class SmallDocumentBlock implements BlockWritable, ListManagedBlock { return size * _block_size; } + + protected int getSmallBlocksPerBigBlock() + { + return _blocks_per_big_block; + } private static SmallDocumentBlock makeEmptySmallDocumentBlock(POIFSBigBlockSize bigBlockSize) { diff --git a/src/java/org/apache/poi/poifs/storage/SmallDocumentBlockList.java b/src/java/org/apache/poi/poifs/storage/SmallDocumentBlockList.java index a510f8e8f..cc6bb7c17 100644 --- a/src/java/org/apache/poi/poifs/storage/SmallDocumentBlockList.java +++ b/src/java/org/apache/poi/poifs/storage/SmallDocumentBlockList.java @@ -23,24 +23,19 @@ import java.util.*; /** * A list of SmallDocumentBlocks instances, and methods to manage the list - * - * @author Marc Johnson (mjohnson at apache dot org) */ - public class SmallDocumentBlockList extends BlockListImpl { - /** * Constructor SmallDocumentBlockList * * @param blocks a list of SmallDocumentBlock instances */ - public SmallDocumentBlockList(final List blocks) + public SmallDocumentBlockList(final List blocks) { - setBlocks(( SmallDocumentBlock [] ) blocks - .toArray(new SmallDocumentBlock[ blocks.size() ])); + setBlocks(blocks.toArray(new SmallDocumentBlock[blocks.size()])); } -} // end public class SmallDocumentBlockList +} diff --git a/src/testcases/org/apache/poi/poifs/storage/TestSmallDocumentBlock.java b/src/testcases/org/apache/poi/poifs/storage/TestSmallDocumentBlock.java index 24278e207..31c4546a4 100644 --- a/src/testcases/org/apache/poi/poifs/storage/TestSmallDocumentBlock.java +++ b/src/testcases/org/apache/poi/poifs/storage/TestSmallDocumentBlock.java @@ -21,13 +21,12 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; -import org.apache.poi.poifs.common.POIFSConstants; - import junit.framework.TestCase; +import org.apache.poi.poifs.common.POIFSConstants; + /** * Class to test SmallDocumentBlock functionality * @@ -53,7 +52,7 @@ public final class TestSmallDocumentBlock extends TestCase { throws IOException { ByteArrayInputStream stream = new ByteArrayInputStream(_testdata); - List documents = new ArrayList(); + List documents = new ArrayList(); while (true) { @@ -66,9 +65,8 @@ public final class TestSmallDocumentBlock extends TestCase { } } SmallDocumentBlock[] results = - SmallDocumentBlock - .convert(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,( BlockWritable [] ) documents - .toArray(new DocumentBlock[ 0 ]), _testdata_size); + SmallDocumentBlock.convert(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, + documents.toArray(new DocumentBlock[ 0 ]), _testdata_size); assertEquals("checking correct result size: ", (_testdata_size + 63) / 64, results.length); @@ -142,20 +140,20 @@ public final class TestSmallDocumentBlock extends TestCase { { for (int j = 0; j <= 8; j++) { - List foo = new ArrayList(); + List blocks = new ArrayList(); for (int k = 0; k < j; k++) { - foo.add(new Object()); + blocks.add(new SmallDocumentBlock(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS)); } - int result = SmallDocumentBlock.fill(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,foo); + int result = SmallDocumentBlock.fill(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, blocks); assertEquals("correct big block count: ", (j + 7) / 8, result); assertEquals("correct small block count: ", 8 * result, - foo.size()); - for (int m = j; m < foo.size(); m++) + blocks.size()); + for (int m = j; m < blocks.size(); m++) { - BlockWritable block = ( BlockWritable ) foo.get(m); + BlockWritable block = blocks.get(m); ByteArrayOutputStream stream = new ByteArrayOutputStream(); block.writeBlocks(stream); @@ -208,13 +206,12 @@ public final class TestSmallDocumentBlock extends TestCase { { new RawDataBlock(new ByteArrayInputStream(data)) }; - List output = SmallDocumentBlock.extract(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,blocks); - Iterator iter = output.iterator(); + List output = SmallDocumentBlock.extract(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,blocks); offset = 0; - while (iter.hasNext()) + for (SmallDocumentBlock block : output) { - byte[] out_data = (( SmallDocumentBlock ) iter.next()).getData(); + byte[] out_data = block.getData(); assertEquals("testing block at offset " + offset, 64, out_data.length);