/** * Constructor * * @param name the name of the POIFSDocument * @param stream the InputStream we read data from */ public OPOIFSDocument(String name, POIFSBigBlockSize bigBlockSize, InputStream stream) throws IOException { List<DocumentBlock> blocks = new ArrayList<DocumentBlock>(); _size = 0; _bigBigBlockSize = bigBlockSize; while (true) { DocumentBlock block = new DocumentBlock(stream, bigBlockSize); int blockSize = block.size(); if (blockSize > 0) { blocks.add(block); _size += blockSize; } if (block.partiallyRead()) { break; } } DocumentBlock[] bigBlocks = blocks.toArray(new DocumentBlock[blocks.size()]); _big_store = new BigBlockStore(bigBlockSize, bigBlocks); _property = new DocumentProperty(name, _size); _property.setDocument(this); if (_property.shouldUseSmallBlocks()) { _small_store = new SmallBlockStore( bigBlockSize, SmallDocumentBlock.convert(bigBlockSize, bigBlocks, _size)); _big_store = new BigBlockStore(bigBlockSize, new DocumentBlock[0]); } else { _small_store = new SmallBlockStore(bigBlockSize, EMPTY_SMALL_BLOCK_ARRAY); } }
/** * Provides a short description of the object, to be used when a POIFSViewable object has not * provided its contents. * * @return short description */ public String getShortDescription() { StringBuffer buffer = new StringBuffer(); buffer.append("Document: \"").append(_property.getName()).append("\""); buffer.append(" size = ").append(getSize()); return buffer.toString(); }
/** * Constructor * * @param name the name of the POIFSDocument * @param size the length of the POIFSDocument * @param path the path of the POIFSDocument * @param writer the writer who will eventually write the document contents */ public OPOIFSDocument( String name, int size, POIFSBigBlockSize bigBlockSize, POIFSDocumentPath path, POIFSWriterListener writer) { _size = size; _bigBigBlockSize = bigBlockSize; _property = new DocumentProperty(name, _size); _property.setDocument(this); if (_property.shouldUseSmallBlocks()) { _small_store = new SmallBlockStore(_bigBigBlockSize, path, name, size, writer); _big_store = new BigBlockStore(_bigBigBlockSize, EMPTY_BIG_BLOCK_ARRAY); } else { _small_store = new SmallBlockStore(_bigBigBlockSize, EMPTY_SMALL_BLOCK_ARRAY); _big_store = new BigBlockStore(_bigBigBlockSize, path, name, size, writer); } }
/** @return <code>null</code> if <tt>offset</tt> points to the end of the document stream */ DataInputBlock getDataInputBlock(int offset) { if (offset >= _size) { if (offset > _size) { throw new RuntimeException("Request for Offset " + offset + " doc size is " + _size); } return null; } if (_property.shouldUseSmallBlocks()) { return SmallDocumentBlock.getDataInputBlock(_small_store.getBlocks(), offset); } return DocumentBlock.getDataInputBlock(_big_store.getBlocks(), offset); }
/** * Constructor from small blocks * * @param name the name of the POIFSDocument * @param blocks the small blocks making up the POIFSDocument * @param length the actual length of the POIFSDocument */ public OPOIFSDocument(String name, SmallDocumentBlock[] blocks, int length) { _size = length; if (blocks.length == 0) { _bigBigBlockSize = POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS; } else { _bigBigBlockSize = blocks[0].getBigBlockSize(); } _big_store = new BigBlockStore(_bigBigBlockSize, EMPTY_BIG_BLOCK_ARRAY); _property = new DocumentProperty(name, _size); _small_store = new SmallBlockStore(_bigBigBlockSize, blocks); _property.setDocument(this); }
/** * Constructor from small blocks * * @param name the name of the POIFSDocument * @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 { _size = length; _property = new DocumentProperty(name, _size); _property.setDocument(this); if (Property.isSmall(_size)) { _big_store = new BigBlockStore(bigBlockSize, EMPTY_BIG_BLOCK_ARRAY); _small_store = new SmallBlockStore(bigBlockSize, convertRawBlocksToSmallBlocks(blocks)); } else { _big_store = new BigBlockStore(bigBlockSize, convertRawBlocksToBigBlocks(blocks)); _small_store = new SmallBlockStore(bigBlockSize, EMPTY_SMALL_BLOCK_ARRAY); } }
/** * Constructor from large blocks * * @param name the name of the POIFSDocument * @param blocks the big blocks making up the POIFSDocument * @param length the actual length of the POIFSDocument */ public OPOIFSDocument(String name, RawDataBlock[] blocks, int length) throws IOException { _size = length; if (blocks.length == 0) { _bigBigBlockSize = POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS; } else { _bigBigBlockSize = (blocks[0].getBigBlockSize() == POIFSConstants.SMALLER_BIG_BLOCK_SIZE ? POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS : POIFSConstants.LARGER_BIG_BLOCK_SIZE_DETAILS); } _big_store = new BigBlockStore(_bigBigBlockSize, convertRawBlocksToBigBlocks(blocks)); _property = new DocumentProperty(name, _size); _small_store = new SmallBlockStore(_bigBigBlockSize, EMPTY_SMALL_BLOCK_ARRAY); _property.setDocument(this); }
/** * Get an array of objects, some of which may implement POIFSViewable * * @return an array of Object; may not be null, but may be empty */ public Object[] getViewableArray() { String result = "<NO DATA>"; try { BlockWritable[] blocks = null; if (_big_store.isValid()) { blocks = _big_store.getBlocks(); } else if (_small_store.isValid()) { blocks = _small_store.getBlocks(); } if (blocks != null) { ByteArrayOutputStream output = new ByteArrayOutputStream(); for (BlockWritable bw : blocks) { bw.writeBlocks(output); } int length = Math.min(output.size(), _property.getSize()); result = HexDump.dump(output.toByteArray(), 0, 0, length); } } catch (IOException e) { result = e.getMessage(); } return new String[] {result}; }
/** * Set the start block for this instance * * @param index index into the array of blocks making up the filesystem */ public void setStartBlock(int index) { _property.setStartBlock(index); }