Example #1
0
  /**
   * 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);
    }
  }
Example #2
0
    /** @return the DocumentBlocks */
    DocumentBlock[] getBlocks() {
      if (isValid() && _writer != null) {
        ByteArrayOutputStream stream = new ByteArrayOutputStream(_size);
        DocumentOutputStream dstream = new DocumentOutputStream(stream, _size);

        _writer.processPOIFSWriterEvent(new POIFSWriterEvent(dstream, _path, _name, _size));
        bigBlocks = DocumentBlock.convert(_bigBlockSize, stream.toByteArray(), _size);
      }
      return bigBlocks;
    }
Example #3
0
 /** @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);
 }
Example #4
0
    /**
     * write the blocks to a stream
     *
     * @param stream the stream to which the data is to be written
     */
    void writeBlocks(OutputStream stream) throws IOException {
      if (isValid()) {
        if (_writer != null) {
          DocumentOutputStream dstream = new DocumentOutputStream(stream, _size);

          _writer.processPOIFSWriterEvent(new POIFSWriterEvent(dstream, _path, _name, _size));
          dstream.writeFiller(
              countBlocks() * _bigBlockSize.getBigBlockSize(), DocumentBlock.getFillByte());
        } else {
          for (int k = 0; k < bigBlocks.length; k++) {
            bigBlocks[k].writeBlocks(stream);
          }
        }
      }
    }